Friday, December 6, 2024
HomeWindowsWindows networkingNT/2000/XP: Add a Temporary Route to the Windows Routing Table

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 0x2 in the route print command), use the following command:

route add 192.168.15.123 172.16.10.1 metric 10 if 2

Quinn McHenry
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.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!