Monday, December 12, 2011

Using netsh to change only gateway IP address?

I'm currently developing simple program that run netsh script to change IP address.



I can use netsh to change my entire IP address (IP address, subnet mask, and gateway).



the command is like:



netsh interface ip set address ';Local Area Connection'; 10.0.0.9 255.0.0.0 10.0.0.1



so the IP will become 10.0.0.9, the subnet mask will become 255.0.0.0, and the gateway will become 10.0.0.1.



But the problem is how can I use netsh to change only the gateway, while leaving the IP address and the subnet mask just the way it is?



I'm going thru the netsh help, and trying this method:



netsh interface ip set address name=';Local Area Connection'; gateway=10.0.0.1



it's not working. like getting the ';syntax is not valid'; error. I'm also trying some other variation like these below, but none working also.



netsh interface ip set address name=';Local Area Connection'; gateway=';10.0.0.1';



netsh interface ip set address ';Local Area Connection'; gateway=10.0.0.1



can somebody help me? thanks.Using netsh to change only gateway IP address?
If it is just a default gateway what you want to change then, you may consider using route command.



Try following script:

******************************

#To remove existing default gateway

route delete 0.0.0.0

#To configure new gateway

route add 0.0.0.0 10.0.0.1

******************************



Hope this helps :)Using netsh to change only gateway IP address?
netsh interface ip set address name=';RJ45'; source=static gateway=192.168.2.1 gwmetric=1



And... Ok! Only gataway address is affected. :)

Report Abuse

No comments:

Post a Comment