Routing table
lastmod 2025-02-11created 2016-03-1516 edits
A routing table is used in computer networks to translate a destination address into the network route needed to reach that destination. The most important purpose of a routing protocol is precisely to build this routing table.
In the simplest model, hop-by-hop routing, each router's routing table holds, for every destination, the information about the next router the packet must pass through to reach that destination. Assuming the routing tables are consistent, data can be sent anywhere on the network with this simple algorithm alone: receive a packet, look up the routing table to find the next router, and hand the packet to that router. In practice, however, hop-by-hop routing is rapidly disappearing, pushed aside by layered architectures such as MPLS. In a layered architecture a single table lookup can replace several forwarding steps, which reduces table lookup time and therefore increases network performance.
The requirement to store routes to a huge number of destinations in limited storage space is a major challenge in building routing tables. One important basic assumption in routing is that similar addresses are destinations at similar addresses will be adjacent, which allows many destination addresses to be managed in a single routing table entry. This grouping method of putting many destinations into one entry has changed a lot over time and is still an active research topic. The grouping technique most widely used on the Internet today is the bitwise prefix-matching scheme called CIDR (Classless Inter-Domain Routing).
Every router on the network must hold consistent routing table information; otherwise loops can occur. This is a serious problem especially in hop-by-hop routing, because routers may pass packets back and forth to each other endlessly even though each appears to have a correct routing table. Avoiding routing loops is one of the important issues in designing routing protocols.
Categories
Tools
- network-manager (linux) - include route
- tracert (windows)
- traceroute (linux)
- iproute2 (ip)
Routing protocols
There are three main kinds of routing algorithms.
- Distance vector algorithm (Distance Vector Routing Algorithm)
- Link state algorithm (Link State Routing Algorithm)
- Path vector algorithm (Path Vector Algorithm)
Example
Checking the routing table of my PC
Use ipconfig to check TCP/IP settings, and use the netstat -r or route print command to view the routing table.
From the output above, only the parts related to the routing table have been rearranged with labels.
| Name | Network Destination | Netmask | Gateway | Interface | Metric |
| default route | 0.0.0.0 | 0.0.0.0 | 203.255.113.254 | 203.255.113.34 | 1 |
| loopback | 127.0.0.0 | 255.0.0.0 | 127.0.0.1 | 127.0.0.1 | 1 |
| subnet network | 203.255.113.0 | 255.255.255.0 | 203.255.113.34 | 203.255.113.34 | 1 |
| LAN card | 203.255.113.34 | 255.255.255.255 | 127.0.0.1 | 127.0.0.1 | 1 |
| subnet broadcast | 203.255.113.255 | 255.255.255.255 | 203.255.113.34 | 203.255.113.34 | 1 |
| multicast | 224.0.0.0 | 224.0.0.0 | 203.255.113.34 | 203.255.113.34 | 1 |
| limited broadcast | 255.255.255.255 | 255.255.255.255 | 203.255.113.34 | 203.255.113.34 | 1 |
Routing table explained (columns)
It consists of 5 columns and determines where my PC's packets should go out. The packet's Destination address is masked with the Netmask to determine the Network Destination, and the packet is then sent to the appropriate Interface.
- Netmask
- The packet's Destination address is ANDed with the Netmask.
- The netmask determines which Network Destination to go to
- Network Destination
- After the AND operation, the packet's Destination address is compared with the Network Destination.
- Interface ( address of the LAN card that sends the packet out )
- The packet is sent to the Interface whose Network Destination matched
- Gateway
- Where the packet goes after leaving the Interface.
- Either your own LAN card address or the gateway of the local subnet (usually a router).
- Metric
- The number of hops to the destination.
- The local LAN counts as one hop
- The Metric is used to decide the best router path
Routing table explained (rows)
It has 7 rows; each row makes up the routing table and sends packets matching its Network Destination to its Interface.
- default route
- If none of the routing table entries match, the packet is sent to the Gateway of the default route.
- Above, it goes to
203.255.113.254, which is usually the router's address.
- loopback
-
127.0.0.1is the software loopback address. - It points to the host itself.
- subnet network
- Indicates the subnet network address of the IP address.
- Since the IP address is
203.255.113.34and the Subnet Mask is255.255.255.0, the AND operation gives203.255.113.0as the network address.
- LAN card
- Means your own IP address.
- subnet broadcast
-
203.255.113.255, the last address of203.255.113.0above, is used for broadcast.
- multicast
- The row representing Class D multicast.
- An address used to deliver messages to a specific group.
- limited broadcast
- A broadcast address that cannot pass through routers.
- Delivered to all hosts on the same subnet.
Routing table lookup order
According to a Microsoft document (Q140859), the lookup order of the routing table rows is as follows:
From the most unique route(host address) to most generic(default gateway)
- host address
- Subnet address
- Network address
- Default gateway
For example, when you send the command ping 207.46.131.137:
- AND
207.46.131.137with the Netmask column of the LAN card row (255.255.255.255):207.46.131.137 - Compare the result above, 207.46.131.137, with the Network Destination of the LAN card row
- If they are the same, send the packet to the Interface of the LAN card row.
- If they differ, compare against the other routing table entries in lookup order
- If no matching Network Destination is found, send the packet to the Gateway of the default route (
0.0.0.0). - Repeat from the first step to send the next packet.
Routing Table on Linux
See NetworkManager#Routing Table on Linux for details.
How to set up communication between IPs on different ranges
See Internet Protocol#How to set up communication between IPs on different ranges for details.