Friday 17 February 2012

How to change IP using Batch File

How to change IP using Batch File

Introduction                                                                                                                  

This is an article on how to change IP using batch file using the DOS command NETSH

The code

I've created 2 batch files, one for home which changes the IP to dhcp

Code:
netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip set dns     "Local Area Connection" dhcp
netsh interface ip show config
This is simple to understand

netsh interface ip is common
set for changing the settings
set addess to change the IP address
set dns to change the dns address
"Local Area Connection" is the name of the network connection
dhcp is the mode which is set for IP and dns both

And netsh interface ip show config is to show the config on screen

And one for office, which changes to static IP.
Code:
netsh interface ip set address "Local Area Connection" static 192.168.0.101 255.255.255.0 192.168.0.1 1
netsh interface ip set dns     "Local Area Connection" static 192.168.0.10
netsh interface ip add dns     "Local Area Connection" 192.168.0.11 index=2
netsh interface ip show config
netsh interface ip is common
set for changing the settings
set addess to change the IP address
set dns to set the primary dns address
add dns to add extra dns address
"Local Area Connection" is the name of the network connection

static 192.168.0.101 255.255.255.0 192.168.0.1 1
to specify the static ip settings
192.168.0.101 - IP address
255.255.255.0 - subnet mask
192.168.0.1 - gateway
1 - I don't know what's the significance but it didn't work without this

static 192.168.0.10 - to add static dns address as primary dns
index=2 to indicate that this is the secondary dns address

References

Used this as a reference for making the batch file
http://www.petri.co.il/configure_tcp_ip_from_cmd.htm

hope u like it

No comments:

Post a Comment