Kaigai Blog living abroad in my twenties

【My Study Note】Basic Routing Concepts

Infotech Networking

Basic Routing Concepts


Routing is one of those things that is very simple and very complex. At a very high level, what routing is and how routers work is actually pretty simple. But underneath the hood, routing is a very complex and technologically advanced topic. Today most intensive routing issues are almost exclusively handled by ISPs and only the largest of companies.

From a very basic standpoint, a router is a network device that forwards traffic depending on the destination address of that traffic. A router is a device that has at least two network interfaces, since it has to be connected to two networks to do its job.

Basic routing has just a few steps

  1. A router receives a packet of data on one of its interfaces.
  2. The router examines the destination IP of this packet.
  3. The router then looks up the destination network of this IP in its routing table.
  4. The router forwards that out though the interface that’s closest to the remote network. As determined by additional info within the routing table.

These steps are repeated as often as needed until the traffic reaches its destination.

Let’s imagine a router connected to two networks. We’ll call the first network, Network A and give it an address space of 192.168.1.0/24. We’ll call the second network, Network B and give it an address space of 10.0.0.0/24.

The router has an interface on each network. On Network A, it has an IP of 192.168.1.1 and on Network B, it has an IP of 10.0.254. Remember, IP addresses belong to networks, not individual nodes on a network. A computer on Network A with an IP address of 192.168.1.100 sends a packet to the address 10.0.0.10. This computer knows that 10.0.0.10 isn’t on its local subnet. So it sends this packet to the MAC address of its gateway, the router.

The router’s interface on Network A receives the packet because it sees that destination MAC address belongs to it. The router then strips away the data-link layer encapsulation, leaving the network layer content, the IP datagram.

Now, the router can directly inspect the IP datagram header for the destination IP field. It finds the destination IP of 10.0.0.10. The router looks at it’s routing table and sees that Network B, or the 10.0.0.0/24 network, is the correct network for the destination IP. It also sees that, this network is only one hop away. In fact, since it’s directly connected, the router even has the MAC address for this IP in its ARP table.

Next, the router needs to form a new packet to forward along to Network B. It takes all of the data from the first IP datagram and duplicates it. But decrements the TTL field by one and calculates a new checksum.

Then it encapsulates this new IP datagram inside of a new Ethernet frame. This time, it sets its own MAC address of the interface on network B as the source MAC address. Since it has the MAC address of 10.0.0.10 in its ARP table, it sets that as the destination MAC address.

destinationのネットワークのMacアドレスをSouceにし、そのネットワーク内にある送りたい機器のMacアドレスをdestinationにする

Lastly, the packet is sent out of its interface on Network B and the data finally gets delivered to the node living at 10.0.0.10.

That’s a pretty basic example of how routing works, but let’s make it a little more complicated and introduce a third network. Everything else is still the same. We have network A whose address space is 192.168.1.0/24. We have network B whose address space is 10.0.0/24. The router that bridges these two networks still has the IPs of 192.168.1.1 on Network A and 10.0.0.254 on Network B.

2つのネットワークを繋げているRouterのNetworkA側のIPアドレスが192.168.1.1でB側のIPアドレスが10.0.0.254ってこと

But let’s introduce a third network, Network C. It has an address space of 172.16.1.0/23.

There is a second router connecting network B and network C. It’s interface on network B has an IP of 10.0.0.1 and its interface on Network C has an IP of 172.16.1.1.

This time around our computer at 192.168.1.100 (inside the network A) wants to send some data to the computer that has an IP of 172.16.1.100 (inside the network C).

We’ll skip the data-link layer stuff, but remember that it’s still happening, of course.

The computer at 192.168.1.100 knows that 172.16.1.100 is not on its local network, so it sends a packet to its gateway, the router between Network A and Network B. Again, the router inspects the content of this packet. It sees a destination address of 172.16.1.100 and through a lookup of its routing table, it knows that the quickest way to get to the 172.16.1.0/23 network is via another router. With an IP of 10.0.0.1 (Network B).

The router decrements the TTL field and sends it along to the router of 10.0.0.1. This router then goes through the motions, knows that the destination IP of 172.16.1.100 is directly connected and forwards the packet to its final destination. That’s the basics of routing.

The only difference between our examples and how things work on the Internet is scale. Routers are usually connected to many more than just two networks. Very often, your traffic may have to cross a dozen routers before it reaches its final destination.

And finally, in order to protect against breakages, core Internet routers are typically connected in a mesh, meaning that there might be many different paths for a packet to take.

Still, the concepts are all the same. Routers inspect the destination IP, look at the routing table to determine which path is the quickest and forward the packet along the path. This happens over and over. Every single packet making up every single bit of traffic all over the Internet at all times.