6.5. Configuring Static Routing Across Subnets
Problem
You have several private subnets to traverse, and they are not all connected to the same physical router, so how do you give them access to each other?
Solution
There is an easy way and a hard way. The hard way is to create static routes from router to router. Suppose you have three subnets and three routers, like Figure 6-3 shows.

Figure 6-3. Three subnets and three routers
Each router will need two routes. For example, you would set the routes on Router C like this:
# route add -net 192.168.10.0/24 gw 172.24.0.25 eth1
# route add -net 172.16.5.0/24 gw 172.24.0.25 eth1Then, Router B:
# route add -net 192.168.10.0/24 gw 172.16.5.125 eth1
# route add -net 172.24.0.0/24 gw 172.16.5.125 eth1And, Router A:
# route add -net 172.16.5.0/24 gw 192.168.10.100 eth1
# route add -net 172.24.0.0/24 gw 192.168.10.100 eth1Now, hosts on all three subnets can communicate with each other. Deleting routes is done like this:
# route del -net 192.168.10.0/24This is a fair bit of work; you have to know netmasks, and be very careful not to make typos. The easy way is to put all three routers on the same network, like in Figure 6-4.

Figure 6-4. Three routers on the same network
Now, you don't need to set routes at all.
Discussion
You may also use ip to set and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access