Change TCP / IP settings using command prompt or .bat script

If you change your network settings quite often, you can save yourself quite a bit of time by creating a simple .bat scripts which allow to set predefined TCP/IP setting with a single click.
To change your IP settings via command prompt you can use netsh command.
You can run netsh either directly in the command prompt or create .bat files and run them when required.
You will need local admin rights for this to work. On Windows Vista and Windows 7 you also have to run commands in the elevated command prompt, or if you use .bat scripts, run them as Administrator.

To set static IP address and static DNS:

Create a .bat file and paste following code:
netsh interface ip set address “Local Area Connection” static 192.168.0.51 255.255.255.0 192.168.0.1 1
netsh interface ip set dns “Local Area Connection” static 8.8.8.8
netsh interface ip add dns “Local Area Connection” 8.8.4.4

Modify values to suit your requirements:
Local Area Connection – Name of the connection you modifying
192.168.0.51 – IP address
255.255.255.0 – Subnet Mask
192.168.0.1 – Gateway
8.8.8.8 – Primary DNS server
8.8.4.4 – Secondary DNS server

To set automatic DHCP IP address and DNS:

Create a .bat file and paste following code:
netsh interface ip set address name=”Local Area Connection” dhcp
netsh interface ip set dns “Local Area Connection” dhcp

Where:
Local Area Connection – Name of the connection you modifying

Windows XP
Windows Vista
Windows 7


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *