Windows Server 2008 : Basic Routing on a Server – Viewing the Routing Table with route print, Adding Routes to the Routing Table with route add

1. Viewing the Routing Table with route print

The route command displays and controls information in the local IP routing table on Windows systems. The route print -4 command enables you to view the IPv4 routing table.

Tip

You can also enter route print -6 to show only IPv6 information or enter route print to show both IPv4 and IPv6 information.

The following text shows a partial output of the route print command:

C:\>route print
======================================================================
Interface List
 10 ...00 03 ff 62 13 d7 ...... Intel 21140-Based PCI Fast Ethernet
Adapter
  1 ........................... Software Loopback Interface 1
======================================================================

IPv4 Route Table
======================================================================
Active Routes:
Network Destination  Netmask         Gateway      Interface    Metric
          0.0.0.0    0.0.0.0         192.168.1.1  192.168.1.5  276
        127.0.0.0    255.0.0.0       On-link      127.0.0.1    306
        127.0.0.1    255.255.255.255 On-link      127.0.0.1    306
  127.255.255.255    255.255.255.255 On-link      127.0.0.1    306
      192.168.1.0    255.255.255.0   On-link      192.168.1.5  276
      192.168.1.5    255.255.255.255 On-link      192.168.1.5  276
    192.168.1.255    255.255.255.255 On-link      192.168.1.5  276
        224.0.0.0    240.0.0.0       On-link      127.0.0.1    306
        224.0.0.0    240.0.0.0       On-link      192.168.1.5  276
  255.255.255.255    255.255.255.255 On-link      127.0.0.1    306
  255.255.255.255    255.255.255.255 On-link      192.168.1.5  276
======================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
          0.0.0.0          0.0.0.0      192.168.1.1  Default
======================================================================		  

 

The route print command has the following sections.

route print Section Comments
Interface list Lists all the physical and virtual network interface cards on the system.
IPv4 Route table Lists the routes known by the system and the path to the default gateway for unknown routes.
IPv4 Persistent Routes Persistent routes are stored in the system and remain even after reboots. The persistent route shown in the output is from the default gateway configured on the NIC.

 

The meat of the route print output is in the routing table. It has five columns, as explained in the following table.

Routing Table Column Comments
Network Destination Identifies the network destination. It is combined with the network mask to identify the network ID of the network.

Tip

The network destination of 0.0.0.0 indicates an unknown network and the default gateway is used. In other words, this path is used for all networks that are not known to the system.


Netmask The netmask, or subnet mask, is matched to the network destination to determine the network ID of the destination network.
Gateway Identifies the IP address of the router that the traffic must pass through to get to other networks.

Tip

On-link indicates that the system is connected to the network. The server used in the route print command is connected to the 192.168.1.0/24 network.


Interface Shows the IP address of the network interface card used to reach the network. Most systems have a single NIC, and it is used to reach all networks (except for the loopback address).

Note

The address of 127.0.0.1 is the loopback address used internally by the system.


Metric Identifies the cost. Systems use a least cost path so if there are multiple paths to the same network, the path with the lowest cost, or lowest metric, is used.

2. Adding Routes to the Routing Table with route add

You can add additional routes to a routing table for any system, even if the system is not a router.

Consider Figure 1, which shows a network with three subnets separated by two routers. Server2 is in Subnet B and is configured with a default gateway of 192.168.1.1. Because Server2 is in the 192.168.1.0/24 network, the routing table lists all traffic destined for this network with a gateway of On-link, and all unknown traffic uses the gateway of 192.168.1.1.

Figure 1. Network with three subnets


Note

The /24 in the address indicates the subnet mask is 255.255.255.0. More specifically, it indicates the first 24 bits of the IP address are a 1 and the last 8 bits are a 0.

Note

The output from the route print command shown earlier is from Server2.

 

Server2’s default gateway is192.168.1.1 (Router1). Any traffic that is not on the 192.168.1.0/24 subnet is routed to the default gateway. This gives Server2 a path to the 10.1.2.0/24 subnet and the Internet. However, Server2 doesn’t have a path to Subnet C unless an additional route is added.

You can add routes to other networks using the route add command. The basic syntax is

route [-p] add network-destination mask network-mask gateway [metric
metric]

The following table shows some common uses of the route add command. These examples add two additional routes to the routing table on Server2 (shown in Figure 22-1). One route goes to the 192.168.17.0 subnet, and the second route goes to Server3 (at 192.168.17.33).

route add Command Comments
Add a route to a network.

C:\>route add 192.168.17.0
mask 255.255.255.0
192.168.1.2 metric 300
C:\>route add 192.168.17.0
mask 255.255.255.0
192.168.1.2


The example adds a route to the 192.168.17.0 network with a subnet mask of 255.255.255.0 (192.168.17.0/24) through Router2 (at address 12.168.1.2). It uses a metric, or cost of 300.

Note

Because there is only one path to the distant subnet, the metric is meaningless. It can be omitted as shown in the second example.


If you run route print after this command, you see the following line:

192.168.17.0    255.255.255.0
192.168.1.2      192.168.1.5     21


Add a route to a specific computer.

C:\>route add 192.168.17.33
mask 255.255.255.255
192.168.1.2


When adding a route to a specific computer, the network mask is always set as 255.255.255.255. If you run route print after this command, you see the following line:

192.168.17.33  255.255.255.255
192.168.1.2      192.168.1.5     21


Add a persistent route.

C:\>route -p add
192.168.17.0 mask
255.255.255.0 192.168.1.2


The -p switch makes the route persistent so that it survives reboots. Without the -p switch, the route will not appear if the system was rebooted.

Note

If you create a route and want to change it to persistent, just repeat the command with the -p switch. You don’t have to use route change or delete the route before re-creating it.


 

If you ran the route print -4 command after adding the persistent route, it should look similar to the following listing:

IPv4 Route Table
======================================================================
Active Routes:
Network Destination  Netmask          Gateway       Interface  Metric
        0.0.0.0             0.0.0.0   192.168.1.1   192.168.1.5    276
      127.0.0.0           255.0.0.0   On-link         127.0.0.1    306
      127.0.0.1      255.255.255.255  On-link         127.0.0.1    306
127.255.255.255      255.255.255.255  On-link         127.0.0.1    306
    192.168.1.0        255.255.255.0  On-link       192.168.1.5    276
    192.168.1.5      255.255.255.255  On-link       192.168.1.5    276
  192.168.1.255      255.255.255.255  On-link       192.168.1.5    276
   192.168.17.0        255.255.255.0  192.168.1.2   192.168.1.5     21
  192.168.17.33      255.255.255.255  192.168.1.2   192.168.1.5     21
      224.0.0.0            240.0.0.0  On-link         127.0.0.1    306
      224.0.0.0            240.0.0.0  On-link       192.168.1.5    276
255.255.255.255       255.255.255.255 On-link         127.0.0.1    306
255.255.255.255       255.255.255.255 On-link       192.168.1.5    276
======================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
          0.0.0.0          0.0.0.0      192.168.1.1  Default
     192.168.17.0    255.255.255.0      192.168.1.2       1
======================================================================

					  

The routes that were added from the previous examples are bold in this listing. The metric of 21 was assigned automatically when a metric was not provided in the route add command, and a metric of 1 was assigned in the persistent route.