22 October 2010

Adding a static route using netsh and route commands

It is recommended by MS that from Windows 2008 onward you use the netsh command shell rather than route to manage routes on your servers.

The Network Shell - netsh
"is a command-line utility that allows you to configure and display the status of various network communications server roles and components after they are installed on computers running Windows Server® 2008 R2 and Windows Server® 2008"

True, you can do tons of things in netsh if you are willing to jump in there and have a look.  I suggest you take a manual with you http://technet.microsoft.com/en-us/library/cc754516(WS.10).aspx

For this article I am going to cover static routes.  This is something I always used to do with the route command.  Check out Static Routing 101

We will be configuring a machines with dual nics, one called Internal and the other External the external will be configured with the default gateway in the TCP/IP properties.  We want to add a static persistent route for all traffic to the 10.x.x.x range to be routed to the internal networks as opposed to the default gateway.

Using the route command

route add MASK -p

To check that it was completed successfully you can review the routes.

route print

To delete the route

Route delete

Using netsh

show interfaces (make note of the correct interface name)
add route "Internal"

To check that it was completed successfully you can review the routes.

netsh interface ipv4 show route

To delete the route

netsh interface ipv4 delete route "Internal"

Since they both configure the same thing you can also use the route to check the netsh setting and vice versa.
Just for reference here is the add route command details from technet.

add route

Adds a route for a specified prefix. Time values can be expressed in days (d), hours (h), minutes (m), and seconds (s). For example, 2d represents two days.


add route [prefix=]IP4Address/Integer [[interface=]String] [[nexthop=]IPv4Address] [[siteprefixlength=]Integer] [[metric=]Integer] [[validlifetime=]{Integer | infinite}] [[preferredlifetime=]{Integer | infinite}] [[store=]{active | persistent}]


[ prefix=] IPv6Address/Integer
Required. Specifies the prefix for which to add a route. Integer specifies the prefix length.
[[ interface=] String]
Specifies an interface name or index.
[[ nexthop=] IPv6Address]
Specifies the gateway address, if the prefix is not on-link.
[[ siteprefixlength=] Integer]
Specifies the prefix length for the entire site, if the prefix is not on-link.
[[ metric=] Integer]
Specifies the route metric.
[[ validlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the route is valid. The default value is infinite.
[[ preferredlifetime=]{ Integer| infinite}]
Specifies the lifetime over which the route is preferred. The default value is infinite.
[[ store=]{ active| persistent}]
Specifies whether the change lasts only until the next boot (active) or is persistent (persistent). The default selection is persistent."

It appears that the route command is, or has been deprecated and will not be around in the next version of Windows.  Netsh is a extremely powerful tool if you take the time to get to know it.  In just a few minutes of scratching around I found some of useful stuff that is not available anywhere else.  Don't be intimidated but be careful. By using netsh interface tcp reset  you will clear every singe network setting ......


Mike Burr said...

Hi, I found your post interesting because I was researching an issue related to the route command. Out of curiosity, can you identify where you found that the Windows route command is being deprecated?

Etienne Liebetrau said...

Hi Mike

When I wrote the article in 2010 the speculation was that it would be removed from "the next version of windows" Since then we have actually gotten our hand on the next version.

I just double checked now on Windows 8 RC and indeed it is still there.

Here is an official list " Features Removed or Deprecated in Windows Server "8" Beta"


I for one am very glad that it is still with us.

Anonymous said...

Hi Mike,
Your post really helped me, and taught me something I couldn't find over the net (except here).
Is there also a way of doing the same with "arp -s"?
And what are the advantages and disadvantages of using each one of the methods over the other?

Anonymous said...

Hi, very usefull. When you put "route add -p xxxx" and check out the routing with "netsh interface ipv4 show route" you can see that the routes are over the default interface, so the only way to put the routes over the "Internal" interface is using netsh.

Anonymous said...

Great! thanks a lot for this post!
Spent a lot of time searching for this...

Anonymous said...

Hi Netsh works!! but added entries not showing TMG2010 - Network topology routes.

Post a Comment