Loading...


bookmark - Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS

Switch Network Settings With Batch Files - A quick way to change IP, Gateway, DNS

 
 Discussion by curare with 23 Replies.
 Last Update: March 18, 2010, 12:01 am ( View Rated (1) )
 
bookmark - Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS  
Quickly Post to Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS w/o signup Share Info about Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS using Facebook, Twitter etc. email your friend about Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Let's suppose you are using two network settings with your laptop frequently. Wether it's a wireless or wired network, all the same: Every time you want to change the IP, subnet mask, default gateway and DNS Server(s) of your network connection in any flavour of Windows, you have to click through menus, submenus, and from that you go to yet another submenu... you have been there, it's awful. :P

There is a better way: the command "netsh" on your command prompt can change all the aforementioned settings, and if you put them in a batch file, you can change them with a double mouse click.

To familiarize yourself with the command, click on "Start/Run" and enter "cmd". The command prompt opens. Enter "netsh /?" and you'll see the options and parameters of this powerful command and its subsets.

Open your network connections folder in the Control Panel. Windows usually calls the Network Interface Card "Local Area Connection" If you want to change the settings of your wireless network settings go to the appropriate status window. Make sure you know the name. Click on it, than click "Properties" and there double-click "Internet Protocol (TCP/IP)" This is where you usually go when you change those settings.

Now open your text editor and create a new file which you will call "Connection_settings_1.bat", or whatever is easily memorable and you associate with your settings # 1. Enter the following code:

CODE


netsh interface ip set address name="Local Area Connection" source=static addr=111.222.333.444 mask=255.255.255.255
netsh interface ip set address name="Local Area Connection" gateway=555.666.777.888 gwmetric=0
netsh interface ip set dns name="Local Area Connection" source=static addr=999.111.222.333  
netsh interface ip add dns name = "Local Area Connection" addr = 444.555.666.777  


Of course you must enter the numbers if the IP, subnet mask, gateway and DNS Server(s) according to your settings! As most of you know, 111.222.333.444 is just an example of an actually non-existing IP address. Save the file.

Assuming that your connection settings #2 are different, say with DHCP, than create another batch file and name it differently from the first.

CODE


netsh interface ip set address name="Local Area Connection" dhcp
netsh interface ip set dns name="Local Area Connection" dhcp


Save the file. If you need WINS you should enter the code

CODE


netsh interface ip set wins name="Local Area Connection" source=static addr=   .   .   .  


at the end of the batch files(s) with the correct settings instead of the dots.

Now test your new batch files. When you double-click on one, a command prompt window opens and the batch file is processed line by line. This takes some time (25 seconds in my case with a 2.8 GH Intel Processor), it is not done instantly. When the processes are finished the window closes.

To check if the settings are applied correctly, open a command prompt and entee "ipconfig". Than double-click on the second batch file and after it is finished put the command prompt where you entered "ipconfig" in focus and enter "ipconfig" again. The settings have changed with one double-click! ;)

A final note: Yes, there is little proggies which do this job as well. One of them is even free. But you can do it without launching any extra program, using the built - in capabilities of your operating system.

curare

   Thu Nov 10, 2005    Reply         

Nice professionally written tutorial. Keep it up ;)

   Sat Nov 12, 2005    Reply         

Yeah hey -where's the reputation system ... we need one back for sure :P Otherwise such works go completely unappreciated. Good one curare - that's the kind of well organized and quality tutorial/post we're always hoping for ;)

   Sat Nov 12, 2005    Reply         


Thank you for your kind words, gentlemen. I have worked some hours on this... and I enjoyed it!

I have a minor (?) request: could you please show your appreciation for this howto by adding some points to my account? While my hosting request has been kindly approved by our dear leader :P I am stuck at 31,25 points and my guess would be that this howto should be worth another two or three points ;)

TIA,

curare








   Sun Nov 13, 2005    Reply         

Heey, :P

You can also set DHCP Server on. Everytime you connect, you will receive a new ip adres. :huh:

The only disadvantages are that your ip adres may change every time you reconnect. But that's only in some cases a problem. :)


Greets,
Mark

   Sun Dec 18, 2005    Reply         

