This file opened in a new window - close the window to return
 
How to set your Internet Protocol (TCP/IP) address using a batch file
 
Introduction

Warning: This file runs in Command Mode: Use at your own risk

Changing TCP/IP settings can be quite time consuming using the 'Network Connections' route every time.

This file will change your settings for you with one or two clicks.

Create a separate file for each location and save them in a convenient place.

Running the file will then set your TCP/IP for that location.

 


Set-up instructions

Download the text file.

Open it with Notepad (NOT Word or Wordpad or any other word processing software)

Change the settings to suit your system

Save it as a batch file (with the suffix .bat)

You can download the text file by clicking this link.

There is more info on how to edit the file at the bottom of this page


NOTES

1. You usually have to have Administrator privileges to run files

2. Vista users may have to right click on the file icon and use 'Run as administrator'


NOTES This MORE INFO

This file runs in Command Mode. Use at your own risk.

The bits you may need to alter are coloured purple

STEP ONE:

Download the text file (see link above) and open it in Notepad. (Right click - IE: Save target as/ Firefox: Save link as). DO NOT try to run the text on this page as code

Firstly you need to change the name in the inverted commas in this line
set lan_name="
Wireless Network Connection"

The name in the inverted commas must match your connection name. The name in our example is the default name for the Wireless Network connections in Vista. You may have names like "Wireless Network Connection (4) or "Ethernet (2) etc etc

STEP TWO:


Define the first part of the network addresses here

set ipsubnet=192.168.1


These are the first three numbers in your ip4 settings.
We will call these the subnet address for the ip address and default gateway.
You will need to know these numbers for your own system. The numbers used here are typical.
Change them if you need to - don't forget the dot between each number - no spaces and don't put a dot at the end.

 

STEP THREE:

Next set the subnet address for the DNS servers.
Note on some systems these will be the same three numbers as the ipsubnet above.
Change them if you need to - don't forget the dot between each number - no spaces and don't put a dot at the end.
set dnssubnet=
194.44.65

STEP FOUR:

Next change the code below to add the fourth number to the ip address for the LAN and the Gateway. Here we have used 150 for the lan-ip and 254 for the gateway. Your numbers will probably be different

rem Set each of IP address, Subnet mask and Default gateway
set lan_ip=%ipsubnet%.
150
set sub_net_mask=255.255.255.0
set gateway_addr=%ipsubnet%.
254

STEP FIVE:

Next change the code below to add the fourth number to the DNS address. In our example we've used the numbers 69 for the Primary (or Preferred) DNS and 68 for the Secondary (or Alternative). Your numbers will probably be different

rem Set both the DNS values
set pri_dns_addr=%dnssubnet%.
69
set sec_dns_addr=%dnssubnet%.
68

The following code does the work and does not need to be altered.

rem set the ip address
@netsh interface ip set address name=%lan_name% source=static addr=%lan_ip%
mask=%sub_net_mask% gateway=%gateway_addr% gwmetric=1
rem set the preferred DNS
@netsh interface ip set dns name=%lan_name% source=static addr=%pri_dns_addr% primary
rem add the alternative DNS
@netsh interface ip add dns name=%lan_name% addr=%sec_dns_addr% index=2

 

This will give you TCP/IP settings as shown below

Save the file with the suffix .bat     for example

homenetwork.bat or office1.bat --- you will need to add the suffix in the Notepad 'Save as' dialogue box otherwise it will save as a text file.