16.5. Configuring Static Routes in ifcfg files
/etc/sysconfig/network-scripts/directory. The file name should be of the format
route-ifname. There are two types of commands to use in the configuration files; ip commands as explained in Section 16.5.1, “Static Routes Using the IP Command Arguments Format” and the Network/Netmask format as explained in Section 16.5.2, “Network/Netmask Directives Format”.
16.5.1. Static Routes Using the IP Command Arguments Format
/etc/sysconfig/network-scripts/route-eth0, define a route to a default gateway on the first line. This is only required if the gateway is not set via
DHCPand is not set globally in the
default via 192.168.1.1
IPaddress of the default gateway. The interface is the interface that is connected to, or can reach, the default gateway. The
devoption can be omitted, it is optional. Note that this setting takes precedence over a setting in the
10.10.10.0/24 via 192.168.1.1 [
IPaddress leading to the remote network. It is preferably the next hop address but the address of the exit interface will work. The “next hop” means the remote end of a link, for example a gateway or router. The
devoption can be used to specify the exit interface interface but it is not required. Add as many static routes as required.
route-interfacefile using the ip command arguments format. The default gateway is
192.168.0.1, interface eth0 and a leased line or WAN connection is available at
192.168.0.10. The two static routes are for reaching the
10.10.10.0/24network and the
default via 192.168.0.1 dev eth0 10.10.10.0/24 via 192.168.0.10 dev eth0 172.16.1.10/32 via 192.168.0.10 dev eth0
192.168.0.0/24network will be directed out the interface attached to that network. Packets going to the
172.16.1.10/32host will be directed to
192.168.0.10. Packets to unknown, remote, networks will use the default gateway therefore static routes should only be configured for remote networks or hosts if the default route is not suitable. Remote in this context means any networks or hosts that are not directly attached to the system.
IPcommand arguments format can cause one of two errors during start-up, or when bringing up an interface from the down state using the
ifupcommand: "RTNETLINK answers: File exists" or 'Error: either "to" is a duplicate, or "X.X.X.X" is a garbage.', where X.X.X.X is the gateway, or a different
IPaddress. These errors can also occur if you have another route to another network using the default gateway. Both of these errors are safe to ignore.