You can also try "Net Profile Switch" http://www.jitbit.com/netprofileswitch.aspx to store and switch multiple network profiles

   Wed Sep 26, 2007    Reply         


Hi

Do you know a way to run multiple batch files with netsh, at certain intervals of time. I want to schedule ip changing at 10 minutes interval, let's say.
Can it be done?
Greets!

-kukubau

   Sun Jan 13, 2008    Reply         

schedule network settings batch
Switch Network Settings With Batch Files

Replying to Feedbacker

Sure, there's already a tool. "scheduled tasks". Then schedule the task to run the batch file at whatever interval you want.

-reply by John Smith

   Wed Mar 12, 2008    Reply         

this doesnt work
Switch Network Settings With Batch Files

I have copied and pasted the exact text in the web page above into a bat file and run it, but it just doesnt seem to work, I am trying to update my wireless connection settings in vista (so I change the name to Wireless network connection etc) but still nothing, please help! :(

Thanks

Pete

-reply by pete

   Fri Apr 11, 2008    Reply         

Very useful info
Switch Network Settings With Batch Files

This tutorial saved my day. I used this technique to switch between two networks. It works just fine. Very informational and useful. Keep it up!

-reply by Subbu

   Mon Apr 21, 2008    Reply         

VISTA UPDATE
Switch Network Settings With Batch Files

Replying to Feedbacker

VISTA UPDATE


I've written the vista update at
Http://samanathon.Com/set-your-ip-address-via-batch-file/

Sorry to link to another site but it saves me typing it all out again!!

-reply by Razzor

   Fri May 23, 2008    Reply         

Doesn
Switch Network Settings With Batch Files

Netsh interface ip set address name="LAN-verbinding 4" source=static addr=192.168.0.99 mask=255.255.255.0

Netsh interface ip set address name="LAN-verbinding 4" gateway=192.168.0.100 gwmetric=0

Netsh interface ip set dns name="LAN-verbinding 4" source=static addr=195.130.131.11

Netsh interface ip add dns name = "LAN-verbinding 4" addr = 195.131.131.12

Pause

Hi, I'm having a strange problem. I copy-pasted the code above, made my changes (as you can see) but nothing in the code itself. But he won't set my ip-address and my subnetmask. I have to say I'm working with a laptop with vista. I've had a lot of problems with security and access and stuff. But now he didn't complain about anything, he setted eveything except for ip and subnet. Can anyone help? Ty ^^

-reply by Emmy

   Sat May 24, 2008    Reply         

VISTA UPDATE
Switch Network Settings With Batch Files

- For Vista users only, I've written it here as well-

@ECHO OFF

Set varip=192.168.1.100
Set varsm=255.255.255.0
Set vargw=192.168.1.1
Set vardns1=66.78.202.254
Set vardns2=66.78.210.254

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 the variables at the beginning to your settings and if needs be, change "wireless network connection" to the name of your connection eg. "LAN-verbinding 4"

-reply by Razzor

   Sun May 25, 2008    Reply         

Thank you very much for looking this up for us :) (and bumping this post, I've been looking for it for a while, but now I don't need it for a few months :P ).

   Thu May 29, 2008    Reply         

Thanks
Switch Network Settings With Batch Files

Great stuff. Keep up the good work



-reply by Pyous

   Mon Jun 2, 2008    Reply         

Vista problems
Switch Network Settings With Batch Files

Hiya,

Have you tried running it by right clicking and using 'run as administrator' instead.

It worked for me as I was getting the:

This command needs to be elevated

HTH

-reply by Andy Holland

   Tue Jun 10, 2008    Reply         

Vista settings
Switch Network Settings With Batch Files

Emmy- that's because you need to type the following into a batch file:

@ECHO OFF

Set varip=192.168.0.99
Set varsm=255.255.255.0
Set vargw=192.168.0.100
Set vardns1=195.131.131.11
Set vardns2=195.131.131.12

ECHO Setting IP to static
Netsh int ipv4 set address name = "LAN-verbinding 4" source = static address = %varip% mask = %varsm%

ECHO Setting IP Address and Subnet Mask
Netsh int ipv4 set address name = "LAN-verbinding 4" address = %varip% mask = %varsm% gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS
Netsh int ip set dns name = "LAN-verbinding 4" source = static addr = %vardns1%

