Introduction to Routing

Before you start

Objectives: learn what is routing, what are routing protocols, why do we use dynamic routing configuration, and why do we sometimes use static route configuration.

Prerequisites: you should already know about different Layer-3 devices such as routers, firewalls and layer 3 switches.

Key terms: routing, network, router, address, table, destination, route, protocol, ip, packet, static


What is Routing

Routing is the process of moving packets between different networks, or in other words – from one network to another. A Router is a device which takes packets received on one network interface, and sends them out on another network interface which is along the path to the destination network. Routers read packet headers to find addressing information, and send them on to their correct destination on the network or Internet. Routers maintain routing tables which are used to make forwarding decisions by looking for destination networks. The routing table in some router will contain:

  • all known destination networks
  • the interface or the next hop router in the path
  • a special value which is used to identify the cost or desirability to reach the destination network, called a metric. Metric is calculated using distance, delay or cost.

Routers automatically will automatically generate entries in their routing tables for all directly-connected networks. Information about other networks can be placed in the routing table using static or dynamic configuration. Let’s see an example. On the picture we can see three Routers (R1, R2 and R3), and five subnets. Let’s take a look at the R1 router, which has three networks which are connected directly. Notice that we also have indicated ports on R1 (eth0, eth1, eth2). How does do the routing table for the R1 router looks like?

 Routers

Simple Private Network

The routing table on the R1 router will include every known network. In our example, the router is directly connect to three separate networks, so it will have an entry for each of those networks. The routing table also identifies the interface that is used to connect to particular network. The R1 router can also reach two additional networks over other routers. In order to route packets through the network, it has to have an entry for each of those subnets in it’s routing table. The routing table looks something like this:

10.1.0.0 /16 eth0
10.2.0.0 /16 eth1
10.3.0.0 /16 eth2
10.4.0.0 /16 eth2
10.5.0.0 /16 eth1

Notice that in order to get to the 10.4.0.0 /16 network, router R1 has to use its eth2 interface, and for network 10.5.0.0 /16 it has to use its eth1 interface. The routing table also includes an address of the next router that’s in the path to the destination network. For the first three networks in our case, this is not an issue since they are directly connected to our R1 router. They don’t need a next hop address of another router, since the router simply sends the information out to that network. For the last two networks, the router will send the messages to other router which is along the path. Let’s say that the IP addresses for the network interfaces are set like shown on the picture.

IP Addresses

IP Addresses on Interfaces

How does the routing table on R1 router looks like now? Remember, we have to put the next hop address of the router along the path which is used to get to the destination network.

10.1.0.0 /16 eth0 –
10.2.0.0 /16 eth1 –
10.3.0.0 /16 eth2 –
10.4.0.0 /16 eth2 10.3.0.2
10.5.0.0 /16 eth1 10.2.0.2

So, to reach network 10.4.0.0 /16, the R1 will send packets to the 10.3.0.2 IP address, which is the next hop address of the next router in path. In order to get to the 10.5.0.0 /16 network, the router will send packets to 10.2.0.2 IP address.

Hosts on the Network

Let’s say that we have a computer called host1 on the 10.1.0.0 /16 network, with the IP address of 10.1.0.10. This hosts needs to communicate with another computer called host2, which is located on the 10.5.0.0 /16 network, and its IP address is 10.5.0.20.

 Computers

Computers on Different Networks

The host1 will create a packet that has the destination IP address of the destination device (10.5.0.20), along with its own source address in the IP packet header (10.1.0.10). It will then create a frame will be sent to the default gateway router. In our case the default gateway for the host1 is the 10.1.0.1 IP address (eth0 interface on the R1 router). The frame will also contain the MAC address of the host1, as the source MAC address, and MAC address of the destination device, which is R1 in this case.

When the frame gets to the R1 router, R1 will check the destination MAC address and realizes that the frame is sent to it. Because of that it will strip off the frame headers and look at the IP packet information to identify the destination IP address of the packet. It will see that the destination is on a different network, so it will check its routing table to identify the destination network for the packet. In routing table R1 will see that the 10.5.0.0 /16 network is available on its eth1, so it will send the packet out its eth1 interface to the next hop router which is 10.2.0.2. Before it does that, the R1 will create a new frame that uses the MAC address of the eth1 interface on R1 router as the source MAC address, and MAC address of the eth1 interface on R3 router as the destination MAC address. The packet header information (source and destination IP address) does not change in this step.

The frame will now get to the R3 router, which has its own routing table. R3 routing table will contain 10.5.0.0 /16 network, which is a directly connected network in its case. R3 router will then substitute the destination MAC address of the destination host2, and put its own MAC address of the eth2 interface as the source MAC address within the frame. Then it will send that frame to the destination device which is host2.

