How to configure static routes in Fedora

Você pode ver este post em português também.

Routes. The unique way I like to see them: Signs and routes

Recently I had to do a fix inside the routing table of a server. I’ve found out a better and more elegant way than this usual:

touch /etc/rc.d/rc.local
echo "touch /var/lock/subsys/local" > /etc/rc.d/rc.local
echo "route add default gw 10.10.0.1 eth0" > /etc/rc.d/rc.local
echo "route add -net 10.1.0.0 netmask 255.255.0.0 gw 10.2.0.1 eth0" > /etc/rc.d/rc.local

Inside Fedora GNU/Linux, static routes can be added in specific files for each one of its interfaces. These files are located at /etc/sysconfig/network-scripts/. The filename must match the route-ifname format. So if you want to add a route to the eth0 interface, the filename must be called /etc/sysconfig/network-scripts/route-eth0. It’s an important detail because an error naming in this file isn’t able to produce any error/warning log in anywhere.

The file content is quite simple. The examples below worth more than the explanation:

#Add a route to a network:
10.1.0.0/16 via 10.2.0.1

#Add a route to a host:
10.1.2.3 via 10.0.0.5

After done, is possible to test your new routes using the ifup-routes ifname command. It adds the configured routes to the active routes table.

See you ;-)

Published At (Updated At)