Set from static IP to DHCP on Windows 8 using comm

2019-09-08 07:28发布

问题:

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?

回答1:

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?



回答2:

For Windows 10

netsh interface ip set address "Ethernet" static 10.10.10.11 255.255.255.0

netsh interface ip set address "Ethernet" source=dhcp