Remember, as packets flow through the network, each router checks its routing table to identify the destination network, the interface and the next hop router that the packet needs to be sent to.

Routing Tables

There are a couple different ways to put routes in the routing tables. Any network that the router is directly connected to gets put in the routing table automatically. For example, if we look at the picture above, we can see three networks which are directly connected to router R1. Those networks will be put in the routing table automatically when the interface is up. Routing table entries for remote networks can be entered manually, or learned dynamically. With manual entries an administrator must add each route. Manual routes stay in the routing table until they are manually removed. If the network changes then we must also manually change the routing table to reflect the change. With dynamic routing, routers use a routing protocol to learn about routes from other routers. Dynamic routing is easier to maintain because routers learn routes automatically, but it does require some network traffic, as routers talk to each other using specific protocol. When a change is made in the network, those changes are shared and learned automatically by all routers in the network. The change can be something like adding or removing a network, or changing a route to a destination. This automatic process takes some time because when a change is made, the other routers need time to share the information. To describe the state in which every router knows about every other network we use the term convergence.

Static Routes

Before convergence occurs, some routers in the network might have wrong information about different networks and their location. After convergence, each router has all information about the whole network. For larger networks we will probably use some kind of routing protocol to share information about networks between routers. The thing is, we can implement static and dynamic routing at the same time on a router, and that’s fine. We often use static and dynamic routing configuration when we have a private network connected to the Internet. Let’s say that we connect our R2 router to the Internet.

 Internet

R2 Connected to the Internet

In this case, the boundary of my private network and Internet is on the R2 router. R2 is now responsible for allowing communication to and from the Internet. Routers on our private network can share information using a routing protocol, and in that way learn about every other subnet within the private network. However, when we connect to the Internet, we don’t share our internal routes out with the Internet. To allow communication out to the Internet, we actually need a single route which will include all networks that are not our internal or private networks. So, anything that’s not internal needs to be sent out to the Internet. To do that we can use a special static route called the default route.The default route has a network address of 0.0.0.0 with a mask of 0.0.0.0. This default route ensures that every packet which doesn’t have a better match in the routing table, should be sent out to the Internet.

For example, let’s say that our host1 (10.1.0.10) computer want’s to send a packet to the IP address of 80.90.100.1. When the router receives a packet addressed to the 80.90.100.1, it would match the packet destination address with the default route of 0.0.0.0, since the router will not have any better route in its routing table. The IP address 80.90.100.1 simply doesn’t match any of the addresses that is in the routing tables of our routers. When that happens, the default route will be used. So, the static default route basically takes anything that is not intended for our private network, and takes it to the internet.

Remember that static route entries remain in the routing table until they are manually removed. When changes to the network occur, static entries must be modified, added, or removed manually.

Dynamic Routing Protocol

The routing protocol defines how routers communicate with each other to share and learn about other networks. Routing protocol also determines how updates to the routing table are communicated between routers. The routing protocol will generate some network traffic, but the advantage is that we don’t have to manually configure routing tables for all routers in our network. When configuring a dynamic routing protocol, we have to enable the protocol on the router and identify interfaces that the router will use for sharing and learning information about networks. In our example that we had, we can enable routing protocol on all routers on our private network, including router R2, which is connected to the Internet. We should enable routing protocol on every router interface that’s connected to a private network. That means that on R2 router, we should only enable routing protocol on its eth1 interface, since it is the only interface connected to our private network. We shouldn’t enable sharing of routing information on the interface which is connected to the Internet (eth2 on R2). Routers on the Internet don’t have to know our private routes, and our routers don’t have to know all routes that are used on the Internet. Packets from the Internet are routed to our network by the router from our ISP. ISP router will have a route in its routing table which will take packets to our network.

Remember that changes in routing information take some time to be propagated to all routers on our network. We can use dynamic and static routing together. We can use static configuration to identify any network which is not learned through the routing protocol. The common reason to create a static entry is to define a default route.

Remember

Routing is a process of moving packets from one network to another. Router uses the routing table to identify destination networks and forward packets to the next hop router, which is the next router in the path to the destination. Routing table entries can be created manually (for example, to define a default route), or learned dynamically through a routing protocol. We will typically implement dynamic routing because it is easier to maintain than static entries. Convergence describes the state when all routers have a correct view of the network, that is, when all routes have been shared and learned. As packets flow through the network, each router checks its routing table to identify the destination network, the interface and the next hop router that the packet needs to be sent to.