ECHO Setting Secondary DNS
Netsh int ip add dns name = "LAN-verbinding 4" addr = %vardns2%

ECHO Here are the new settings for %computername%:
Netsh int ip show config

Pause

-reply by Razzor

   Sat Jun 7, 2008    Reply         

how to add the one more ip address to a batch file
Switch Network Settings With Batch Files

Hi,


Iam Rajkumar working in crystal granite marble pvt ltd.


Here our lan ip is 192.168.0.1 subnetmask is 255.255.255.0

And internet ip is 10.7.192.81 subnetmask is 255.255.255.240


I want to add the one moreip address to the above mentioned batchfile


I can add the one more dns also but iam not able to add the ip address


Please help me in this scenario



Thnaks and Regards,
Rajkumar.S

-reply by RAJKUMAR

   Tue Jul 1, 2008    Reply         

Thanks
Switch Network Settings With Batch Files

I'm using vista but it didn't work as mentioned above

I tried

Set address name="Wireless Network Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1

And now it works perfectly!

-reply by Quang Tran

   Sat Jun 28, 2008    Reply         

Excellent post.

I'm a little lazy, and found some freeware - "NetSetMan". Works fine for me, and can hold up to 6 different network profiles.

Thanks to all.

- Andy

   Mon Jan 26, 2009    Reply         

What settings?Switch Network Settings With Batch Files

I got the right command in the batch file but it doesn't change my IP. Do I have to have a static IP address to make this work? My friend said I won't have to change it. When I do ipconfig after the batch file launch EVERYTHING is still the same, how?

   Sun Jul 19, 2009    Reply         

Alternate ScriptSwitch Network Settings With Batch FilesI couldn't quite get these working, however I modded a couple of scripts together and the script below works for me on Vista.@ECHO OFFSet varNet="Wireless Network Connection"Set varip=192.168.0.1Set varsm=255.255.255.0Set vargw=192.168.0.2Set vardns1=192.168.0.3Set vardns2=192.168.0.4ECHO Setting IP Address, Subnet Mask and GatewayNetsh int ip set address name = %varNet% source = static addr = %varip% mask = %varsm% gateway = %vargw% gwmetric = 1ECHO Setting Primary DNSNetsh int ip set dns name = %varNet% source = static addr = %vardns1%ECHO Setting Secondary DNSNetsh int ip add dns name = %varNet% addr = %vardns2%-reply by Noot

 

   Wed Jul 15, 2009    Reply         

Thanks a lotSwitch Network Settings With Batch Files

Thanks a lot curare..

But it was the solution of Quang that saved me. I guess they changed the parameters on Vista.

 So thanks to you both,

 Cheers

Keywords: save ip address different network

   Tue Feb 9, 2010    Reply         

simply amazing man...U solved my problem,was struggling to do this for long...Thanx...Take care,keep up the good work

-reply by Faisal

   Thu Mar 18, 2010    Reply         

Quickly Post to Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS w/o signup Share Info about Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS using Facebook, Twitter etc. email your friend about Switch Network Settings With Batch Files A quick way to change IP, Gateway, DNS Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Wireless Networking And Switch

Hey i was just wondering is it possible, since i have two computer (looking at buying my own, the other two are family owned) and a ps2 all wanting to be connected to the net, i bought a switch. It is a 5 pot switch and i have one port spare. See my adsl modem is connected to the switch and then my ...more

   27-Feb-2005    Reply         

Lock Down Switch Port To Increase N...

One way to boost network security is to use Cisco's Port Security feature to lock down switch ports. A growing challenge facing network administrators is determining how to control who can access the organization's internal network—and who can't. For example, can anyone walk ...more

   09-Oct-2006    Reply         

2 Networks, Wrong One Takes Over

Hello, I have a problem with 2 networks one wireless and one wired. The problem is that when I connect to the wired network it takes over and does not let my comp send info over the wireless network. I had it working before but I did several things like bridge the two connections or it could have be ...more

   24-Oct-2007    Reply         

Bash Script To Display Your Ip Script to display your ip   Bash Script To Display Your Ip Script to display your ip (12) (12) Detecting Wirless Networks   Detecting Wirless Networks