"Command lines to setup IP address and DNS of Windows PC" on Show IP Protocols
|
|
Command lines to setup IP address and DNS of Windows PC Posted: 02 Jul 2011 08:07 AM PDT When I use my Windows notebook as connectivity tester, I often have to switch the IP address configuration from DHCP to some fixed IP, and back and forth. Also, different customers have different assigned fixed IP addresses.
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:
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
|
You are subscribed to email updates from Show IP Protocols
To stop receiving these emails, you may unsubscribe now. |
Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |