Jump to content
xisto Community
curare

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

Recommended Posts

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:

 

netsh interface ip set address name="Local Area Connection" source=static addr=111.222.333.444 mask=255.255.255.255netsh interface ip set address name="Local Area Connection" gateway=555.666.777.888 gwmetric=0netsh 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.

 

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

Save the file. If you need WINS you should enter the 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

HiDo 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 ).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.