Jump to content

Trying to use netsh command but can't get syntax right


Nomen

Recommended Posts

This is not necessarily XP-specific, but I am following instructions written for XP, on an XP system. Specifically, I'm following the examples on these pages:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/netsh_int_ip.mspx?mfr=true

https://technet.microsoft.com/en-ca/library/bb490943.aspx

such as trying this:

netsh interface ip>set address local static 192.168.2.123 255.255.255.0 192.168.2.2

or this:

netsh interface ip>set address name="Local Area Connection 4" source=static addr=192.168.2.123 mask=255.255.255.0 gateway=192.168.2.2

and getting this response:

The syntax supplied for this command is not valid. Check help for the correct syntax.

All I want is a command-line function to set the gateway IPv4 address. What is the correct syntax to do this from a command prompt?

Link to comment
Share on other sites


Ah - yes. It seems to need gwmetric as part of the syntax, although the documentation doesn't mention it. Seems these people also came across this situation: http://forums.scotsnewsletter.com/index.php?showtopic=43164

I haven't tried this yet, but this apparently works:

netsh interface ip set address name="Local Area Connection 2" gateway=192.168.1.3 gwmetric=1

If all I want to change is the gateway IP, then would this work?

netsh interface ip set gateway=192.168.1.3 gwmetric=1

Bonus question: Can XP have 2 gateway IP settings, and dynamically figure out which one to use? The TCP/IP properties for win-98 has a list box for "installed gateways" and says the first one in the list is the default, but I have no idea if it really works - will it try other entries as needed from the list?

Link to comment
Share on other sites

Ah - yes. It seems to need gwmetric as part of the syntax, although the documentation doesn't mention it.

Actually it *somewhat* does:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/netsh_int_ip.mspx?mfr=true

 

Syntax

set address [name=]InterfaceName [source=]{dhcp | static [addr=]IPAddress [mask=]SubnetMask [gateway=]{none | DefaultGateway [[gwmetric=]GatewayMetric]}}

Top of page

Parameters

[name =] InterfaceName : Required. Specifies the name of the interface for which you want to configure address and gateway information. The InterfaceName parameter must match the name of the interface as specified in Network Connections. If InterfaceName contains spaces, use quotation marks around the text (for example, "Interface Name").

[source=]{dhcp | static [addr=]IPAddress [mask=]SubnetMask [gateway=]{none | DefaultGateway [[gwmetric=]GatewayMetric]}} : Required. Specifies whether the IP address to configure originates from a Dynamic Host Configuration Protocol (DHCP) server or is static. If the address is static, IPAddress specifies the address to configure, and SubnetMask specifies the subnet mask for the IP address being configured. If the address is static, you must also specify whether you want to leave the current default gateway (if any) in place or configure one for the address. If you configure a default gateway, DefaultGateway specifies the IP address of the default gateway to be configured, and GatewayMetric specifies the metric for the default gateway to be configured.

 

though not in an extremely "clear" manner.

 

AFAIK gateways are in a given order and the first one is what is used, the second is is a "fallback" device that only is used if the first fails and so on....

The routing table (if any)  is what is otherwise used for choosing the gateway to be used, and here comes (again) into play the metric:

http://serverfault.com/questions/59442/routing-decision-when-there-are-two-default-gateways-on-windows

https://technet.microsoft.com/en-us/library/cc779696(WS.10).aspx

http://blog.palehorse.net/2009/08/24/using-windows-7-with-multiple-gateways-and-dhcp/

 

jaclaz

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...