|
|
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) ) | |||
![]() |
|
|
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
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
TIA,
curare
You can also set DHCP Server on. Everytime you connect, you will receive a new ip adres.
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
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
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
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
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
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
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
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
Switch Network Settings With Batch Files
Great stuff. Keep up the good work
-reply by Pyous
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
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
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
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
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
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?
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
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
Similar Topics:
Wireless Networking And Switch
Lock Down Switch Port To Increase N...
2 Networks, Wrong One Takes Over
Bash Script To Display Your Ip Script to display your ip (12)
|
(12) Detecting Wirless Networks
|
HOME 





Setting up a Network Connection in Linux (Backtrack)
Low-Cost Internet Access Using Mechanical Backhaul
How To Fix Your NAT Tutorial
How to change your ip address (direct modem) Get unbanned hacking tip
Healthy Body = Functional Body. Hollywood Look Side Effect: Healthy Function

