It is very annoying using GUI to change the configuration repeatedly. It also creates lots of typos to add up more troubleshooting time. I decided to create some automation. If I can create small scripts or batch files to do such routines for me, it will save me so much time!
After some research and try-and-error, I found NETSH, and I also learned something:
- When we use NETSH to switch back to DHCP, we must issue two commands: one for IP address, and one for DNS.
- NETSH command "set dnsserver" replaces all previous DNS settings. Only the First DNS server can be configured using this command.
- To add more DNS servers, we have to use "add dnsserver ... index=2" for the Second one, and so on.
Here are the sample batch contents for you to cut-and-paste. To execute them without error, you should raise your privilege level to system administrator, especially in Windows Vista and Windows 7.
Setup PC's NIC as DHCP
netsh interface ip set address "Local Area Network" dhcp
netsh interface ip set dnsserver "Local Area Network" dhcp
Setup PC's NIC as Fixed configuration
set ADDRESS="1.2.3.4"
set MASK="255.255.255.0"
set GATEWAY="1.2.3.1"
set METRIC="1"
set DNS1="192.168.0.253"
set DNS2="192.168.0.254"
set DNS3="192.168.0.252"
netsh interface ip set address "Local Area Network" ^
static %ADDRESS% %MASK% %GATEWAY% %METRIC%
netsh interface ip set dnsserver "Local Area Network" static %DNS1%
netsh interface ip add dnsserver "Local Area Network" %DNS2% index=2
netsh interface ip add dnsserver "Local Area Network" %DNS3% index=3
References
No comments:
Post a Comment
Tip: you can also anonymously comment here.