Manipulating the network card with Netsh

Swip Swap, from Static to DHCP via the terminal

Recently, in an advent of troubleshooting a network issue, I had to run around and set a number of static IP’s onto devices. This being said, having to physically get up and run around a touch a number of devices can be a bit tedious.

Given you can get a remote session with each computer, you can issue the following commands using netsh.

Gathering Information

Lets start by getting some information on the current device. To do so, you will want to run the following command.

1
netsh interface ip show config

The above command should spit out something along the lines of this, depending on how many network interfaces you have available.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
Configuration for interface "Ethernet"
    DHCP enabled:                         No
    IP Address:                           10.XX.XX.XX
    Subnet Prefix:                        10.XX.XX.XX/16 (mask 255.255.0.0)
    Default Gateway:                      10.XX.XX.X
    Gateway Metric:                       256
    InterfaceMetric:                      25
    Statically Configured DNS Servers:    8.8.8.8
                                          4.2.2.2
    Register with which suffix:           Primary only
    Statically Configured WINS Servers:   None

Configuration for interface "Loopback Pseudo-Interface 1"
    DHCP enabled:                         No
    IP Address:                           127.0.0.1
    Subnet Prefix:                        127.0.0.0/8 (mask 255.0.0.0)
    InterfaceMetric:                      75
    Statically Configured DNS Servers:    None
    Register with which suffix:           Primary only
    Statically Configured WINS Servers:   None

The key thing here to notice is that the DHCP enabled line says no, meaning that the address shown under IP Address is your statically assigned IP.

Manipulating the Network Card

Next, to modify the DHCP enabled value and essentially over write the statically set address, you will want to run the following command.

1
netsh interface ip set address "Ethernet" dhcp

Note that the above command contains “Ethernet” for the interface that I am manipulating, but you should use whatever interface you want to modifies name is. For example some computers, it shows up as “Ethernet 2”.

If everything works, running the above command will literally brick your session, booting you from the console. Give it a few seconds, then do a NSLOOKUP or a PING to find the new IP assigned by DHCP, and you should be able to ping it again.

If the device is pingable, then it should be online and good to go.

GNU General Public License v3.0
Built with Hugo
Theme Stack designed by Jimmy