A static route is an entry you write on a router saying that traffic for a given network goes to a given next-hop address. In a chain of three settlements the middle router needs two routes, each end router needs a single default route, and every router needs forwarding switched on, which comes to 4 routes in all, against 8 if the ends listed every network. Static routes never adapt to a failure, so draw them on paper first, give every link its own subnet, and test every path in both directions.

Part of Networking

Writing routing tables by hand for a small settlement network: the example topology, the commands, the counting rule and how it fails.

A Static Route Is A Hand-Written Instruction To Forward

Routing Basics states what static routing is and its limit: it is simple, predictable and right for a small stable network, but it does not adapt, so packets are lost until an administrator changes the table. This article shows the work. The carrier Internet Infrastructure gives the first step: enable forwarding in /etc/sysctl.conf with net.ipv4.ip_forward = 1, then configure static routes. Each route names a destination network and the next router to hand packets to; the next router must be on a network the sender is directly connected to (Routing Basics).

What You Need

  • An address plan with a /30 for every router-to-router link (CIDR Notation)
  • Forwarding enabled on every router
  • A diagram with every interface address on it

The Example Network

Three settlements in a line, A to B to C.

NetworkSubnet
A’s LAN10.1.0.0/24
B’s LAN10.2.0.0/24
C’s LAN10.3.0.0/24
Link A-B10.255.0.0/30
Link B-C10.255.0.4/30

Router interfaces: RA has 10.1.0.1 on its LAN and 10.255.0.1 on link A-B. RB has 10.2.0.1 on its LAN, 10.255.0.2 on link A-B and 10.255.0.5 on link B-C. RC has 10.3.0.1 on its LAN and 10.255.0.6 on link B-C. The two link subnets are /30: 10.255.0.0/30 has network .0, usable .1 and .2, broadcast .3; 10.255.0.4/30 has network .4, usable .5 and .6, broadcast .7.

Method: Write The Routes

Step 1: List what each router already knows Each router knows the subnets on its own interfaces. RA: 10.1.0.0/24 and 10.255.0.0/30. RB: all three of its subnets. RC: 10.3.0.0/24 and 10.255.0.4/30.

Step 2: Add a default route on each end RA and RC each have only one way out, so one route does for everything else. On Linux: ip route add default via 10.255.0.2 on RA, and ip route add default via 10.255.0.5 on RC.

Step 3: Add specific routes in the middle RB must say where the two outer LANs are: ip route add 10.1.0.0/24 via 10.255.0.1 and ip route add 10.3.0.0/24 via 10.255.0.6.

Step 4: Make them survive a reboot Routes added with a command are lost at restart. Put them in the system’s network configuration, which differs between distributions (general knowledge; check the documentation of the system you installed).

Step 5: Test in both directions From a machine in A’s LAN, ping a machine in C’s LAN. A reply needs the return route as well, so also ping from C to A. If one direction works and not the other, a route is missing at one of the routers. Use traceroute (Routing Basics) to see where it stops.

Worked Example: How Many Routes

A router needs a route for every subnet in the network that is not on one of its own interfaces. The network has 5 subnets (3 LANs and 2 links).

  • RA has 2 directly connected subnets, so it needs 5 - 2 = 3 routes (B’s LAN, C’s LAN and link B-C), or one default route.
  • RB has 3 directly connected, so it needs 5 - 3 = 2 routes (the two outer LANs).
  • RC has 2 directly connected, so it needs 3 routes, or one default route.

Listing every network: 3 + 2 + 3 = 8 routes. With default routes at both ends: 1 + 2 + 1 = 4. The default routes are safe here because RA and RC each have one exit; they would not be on a router with two ways out.

A fourth settlement D beyond C adds 2 subnets: D’s LAN and the C-D link. RB would need 2 more routes, RC would need a route to D’s LAN through the new link, and RA’s default route covers both. That growth is the cost of static routing: several routers must be edited every time the network changes.

Common Mistakes

  • A next hop that is not on a directly connected subnet — the router has no way to reach it, so the route does nothing
  • Two routers each with a default route pointing at the other — a packet bounces between them until its time-to-live runs out (Packet Structure)
  • Forgetting the return route — the reply is lost and the symptom is identical to a forward failure
  • Leaving forwarding off — a router with forwarding off silently drops transit traffic
  • Keeping the routes only in memory — the first reboot removes them; keep a paper copy of each router’s table

What’s Next