To be able to route a packet, a router must know at least the following:
As you would have realized by now, the essence of routing is how the router learns about the remote networks. Routing information is stored in the routing table also called the Routing Information Base (RIB). The RIB consists of routes to destination networks. Each route is a combination of the destination network address, subnet mask and the next hop towards the destination. There are three ways for a router to learn routes:
The following sections look at each of these routing types while implementing the first two types in our example network.
When you manually add routes to the routing table, it is called static routing. There are advantages and disadvantages in using static routing. The advantages are:
The disadvantages of static routing are:
To add a static route, use the following command in the global configuration mode:
ip route destination_network maskAs you can see, the command is pretty simple. You need to specify the destination network address, its mask and the address of the next hop towards the destination. You can also specify the exit interface instead of the next hop address. Using the exit interface will cause the router to reply or ARP query and response from the next hop router and is not generally recommended.
Figure 4-2 Static Routing
Let us configure our example network shown in Figure 4-2 (Figure 4-1 is repeated as Figure 4-2 so that you it is easier to understand), using static routing. To configure static routing, you need to look at the path traffic will taken from source to destination and back from destination to source. Each router in the path should know the source and destination network. So assuming our source is in network 192.168.1.0/24 (Host1) and our destination is in 192.168.5.0/24 network (Host3), let us look at the source to destination path, which is Router1->Router2->Router3.
Following the path back from the destination to source, which is Router3->Router2->Router1:
To view the routing table and verifying static routing, you can use the show ip route command. The output from all three routers in our example is given below:
Router1#sh 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 level-2
ia – 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
S 192.168.5.0/24 [1/0] via 10.1.1.2
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/1
C 192.168.1.0/24 is directly connected, FastEthernet0/0
Router2#sh ip route
-output truncated–
S 192.168.5.0/24 [1/0] via 10.1.2.2
10.0.0.0/24 is subnetted, 2 subnets
C 10.1.2.0 is directly connected, FastEthernet0/1
C 10.1.1.0 is directly connected, FastEthernet0/0
S 192.168.1.0/24 [1/0] via 10.1.1.1
Router3#sh ip route
-output truncated–
Gateway of last resort is not set
C 192.168.5.0/24 is directly connected, FastEthernet0/1
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.2.0 is directly connected, FastEthernet0/0
S 192.168.1.0/24 [1/0] via 10.1.2.1
Though the output of the show ip route command will be discussed in detail later in the chapter and in the next chapter, here are a few things you need to know now:
The outputs show that all the routes that you added above have taken effect and traffic can flow between the 192.168.1.0/24 and 192.168.5.0/24 networks in both directions now. You may have noticed that Router1 still does not know about the network between Router2 and Router3 (10.1.2.0/24) and Router3 does not know about the network between Router1 and Router2 (10.1.1.0/24). Though it is not necessary for them to know about these networks, from a troubleshooting perspective it better to add routes for these networks also as shown below:
Router1(config)#ip route 10.1.2.0 255.255.255.0 10.1.1.2
Router3(config)#ip route 10.1.1.0 255.255.255.0 10.1.2.1
After these routes are added, the example network has complete reachability using static routing.
Default routing can be considered a special type of static routing. The difference between a normal static route and a default route is that a default route is used to send packets destined to any unknown destination to a single next hop address. To understand how this works, consider Router1 from our example (Figure 4-2), without any static routes in it. When it receives a packet destined to 192.168.5.0/24 it will drop it since it does not know where the destination network is. If a default route is added in Router1 with next hop address of Router2, all packets destined to any unknown destination, such as 192.168.5.0/24 will be sent to Router2.
Default routes are useful when dealing with a network with a single exit point. It is also useful when a bulk of destination networks have to be routed to a single next-hop device. When adding a default route, you should ensure that the next-hop device can route the packet further, or else the next hop device will drop the packet.
Another point to remember is that when a more specific route to a destination exists in the routing table, the router will use that route and not the default route. The only time the router will use the default route is when a specific route does not exist.
The command to add a default route is same as that of adding a static route, but with the network address and mask set to 0.0.0.0 as shown below:
ip route 0.0.0.0 0.0.0.0 next-hopIn our example network, the only exit point for the 192.168.1.0/24 and 192.168.5.0/24 networks is towards Router2. Hence, we can remove the static routes from Router1 and Router3 and add default routes as shown below:
Router1(config)#no ip route 10.1.2.0 255.255.255.0 10.1.1.2
Router1(config)#no ip route 192.168.5.0 255.255.255.0 10.1.1.2
Router1(config)#ip route 0.0.0.0 0.0.0.0 10.1.1.2
Router3(config)#no ip route 10.1.1.0 255.255.255.0 10.1.2.1
Router3(config)#no ip route 192.168.1.0 255.255.255.0 10.1.2.1
Router3(config)#ip route 0.0.0.0 0.0.0.0 10.1.2.1
Remember that since Router2 has multiple exists, you cannot use default routing there. It still needs the static routes.
Take a look at the routing table on Router1 and Router3 after the above changes:
Router1#sh ip route
–output truncated–
Gateway of last resort is 10.1.1.2 to network 0.0.0.0
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/1
C 192.168.1.0/24 is directly connected, FastEthernet0/0
S* 0.0.0.0/0 [1/0] via 10.1.1.2
Router3#sh ip route
–output truncated–
Gateway of last resort is 10.1.2.1 to network 0.0.0.0
C 192.168.5.0/24 is directly connected, FastEthernet0/1
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.2.0 is directly connected, FastEthernet0/0
S* 0.0.0.0/0 [1/0] via 10.1.2.1
In the above output notice that the static route to 0.0.0.0/0 is now seen in the routing table. Apart from that, the gateway of last resort is now the next-hop as specified in the default route.
A second way of adding a default route would be to specify the exit interface instead of the next-hop address. For example, on Router1, you can use the following command instead of the one used above:
Router1(config)#ip route 0.0.0.0 0.0.0.0 fa0/0
This tells the route to forward all packets, destined to unknown destinations, out fa0/0. While this will accomplish the same thing, the big difference is that a static route with an exit interface specified will take preference over a static route with next-hop specified. This is because the administrative distance of a route with exit interface is lower than the other one. Administrative distance is covered later in the chapter.
A third way of defining a default route is using the ip default-network command. Using this command you can tell the router to use the next-hop address of a known network as the gateway of last resort. For example, on Router1, you can use the following two commands to set the gateway of last resort:
Router1(config)#ip route 10.1.2.0 255.255.255.0 10.1.1.2The second command will cause the router to lookup the route to 10.1.2.0 and use 10.1.1.2 (next-hop address for 10.1.2.0) as the gateway of last resort.
The routing table will look as shown below, after the above two commands are entered:
Router1#sh 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 level-2
ia – IS-IS inter area, * – candidate default, U – per-user static route
o – ODR, P – periodic downloaded static route
Gateway of last resort is 10.1.1.2 to network 10.1.2.0
S 10.1.2.0/24 [1/0] via 10.1.1.2
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/1
C 192.168.1.0/24 is directly connected, FastEthernet0/0
The difference between using the ip route command and the ip default-network command for adding a default route is that the route added using ip route command is local and does not get propagated through a routing protocol, if one is enabled. The route added through the ip default-network command will get propagated by a routing protocol.
Another thing to remember is that prior to IOS version 12.4, the ip classless command was not enabled by default. You will remember from Chapter 2, that if the ip classless command is not used, the router will do classful routing and expect a default mask on each interface. A side effect of this command not being present is that if the destination network is not in the routing table, the router will drop the packet. If you are using default routing, it is possible that you do not have any specific routes in the table. So you must enable classless routing using the ip classless command for default routing to work.
Dynamic routing is when protocols, called routing protocols, are used to build the routing tables across the network. Using a routing protocol is easier than static routing and default routing, but it is more expensive in terms of CPU and bandwidth usage. Every routing protocol defines its own rules for communication between routers and selecting the best route.
Routing protocols are broadly classified as Interior Gateway Protocols (IGP) or Exterior Gateway Protocols (EGP). IGPs are used to exchange routing information within internetworks that fall under a single administrative domain (also called Autonomous Systems). EGPs on the other hand are used to exchange routing information between different autonomous systems. Common examples of IGPs are Routing Information Protocol (RIP), Enhanced Interior Gateway Routing Protocol (EIGRP) and Open Shortest Path First (OSPF). These are covered in detail in the next chapter. On the other hand, Border Gateway Protocol (BGP) is an example of EGP. It is the protocol used for routing information exchange on Internet. It is beyond the scope of CCNA, hence we will not cover it in this book.
While the next chapter covers the IGPs in detail, the rest of this chapter is dedicated to basics of routing protocols that are necessary for you to understand before looking into specific protocols.