- Challenge: Configuring IP with PowerShell.
Are you tired of clicking around the GUI?
Use PowerShell, use the command line.
In this lab, we'll configure a static IP
version 4 address within PowerShell.
To do this, we'll use the following format
and we're gonna use the netsh command.
This command could do all kinds of things in Windows,
we're just gonna use it here to configure TCP/IP.
And for this command we're gonna use netsh
and a lot of options and parameters.
It's going to be netsh interface, IP set address
and then your connection name.
By default in Windows, if you have a wired connection
that connection's name will be called ethernet
and that's what I'll be using in the demonstration
in just a minute.
Then we'll say static because we're going
to manually configure the IP address
and then we'll enter the actual IP version
4 address that we want to use,
as well as the IP version 4 subnet mask
and the gateway address.
Afterward, we'll add a DNS server
so that we can do our name to IP resolution.
And once again, we'll use the netsh interface IP command,
but this time we'll type add DNS,
once again our connection name
and then the IP address of our DNS server.
After we do that, we'll test it
and make sure that it can function
and that we can connect to the internet.
When we're done, we'll set it back to DHCP
and the command for that netsh interface IP set address,
the connection name and just DHCP.
So let's get into the demonstration now.
I'm going to be doing this on a Windows 11 virtual machine
and we want to open up PowerShell as an administrator.
Several ways to do this.
In Windows 11 you could right click on start
and open Windows Terminal,
which will automatically open PowerShell.
And you'd wanna do that as an admin,
or we could press the Windows key
and type in PowerShell
and run it from there,
or do it from the run prompt and type PowerShell.
And to run it as an admin we'd press control shift enter
but I like the search option.
It's very easy.
We can right click on Windows PowerShell
and select run as administrator.
And we'll say yes
and that brings up the Windows PowerShell
as an administrator, meaning in elevated mode.
So now we can do these types of commands
that we need to do as an admin.
I'm going to change to the root directory
and clear the screen with a control L
so that we have a little bit more space here.
And the first thing I wanna do
is run an IP config slash all,
to check out the current IP configuration.
Now, as I mentioned, this is a virtual machine
and it's on a virtualization platform
that automatically hands out IP addresses.
I know that this virtual machine
is obtaining its IP address from a DHCP server.
I know that because here it says DHCP enabled
and yes.
So we know we're getting our TCP/IP information
from a DHCP server.
And that's the DHCP server that's built into
my virtualization platform.
The IP version 4 address that we received
is 192.168.122.63.
So the IP network that my virtualization platform
is using here is 192.168.122.
I wanna stay on that particular network.
What differentiates this system from other systems
is the last octet, that dot 63.
And I'll be changing that when we set a static IP address.
We're also getting the subnet mask information
from the DHCP server which is 255.255.255.0.
We also see the default gateway
which is 192.168.122.1,
and the DNS server, which is the same host.
Now you might do this on a network with the Soho router
and it would work in the same manner.
Your network might be 192.168.0,
or 192.168.1.
Or if you're on a different virtualization platform,
it might be a different network as well.
So whatever that network is,
that's the network that you want to work within.
So I'm gonna change this now,
I don't want to have DHCP anymore.
A lot of times I'll be working on a system
and I want it to have a static IP address
so that I know the IP address will not change
and I can have permanent connections
to that system via that static IP.
So a lot of times I'll use a static IP address.
So let's make the change now.
We're gonna do that with the netsh command
and that's gonna be interface
and IP set address.
And then we need the name
of our wired network interface card.
Now, again, this is a virtual machine
so it uses virtualized hardware,
but it works the same way as a physical system.
And what we wanna look for is ethernet adapter
and then the name that's after that.
By default in Windows,
the name of a wired connection is called ethernet.
If you're working with a wireless connection,
the default name is wifi.
You could change this in the PowerShell if you wanted to,
but we're gonna stick with the name ethernet.
And we wanna put that in double quotes.
So we'll add that in now,
you can see the different color there
and then we want to state
that we are going to add a static IP address.
So we put in the word static
and then the IP address I want to use.
Well, I'm gonna use the same network
but I'm gonna change the last octet.
And I'm just gonna change it to say, .150.
It doesn't really matter,
as long as the address that I select is not being used
by any other systems.
So I'm going to type 192.168.122.150.
Next, we need the subnet mask
and I'm gonna use the same subnet mask
that I'm currently using,
255.255.255.0.
And that just wrapped around the screen there.
Now you could also do something like this
slash 24,
which is cidr notation,
it's the same thing.
For now I'll just do 255.255.255.0,
and then we need to know the gateway address.
It's gonna be the same default gateway.
So we'll type in this IP.
For you, it may be different on your system.
It probably will be, but that's the IP for me,
192.168.122.1.
And that's it, that's our command.
So we'll press enter,
that will apply the new information,
deactivate and reactivate the network interface.
And then we can check that with an IP config slash all.
Okay. Now, when we look at DHCP enabled, it says, no.
We're not using DHCP anymore, it's a static IP.
When we look at the IP version 4 address,
we see 192.168.122.150.
And we have our default gateway.
Now the DNS server is already there,
but if you had a problem with that,
if there was an issue with DNS,
you could add that on
and you would do that with the netsh interface IP, add DNS
for our ethernet connection
and then specify the IP address 192.168.122.1.
And it says the object is already in the list,
but just in the case that it wasn't there,
if you lost it for some reason,
or it didn't show up when you changed over to static,
then you could add that with this command.
Now we want to go ahead and test it and make sure it works.
So I'm gonna ping a website
on the internet
and we get replies.
We can ping Depro Computer so we know the test has passed
and we should be able to do anything we need to do
with our internet connection, inbound and outbound.
That's it.
That's how you change to a static IP.
Now let's go ahead and change it back to DHCP.
And we'll do that with the netsh interface IP set address
and the name's ethernet, and just say DHCP.
That's gonna make the change deactivate
and reactivate the network interface.
And then I'll just up arrow
to IP config slash all to check it.
Once again, DHCP enabled, yes.
IP version 4 address dot 63.
Well, Windows remembers the IP address that we were using.
And it reapplies to that,
as long as the DHCP server is okay with that.
Our gateway address is there
and our DNS server is there.
We'll test once again with a ping,
all as well.
Okay? So the only things you might change with that
are your network number.
You want to put in whatever network number you're using.
For example, if you're on VirtualBox
you're probably on 10.0.2.
If you're on VMware Workstation,
you might be using another 192.168 network.
If you're working on the local area network
on a test computer, like a laptop
and you have a Soho network
it might be 192.168.0, or .1, or what have you.
And the name of the adapter, if it's wired,
by default will be ethernet.
By default, if it's wireless, it'll be wifi.
And make sure you put that in double quotes.
Now you'll notice that we have the blue background here.
If we were to run the command dollar sign PS version table,
you'll see that the PowerShell version
that I'm running is 5.1.
This is an older version.
We have much newer versions of PowerShell.
And so in another challenge video
we'll show how to update PowerShell to a newer version.
Now, one other thing here,
sometimes we'll be working on a system
that has lots of network connections.
For example, here's a Windows laptop.
I'm gonna open up PowerShell on here as an administrator,
say yes to that, bring that up.
And if I run an IP config on here with a slash all,
you're gonna see tons and tons and tons of information
and the Bluetooth and the wireless
aren't even connected right now.
So it's limited, but there's still tons of information.
There's all kinds of virtual networks
and wired connection and blah, blah, blah.
That's a lot of information to look at
within IP config slash all.
So if you're working on a server
with lots of network connections,
or if you're working on a power works station
with lots of connections or maybe a developer laptop
with lots of virtual connections,
sometimes you may wanna filter this information.
So you might do an IP config slash all
with the pipe sign
and do select string, run the SLS parameter here
and then filter for what you want.
So for example, I might filter for description
and also IP version 4.
When I do that,
I get a lot less information and just what I want.
So for example, description,
real tech PCI express controller.
That's the wired connection
and its IP version 4 address is 10.42.0.250.
And you can do that for each of these here,
all of the connections.
So just a quick little trick there, use SLS
to filter out results of commands
that give you tons of information,
just a little bonus there.
All right.
And like I said, in a future video we'll show how to upgrade
to the latest stable version of PowerShell.
And in closing, go ahead now,
I challenge you to try configuring a new IP address
on a test Windows system, now I recommend a virtual machine
but some test system always do all this stuff
on testing systems, not your main system.
And remember to run PowerShell as an admin,
chances are you will need PowerShell in the field.
Use it.