A router by default only knows about networks that are directly connected to it. If a router is not directly connected to the final destination subnet, then the router needs to learn, or be told how to get to that destination.
Learning routes can take place through the use of routing protocols, however in this article I’m going to cover how to configure static routes to tell the router how to get to the destination network.
In the live demo you will notice that all the configuration is done on a router named AOIP.ORG and in the diagram below you will see that AOIP.ORG is only connected to the subnet 192.168.1.0 /24 and the loopback interface which has an IP address of 5.5.5.5 /24. If our router is to send a packet to any other network, it will have to have routing configured on it. If however it wants to send a packet to the network 192.168.1.0 or 5.5.5.0 it could do this without creating routes as both networks are directly connected.
To illustrate this point, I tried to ping the IP address 10.0.1.2 which is connected to R2, and is not directly connected to AOIP.ORG. You will see that the ping was unsuccessful since AOIP.ORG does not have a route to the network 10.0.1.0 and it’s not connected directly to it either.
After adding a static route of ‘ip route 10.0.1.0 255.255.255.0 192.168.1.1’ the ping works perfectly.
The ‘ip route’ command is broken up as follows
‘ip route {destination network} {subnetmask to match} {next-hop-address} {administrative distance}‘
The {destination network} is the network I would like to route to. (10.0.1.0)
The {subnetmask to match} entry identifies how much of the destination network needs to match. So in our case we are telling it to check the first 3 octets for a match ie: 10.0.1 and not worry about the value in the last octet. (255.255.255.0)
Note: I could have created a {destination network} of 10.0.0.0 and a {subnetmask} to match of 255.0.0.0. This would have told the router that if a packet was going to ANY network starting with IP address ’10’ it could use this route. I have been as specific as possible and hence told the router to match ‘10.0.1’
The {next-hop-address} is the next router that the packet will be sent to and must be directly connected to the router you issue this command on (192.168.1.1)
The {administrative distance} I have not used in our example, but this is used to indicate how trust worthy the route is. If there are multiple options for the router to choose from, it will choose the most trust worthy, the lowest number.
Note: Routing has already been configured on all the other routers in the example below.