How to configure static route on Cisco IOS Router

Hello Ugo

When you look at the routing table of a router, you will see something like this:

HQ#show ip route 
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 -IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

C       1.2.3.0 is directly connected, FastEthernet1/0
     192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
S       192.168.1.0/25 [1/0] via 10.2.2.2
S       192.168.1.128/25 [1/0] via 10.3.3.2

When a packet arrives that has a destination IP address of 192.168.1.55, it will match the static route of 192.168.1.0/25 and will be sent to the next hop IP of 10.2.2.2 according to the routing table. Why?

Well, look at the routing table entry of 192.168.1.0/25. This can also be written as 192.168.1.0 255.255.255.128. This specifies an IP address range of 192.168.1.0 to 192.168.1.128. Now the destination IP address of 192.168.1.55 falls within this range, so the packet was routed.

What if a packet arrives with a destination address of 55.1.2.3? It is not in the range of any of the routing table entries, so it will be dropped… unless a default route is configured.

The default route, when configured, will route any packet that doesn’t find any match in the routing table, to a particular next hop that you define. This is done using the 0.0.0.0 0.0.0.0 designation.

In the same way that the 192.168.1.0 255.255.255.128 defines a specific range of addresses, 0.0.0.0 0.0.0.0 also defines a range. Specifically, 0.0.0.0 0.0.0.0 defines a range from 0.0.0.0 to 255.255.255.255. In other words, all of the IPv4 address space.

Essentially it defines a network address of 0.0.0.0 with a subnet mask of 0.0.0.0. If you use these values to calculate the IP address range defined by these using subnetting as defined in this lesson, you will find that this is indeed the case.

So if you define a default route like so:

HQ(config)#ip route 0.0.0.0 0.0.0.0 170.170.3.4

It will appear in the routing table like so:

HQ#show ip route 
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 -IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is 170.170.3.4 to network 0.0.0.0

C       1.2.3.0 is directly connected, FastEthernet1/0
     192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
S       192.168.1.0/25 [1/0] via 10.2.2.2
S       192.168.1.128/25 [1/0] via 10.3.3.2
S*   0.0.0.0/0 [1/0] via 170.170.3.4

Here you can see that the network to which this route belongs is 0.0.0.0/0 which is all IPv4 addresses. If a packet doesn’t match any other routing table entry, this final default route entry will match all traffic.

I hope this has been helpful!

Laz