NT/2000/XP: Add a temporary route to the Windows routing table

Home -> Windows -> Network administration

63097 views

From the computer of: qmchenry (338 recipes)
Created: Jun 23, 2004


Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

A route describes the gateway IP address and network interface to use when sending packets to a network. The routing table on a host holds a list of destination networks and the routes to those networks. This recipe describes adding entries to this routing table that will not persist following a reboot. These temporary routes are useful during troubleshooting or when making changes to the network topology.

To add a route to the network 192.168.1.1/24 (corresponding to a subnet mask of 255.255.255.0) through the gateway 172.16.100.1, use the following command:

route add 192.168.1.1 mask 255.255.255.0 172.16.100.1


This is the simplest method of adding a temporary route. The subnet mask parameter is optional and defaults to 255.255.255.255 which specifies that the target is a single IP address instead of a network.

An optional routing metric can be added to the route command for more complex situations. The metric can be considered a cost for using the route. If a routing table contains multiple routes to the same destination, the cheapest route (lowest cost or metric) will be used. To add a route with a metric of 10 to the host 192.168.15.123 through the gateway 172.16.10.1, use the following command:

route add 192.168.15.123 172.16.10.1 metric 10


In this case, the subnet mask is not given so the command defaults to the mask 255.255.255.255.

It is possible to use names instead of numbers for the gateway and subnets. If you use a name for the gateway, the name is looked up in the hosts file ({windows_home}\system32\drivers\etc\hosts) and the corresponding IP address is used. Named subnets will be looked up in the networks file ({windows_home}\system32\drivers).

If multiple network interfaces are available to route to the same destination, the interface can be specified in the route command. The interface number associated with the interface is shown using the route print command. Windows will automatically guess which interface is most appropriate for the given route. If you are dissatisfied with Windows's guess, the optional if {interface} parameter can be used. To specify that the previous route example should use interface 2 (identified with the hexadecimal value 0x2 in the route print command), use the following command:

route add 192.168.15.123 172.16.10.1 metric 10 if 2

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.





Related recipes:

  NT/2000/XP: Display or view the Windows routing table
  Connect to XP's Remote Desktop Connection with Windows 95,98,ME,NT, or 2000
  NT/2000/XP: Free GUI IP Configuration Tool from Microsoft
  Windows: Service Managing Through Command Line
  Add The Stored User Names and Passwords Applet to XP's Control Panel
  XP: Set or configure static network IP address wtih netsh from command line
  Encrypt Files in XP Using EFS
  Setup and Use a Direct Connection to Easily Transfer Data
  Opening Blocked Attachments with Outlook 2003
  Increase Number of Windows Open before XP Starts to Group Them

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.