Routing: ip route, default gateway, IP forwarding
Sign in to read this lesson
A Linux server decides where to send a packet by looking at its routing table — just like a router. In this lesson we learn to read the routing table, the default gateway, adding static routes, the longest-prefix rule, and the IP forwarding and NAT that turn Linux into a small router.
What you will learn
ip route(short:ip r) shows the routing table — likeshow ip routeon Cisco.default via 10.20.0.1— everything that matches no other route goes to the gateway.- Selection follows the longest prefix rule: a
/24route beats a/16and thedefault. sudo ip route add 10.30.0.0/24 via 10.20.0.254— a temporary static route; netplan for a permanent one.- To be a router you need
net.ipv4.ip_forward = 1, and for internet access NAT (masquerade).
The lesson has 5 key points, an explanation and 5 questions. It opens with a package.