Thursday, November 19, 2015

CentOS - RHEL static routes

If you ever need to remember how to assign static routes on a RHEL/CentOS system here are some notes:

Static route configuration is stored in a /etc/sysconfig/network-scripts/route-interface file. For example, static routes for the eth0 interface would be stored in the /etc/sysconfig/network-scripts/route-eth0 file. Theroute-interface file has two formats: IP command arguments and network/netmask directives.
IP Command Arguments Format
Define a default gateway on the first line. This is only required if the default gateway is not set via DHCP:
default X.X.X.X dev interface
X.X.X.X is the IP address of the default gateway. The interface is the interface that is connected to, or can reach, the default gateway.
Define a static route. Each line is parsed as an individual route:
X.X.X.X/X via a.a.a.a dev interface
X.X.X.X/X is the network number and netmask for the static route. a.a.a.a and interface are the IP address and interface for the default gateway respectively. The X.X.X.X address does not have to be the default gateway IP address. In most cases, X.X.X.X will be an IP address in a different subnet, and interface will be the interface that is connected to, or can reach, that subnet. Add as many static routes as required.

The following is a sample route-eth0 file using the IP command arguments format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for the 10.10.10.0/24 and 172.16.1.0/24 networks:
default 192.168.0.1 dev eth0
10.10.10.0/24 via 192.168.0.254 dev eth0
172.16.1.0/24 via 192.168.0.254 dev eth0

No comments:

Post a Comment