NT/2000/XP: Add a Temporary Route to the Windows Routing Table

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 tutorial 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.

Using names instead of numbers for the gateway and subnets is possible. 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 the guess Windows makes, the optional if {interface} parameter can be used. To specify that the previous route example should use interface 2 (identified with the hexadecimal value 0×2 in the route print command), use the following command:

route add 192.168.15.123 172.16.10.1 metric 10 if 2

 

About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

5 Responses to “NT/2000/XP: Add a Temporary Route to the Windows Routing Table”

  1. May 18, 2010 at 7:54 am, qq said:

    how to fix the value of interface list..

    Reply

  2. August 03, 2011 at 1:43 pm, Peter said:

    simply do a ROUTE PRINT values of your interfaces are infront of iface name

    Reply

  3. October 05, 2011 at 11:54 pm, jalal said:

    The ROUTE is not working for a MAIL SERVER.
    I used the add route command to access the standby mail server 192.168.1.17 instead of the main mail server 192.168.1.11, but the connection to the standby mail server could not be established
    route add 192.168.1.11 mask 255.255.255.255 192.168.1.17

    Reply

  4. March 01, 2012 at 1:08 am, karthikbhat said:

    Hey there,
    Even I was facing the same problem as i was not able to save the routing information , but then I found a file where i added these routing information and then on subsequent boot up I was able to get this routing info being taken.

    the file is
    /etc/rc.d/rc.local

    Reply

  5. March 01, 2012 at 1:08 am, karthikbhat said:

    Hey there,
    Even I was facing the same problem as i was not able to save the routing information , but then I found a file where i added these routing information and then on subsequent boot up I was able to get this routing info being taken.

    the file is
    /etc/rc.d/rc.local

    Reply

Leave a Reply