Routing

Packets move from one network to another via special network hosts called routers or gateways. A router is connected to at least two local networks and can forward IP packets from one network to the other. Each router has multiple IP addresses, one for each network.

../../_images/router.png

If an IP packet has a destination that is not within a connected network, it is redirected. The rules that govern this are set in a system’s routing table. If there is no explicit rule for a given target, the packet will be sent to the default gateway.

You can visualize the routing table on a Linux system with the ip route command.

$ ip route
default via 129.32.84.129 dev em4
129.32.84.128/25 dev em3 proto kernel scope link src 129.32.84.216
192.168.0.0/20 dev em1 proto kernel scope link src 192.168.0.1

In above example the first line shows the default route, in case an IP packet has not route to a directly attached network. Here any outside package is routed to 129.32.84.129 on network device em4.

It is followed by two rules for two connected networks. Packets addressed to any IP in the 129.32.84.128/25 network should be sent via the em3 network device with a source IP 129.32.84.216. Packets addressed to any IP in the 192.168.0.0/20 network should be sent via the em1 network device with a source IP 192.168.0.1.