Setting Up Static Routes on RHEL 7 and RHEL 8

Static routes are crucial for directing network traffic along specific paths. Here’s a step-by-step guide on how to set them up in RHEL 7 and RHEL 8.

RHEL 7 Static Routes

1. Temporary route with ip command:
To add a static route to the 192.168.2.0/24 network via the 192.168.1.1 gateway:

ip route add 192.168.2.0/24 via 192.168.1.1

2. Permanent route using configuration files:
a. Navigate to the network-scripts directory:

cd /etc/sysconfig/network-scripts/

b. Create or edit route-<interface-name>. For eth0, it’d be route-eth0.
c. Add your static route:

ADDRESS0=192.168.2.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.1.1

d. Save and restart the network service:

systemctl restart network

RHEL 8 Static Routes

1. Temporary route with ip command:
It remains the same as RHEL 7:

ip route add 192.168.2.0/24 via 192.168.1.1

2. Using nmcli for permanent routes:
a. List active connections:

nmcli con show

b. Add your static route:

nmcli con modify <connection-name> +ipv4.routes "192.168.2.0/24 192.168.1.1"

c. Restart NetworkManager:

systemctl restart NetworkManager

3. Traditional network-scripts method:
a. Navigate to the network-scripts directory:

cd /etc/sysconfig/network-scripts/

b. For interface ens33, edit or create route-ens33.
c. Add your route:

192.168.2.0/24 via 192.168.1.1

d. Save and restart the network or toggle the interface.


Conclusion: While both RHEL 7 and RHEL 8 provide means to set static routes, it’s advisable to familiarize yourself with the nmcli tool for RHEL 8, as it’s the recommended approach for modern network management on Red Hat systems.


Leave a comment

Your email address will not be published. Required fields are marked *