Create a static host route

In one of the previous lessons we’ve defined a static route for a specific subnet by using the subnet mask of 255.255.255.0 in the ip route command. IOS also allows you to specify a static host route for a single host by specifying the 255.255.255.255 (/32) subnet mask in the ip route command.

Static host routes are usually used when redundant paths exist. Consider the following example:

Static host route example network

In the example above you can see that we have a network of three routers and a switch connected to the 10.0.0.0/24 subnet. R1 has two paths to reach that subnet – one going through R2, and the other one through R3. Let’s say that we want to use the path going through R2 for all hosts, except the 10.0.0.10/24 host. For that host, we want to use the route going through R3. Here is how this can be done:

R1(config)#ip route 10.0.0.0 255.255.255.0 192.168.0.2
R1(config)#ip route 10.0.0.10 255.255.255.255 172.16.0.2

In the first command we’ve specified R1 to send all packets destined for the 10.0.0.0/24 network to 192.168.0.2 (the IP address of the interface on R2 connected to R1). However, for packets destined for the 10.0.0.10 host, we’ve instructed R1 to send all packets to 172.16.0.2 (the IP address of the interface on R3).

The two routes specified in the ip routes command above overlap (e.g. the IP address 10.0.0.10 is also included in the first command); however, routers always use a more specific route with the longer prefix length. Since /32 is a more specific route than /24, R1 will use the route going through R3 to reach 10.0.0.10.

We can verify that packets are indeed going through desired routes by using the traceroute command on R1:

R1#traceroute 10.0.0.5
Type escape sequence to abort.
Tracing the route to 10.0.0.5

  1   192.168.0.2     0 msec    0 msec    0 msec    
  2   10.0.0.5        0 msec    0 msec    0 msec    
R1#
R1#traceroute 10.0.0.10
Type escape sequence to abort.
Tracing the route to 10.0.0.10

  1   172.16.0.2      0 msec    0 msec    0 msec    
  2   10.0.0.10       0 msec    0 msec    0 msec    

NOTE
The hosts also need to be configured with a correct default gateway – 10.0.0.10 needs to have the IP address of R3 configured as its default gateway, and other hosts on the 10.0.0.0/24 subnet need to have R2 configure as their default gateway.
upravnik