RHEL Interface Route – Interface Routing on CentOS / RHEL


Overview

In my environment I have several RHEL systems with multiple network interfaces. Each interface is connected to a separate network. To avoid asynchronous routing and ensure that traffic to each network is sent via the correct interface (instead of to the default gateway) I have defined an interface route. Here’s how it works.

In this example we will configure an interface route to send traffic to 192.168.200.0/24 out the eth1 interface.

These instructions are valid for RHEL, CentOS and Oracle Linux systems.

Adding the interface route

First, add a route statement to the /etc/sysconfig/network-scripts/route-eth1 file. If this file doesn’t exist you can safely create it.

The below statement will send traffic to the subnet 192.168.200.0/24 via the eth1 interface. A null gateway (0.0.0.0) is used because this traffic will stay local to the LAN eth1 is connected to.

#/etc/sysconfig/network-scripts/route-eth1
 
192.168.200.0/24 via 0.0.0.0 dev eth1

Activating the interface route

In order to apply the route statement added above the interface needs to be brought down and back up.

# Bring down eth1 using network scripts
[root@host network-scripts]# ifdown eth1
 
# Bring up eth1 using network scripts
[root@host network-scripts]# ifup eth1

Verifying the rhel interface route

Now that the new route configuration has been applied we can verify that the configuration is active.

First, check the routing table for the interface route. We want to make sure that a route statement for 192.168.200.0/24 via eth1 is present.

[root@host network-scripts]# netstat -nr | grep 192.168.200.0
# Check routing table for subnet that is interface routed.
# Added heading for readability
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
 
192.168.200.0   0.0.0.0         255.255.255.0   U         0 0          0 eth1

Here you can see that the network 192.168.200.0/24 (255.255.255.0 and /24 mean the same thing) is now routed via interface eth1 with no gateway specified.

Then, confirm that traffic is flowing correctly using tcpdump. You should see traffic from 192.168.200.0/24 only leaving via the eth1 interface.

# Listen on eth1 for traffic in subnet 192.168.200.0/24
 
[root@host ~]# tcpdump -n -i eth1 net 192.168.200.0/24

Using the above command you should only see outbound traffic to 192.168.200.0/24. You may need to generate some test traffic. Using the same tcpdump filter on other interfaces should show no outbound traffic to this subnet.

Join the Conversation