WIN 7 .bat file to change IP address .. DHCP problem
I have a few batch files that I use to switch NIC settings. These are all "Run as Administrator".
For static IP, I use this:
@ECHO OFFset varip=192.168.0.99set varsm=255.255.255.0set vargw=192.168.0.1set vargwmetric=1set vardns1=192.168.0.1set vardns2=8.8.8.8set vardnsindex1=1set vardnsindex2=2REM ***** You don’t need to change anything below this line! ******ECHO Setting IP, mask, gateway and DNSREM netsh set address "Local Area Connection" static %varip% %varsm% %vargw% %vargwmetric%netsh interface ip set address "Local Area Connection" static %varip% %varsm% %vargw% %vargwmetric%ECHO Setting Primary DNSnetsh interface ip set dns name="Local Area Connection" source=static address=noneECHO Setting primary DNSnetsh interface ip add dns name="Local Area Connection" %vardns1% index=%vardnsindex1%ECHO Setting secondary DNSnetsh interface ip add dnsserver "Local Area Connection" %vardns2% index=%vardnsindex2%ECHO Here are the new settings for %computername%:netsh int ip show configpauseend
To switch to DHCP "get an address automatically", I use this:
@ECHO OFFREM ***** You don’t need to change anything below this line! ******netsh interface ip set address name="Local Area Connection" dhcpnetsh interface ip set dns name="Local Area Connection" dhcpnetsh interface ip set default gateway name="Local Area Connection" dhcpnetsh interface ip show config[embed=file 906425]pauseend
The problem is, that when I switch from a static address to a DHCP configuration, the default gateway IP address remains and the DHCP button isn't turned on - and the NIC settings dialog appears to disagree with the results of ipconfig that says DHCP YES!
At the same time, the NIC ipv4 settings look like this:
What might be the problem here?
ipconfig result and the GUI result are different re: DHCP.