/etc/sysconfig/network-scripts/ directory. The file name should be of the format route-ethX. There are two types of commands to use in the configuration files; ip commands as explained in Section 2.3.4, “ Static Routes Using the IP Command Arguments Format ” and the Network/Netmask format as explained in Section 2.3.4, “ Network/Netmask Directives 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 DHCP and is not set globally in the /etc/sysconfig/network file:
default via 192.168.1.1 dev interfaceIP address of the default gateway. The interface is the interface that is connected to, or can reach, the default gateway. The dev option can be omitted, it is optional. Note that this setting takes precedence over a setting in the /etc/sysconfig/network file.
10.10.10.0/24 via 192.168.1.1 dev interfaceIP address and interface for the gateway leading to the remote network. Add as many static routes as required.
route-eth0 file 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/24 network and the 172.16.1.10/32 host:
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/24 network will be directed out the interface attached to that network. Packets to unknown, remote, networks will use the default gateway. Below is an example of setting static routes to a different network, on a machine in the 192.168.0.0/24 network. The example machine has an eth0 interface in the 192.168.0.0/24 network, and an eth1 interface (with address 10.10.10.1) in the 10.10.10.0/24 network:
10.10.10.0/24 via 10.10.10.1 dev eth1
Duplicate default gateways
DHCP, the ip command arguments format can cause one of two errors during start-up, or when bringing up an interface from the down state using the ifup command: "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 IP address. 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.
route-interface files. The following is a template for the network/netmask format, with instructions following afterwards:
ADDRESS0=10.10.10.0 NETMASK0=255.255.255.0 GATEWAY0=192.168.1.1
ADDRESS0=10.10.10.0 is the network address of the remote network or host to be reached.
NETMASK0=255.255.255.0 is the netmask for the network address defined with ADDRESS0=10.10.10.0.
GATEWAY0=192.168.1.1 is the default gateway, or an IP address that can be used to reach ADDRESS0=10.10.10.0
route-eth0 file using the network/netmask directives format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for reaching the 10.10.10.0/24 and 172.16.1.0/24 networks. This example is not necessary as traffic trying to reach a remote network or host would use the default gateway anyway:
ADDRESS0=10.10.10.0 NETMASK0=255.255.255.0 GATEWAY0=192.168.0.1 ADDRESS1=172.16.1.0 NETMASK1=255.255.255.0 GATEWAY1=192.168.0.1
ADDRESS0, ADDRESS1, ADDRESS2, and so on.
192.168.0.0/24 network. The example machine has an eth0 interface in the 192.168.0.0/24 network, and an eth1 interface ( with address 10.10.10.1) in the 10.10.10.0/24 network:
ADDRESS0=10.10.10.0 NETMASK0=255.255.255.0 GATEWAY0=10.10.10.1
DHCP is used, it can assign these settings automatically.