Search code examples
windowsdhcpstatic-ip-address

Set from static IP to DHCP on Windows 8 using command line


My computer is Windows 8. I used command line to set static IP address by

netsh interface ipv4 set address name="Wired Ethernet Connection" source=static address=1.1.1.1 mask=1.1.1.1 gateway=1.1.1.1

And static DNS by

netsh interface ipv4 add dnsserver name="Wired Ethernet Connection" address=1.1.1.1 index=1

Where 1.1.1.1 in both cases is just for demonstration and was replaced by my real IP.

Edit: As of 2018, 1.1.1.1 is used as a DNS server now.


I want to change from static IP to DHCP now.

I tried

netsh interface ipv4 set address name="Wired Ethernet Connection" source=dhcp

for IP and

netsh interface ipv4 set dnsservers name="Wired Ethernet Connection" source=dhcp

for DNS.

However, only the command for DNS worked.


I then checked with

ipconfig /all

It told me that DHCP was on for Ethernet. However, my previous IP was still there.

Is there any way to set from static to DHCP in command line?


Solution

  • netsh interface ipv4 set address name="Wired Ethernet Connection" source=dhcp
    ipconfig /renew Wired*
    

    If above ipconfig /renew command does not help, try

    netsh interface set interface name="Wired Ethernet Connection" admin=DISABLED
    netsh interface ipv4 set address name="Wired Ethernet Connection" source=dhcp
    netsh interface set interface name="Wired Ethernet Connection" admin=ENABLED
    

    However, maybe all address, mask and gateway obtained from dhcp could match those defined by source=static previously.
    Are there Lease Obtained and Lease Expires properties displayed in the ipconfig /ALL output?