Static routes can help provide precise control over routing but may create a burden when it comes to maintenance. As your network grows creating static routes everything can lead to inconsistencies when trying to modify your network.
Using static routes comes with some pros and cons. One advantage is that it requires zero network bandwidth since it requires no communication with other routers. The disadvantage is with no communications to routers and if a link goes down the path is no longer valid and network traffic will begin to drop.
Although dynamic routing protocols are preferred, sometimes configuring a static route will be needed in certain cases. There are different static route types and in this guide we will learn how to configure the following types:
- Directly Attached Static Routes
- Recursive Static Routes
- Fully Specified Static Routes
What is a directly attached static route
A directly attached static route is a route that that uses only the outbound next-hop interface. This route requires that the outbound interface be in an up state for the route to be installed in the routing table. We will use the below diagram to create connectivity between the two networks.
This simple test network can easily be replicated with the below config. As you see in the highlighted ip route command it directly indicates the outgoing interface.
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#int gi 0/0
R1(config-if)#ip address 10.0.1.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#int gi 0/1
R1(config-if)#ip address 10.0.0.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
R1(config)# ip route 10.0.2.0 255.255.255.0 gigabitEthernet 0/0
R2#conf t
R2(config)#int gigabitEthernet 0/1
R2(config-if)#ip address 10.0.2.1 255.255.255.0
R2(config-if)#no shut
R2(config-if)#int gi 0/0
R2(config-if)#ip address 10.0.1.2 255.255.255.0
R2(config-if)#no shut
R2(config)#ip route 10.0.0.0 255.255.255.0 gigabitEthernet 0/0
Now that the directly attached type of static route is configured we can test pinging both sides of the networks and their outputted results. We have full connectivity and looking at the S in the show ip route we have a route that states directly connected.
R1#ping 10.0.2.1 source 10.0.0.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.2.1, timeout is 2 seconds:
Packet sent with a source address of 10.0.0.1
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 2/2/2 ms
R1#show ip route
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
C 10.0.0.0/24 is directly connected, GigabitEthernet0/1
L 10.0.0.1/32 is directly connected, GigabitEthernet0/1
C 10.0.1.0/24 is directly connected, GigabitEthernet0/0
L 10.0.1.1/32 is directly connected, GigabitEthernet0/0
S 10.0.2.0/24 is directly connected, GigabitEthernet0/0
R2#ping 10.0.0.2 source 10.0.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0.2, timeout is 2 seconds:
Packet sent with a source address of 10.0.2.1
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 1/4/15 ms
R2#show ip route
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
S 10.0.0.0/24 is directly connected, GigabitEthernet0/0
C 10.0.1.0/24 is directly connected, GigabitEthernet0/0
L 10.0.1.2/32 is directly connected, GigabitEthernet0/0
C 10.0.2.0/24 is directly connected, GigabitEthernet0/1
L 10.0.2.1/32 is directly connected, GigabitEthernet0/1
What is a recursive static route
One of the other types of static routes configured is a recursive static route. This type of route uses the ip address of the next-hop address. This recursive lookup happens when the router queries the RIB to locate the route to the next hop address.
Recursive static routes require the next-hop address to exist in the routing table to install the route. Using the same topology as above a recursive route can be created using the below command:
R1#conf t
R1(config)#ip route 10.0.2.0 255.255.255.0 10.0.1.2
R1(config)#exit
R1#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
C 10.0.0.0/24 is directly connected, GigabitEthernet0/1
L 10.0.0.1/32 is directly connected, GigabitEthernet0/1
C 10.0.1.0/24 is directly connected, GigabitEthernet0/0
L 10.0.1.1/32 is directly connected, GigabitEthernet0/0
S 10.0.2.0/24 [1/0] via 10.0.1.2
R2#conf t
R2(config)#ip route 10.0.0.0 255.255.255.0 10.0.1.1
R2(config)#exit
R2#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
S 10.0.0.0/24 [1/0] via 10.0.1.1
C 10.0.1.0/24 is directly connected, GigabitEthernet0/0
L 10.0.1.2/32 is directly connected, GigabitEthernet0/0
C 10.0.2.0/24 is directly connected, GigabitEthernet0/1
L 10.0.2.1/32 is directly connected, GigabitEthernet0/1
The routes now show via instead of directly connected. Now the routes will get to the destined network via its next hop static ip address.
What is a fully specified static route
Now finally the last type of static route is called a fully specified static route. This type of route uses both an interface and next-hop ip address. Specifying the next-hop address and along with the outbound physical interface removes the recursive lookup that happens with recursive static routes.
Fully specified static routes are configured with the following commands:
R1#conf t
R1(config)#ip route 10.0.2.0 255.255.255.0 gigabitEthernet 0/0 10.0.1.2
R1(config)#exit
R1#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
C 10.0.0.0/24 is directly connected, GigabitEthernet0/1
L 10.0.0.1/32 is directly connected, GigabitEthernet0/1
C 10.0.1.0/24 is directly connected, GigabitEthernet0/0
L 10.0.1.1/32 is directly connected, GigabitEthernet0/0
S 10.0.2.0/24 [1/0] via 10.0.1.2, GigabitEthernet0/0
Conclusion
Now that we have learned about the different types of static routes, hopefully you have can administer these in ways that can help your environment. Static routes have their place in networks, but as you start to grow its best to look into ways to utilize dynamic routing protocols such as eigrp or ospf.
Thanks for your blog, nice to read. Do not stop.
No problem, thanks hope I was able to help where I can.
I am facing a problem that If i ping a 8.8.8.8 using Router1.
ping 8.8.8.8 source g0/1 is not pinging
Is 8.8.8.8 configured as one of the networks in your lab. If so you may need to add a route to get to that network. You could do something like “ip route 8.8.8.8 255.255.255.255 gigabitethernet 0/1” to test. If you can maybe share your config and I can take a look. You may also need the return route set to if its not a directly connected network