Windows Quick Tip: How to Create a Batch File for Changing Network Settings
The aim of this tutorial is to create a batch file using which you will be able to change your network settings with just a click of your mouse.
Why to create a batch file for changing network settings?
If you happen to use a laptop at your workplace and at home the you may have to change the network settings when ever you move from home or office. The normal procedure where we usually open the network connections and enter the IP address manually is painful if we do it daily. To get this done easily all you have to do is create two batch files which will ease our task.
How to create a batch file for changing network settings?
1. Open notepad.
2. Now copy the code that is given below
netsh interface ip set address name="Local Area Connection" source=static addr=192.168.1.100 mask=255.255.255.0
netsh interface ip set address name="Local Area Connection" gateway=192.168.1.1 gwmetric=0
netsh interface ip set dns name="Local Area Connection" source=static addr=208.67.222.222
netsh interface ip add dns name = "Local Area Connection" addr =208.67.220.220
The relevant IP’s are illustrated in the screenshot below, the IP’s that are illustrated are only examples:

3. Now that you have copied the code, paste this in the Notepad. Enter the IP’s as per your requirements and save the file with the extension *.bat
[eminimall]
4. Your batch file is now ready for execution, now double click the batch file that you just created and you will find your network settings configured in a few seconds.
5. Create another batch file using the similar procedure, in this batch file you enter the IP’s that are relevant to your other location.
6. Now you should be having two batch files one for your office network and the other for your home network.
I guess by using this method your life would ease a bit.
If you have better method then do let me know.
Cool, never knew of the netsh command.
In fact I was just going over the MS documentation, there is an option of running the a pre-configured script as well. Accomplishes the same thing, but probably its more neat
As of now I have no trouble using my laptop at work and home. The default setting of automatically getting the IP works with no issues.
Indeed very nice tip. I’m sure I would have used it however, the DHCP enabled wireless router just saved me from using this. But, many more will certainly find it useful
I use NetsetMan…works great and allows multiple network profiles
Free for personal use
http://www.netsetman.com/
Terrific! I’m constantly connecting to brand new routers/printers/print servers/WAPs/whatever and setting them up… It’s always a pain to click your way through the TCP/IP settings again and again for each device. This will prove very handy.
I have used this type of command for over a year at my current work site, however; I have just tried to used it in Vista to see if it is valid after an upgrade and I cannot seem to make it work, nor can I find anything saying “Change this or this and it will work in Vista as well”. Got any ideas? It is setting the Gateway and both DNS without a problem but will not set the Address nor the Mask.
Dwanna-
This code is not currently working in Vista, I will try to fix this once I get some time, but XP users can use it
For complex cases you can use special application for changing your connectivity but if it is simply changing of IP address and mask you can use this bat file.
Create a Batch File for Changing Network Settings
netsh interface ip set address name=”Local Area Connection” source=static addr=192.168.1.100 mask=255.255.255.0
netsh interface ip set address name=”Local Area Connection” gateway=192.168.1.1 gwmetric=0
netsh interface ip set dns name=”Local Area Connection” source=static addr=208.67.222.222
netsh interface ip add dns name = “Local Area Connection” addr =208.67.220.220
It’s work im very thaxnfull toooo…
VISTA UPDATE!!!!!
FINALLY! I have worked out how to get it to work in vista!!
@ECHO OFF
set varip=65.88.48.77
set varsm=255.255.255.224
set vargw=65.88.48.65
set vardns1=66.78.202.254
set vardns2=66.78.210.254
REM ***** You don’t need to change anything below this line! ******
ECHO Setting IP to static
netsh int ipv4 set address name = “Wireless Network Connection” source = static address = %varip% mask = %varsm%
ECHO Setting IP Address and Subnet Mask
netsh int ipv4 set address name = “Wireless Network Connection” address = %varip% mask = %varsm% gateway = %vargw% gwmetric = 1
ECHO Setting Primary DNS
netsh int ip set dns name = “Wireless Network Connection” source = static addr = %vardns1%
ECHO Setting Secondary DNS
netsh int ip add dns name = “Wireless Network Connection” addr = %vardns2%
ECHO Here are the new settings for %computername%:
netsh int ip show config
pause
The change is quite simple…the problem seems to lie in vista’s inability to set the ip to static, and assign the ip address at the same time. So all you have to do is set up the ip to static first, then set the ip…very strange
Note that your static ip is not displayed when shown, however it is set.
Just change your network settings at the top and don’t forget to change “Wireless Network Connection” to the name of your connection
You need to copy everything from @ECHO OFF down to and including pause into a text file and give it a .bat extension
This is something I’ve been looking for a long time
Thanks for tip!!!
HEy can any1 tell me how to disable/enable LAN using batch file??
I have tried solution for Vista but i got below error after each line:
The requested operation requires elevation.
What could be the reason
You need to right click the batch file and choose “run as administrator”
@Vijeth,
The following, at the top, has a utility called ToggleNIC.exe, which will do what you want. http://channel9.msdn.com/playground/Sandbox/154712/