20090921 static routes in rhel - plembo/onemoretech GitHub Wiki

title: Static routes in RHEL link: https://onemoretech.wordpress.com/2009/09/21/static-routes-in-rhel/ author: lembobro description: post_id: 243 created: 2009/09/21 17:40:56 created_gmt: 2009/09/21 17:40:56 comment_status: open post_name: static-routes-in-rhel status: publish post_type: post

Static routes in RHEL

"Where do I define any needed static routes for a Red Hat Enterprise Linux (RHEL) system?" I'm glad you asked. In

/etc/sysconfig/network-scripts/route-[interface]

for each network interface, of course, right where anyone who had the courage to take (and the skill to pass) either the RHCT (Red Hat Certified Technician) or RHCE (Red Hat Certified Engineer) test would expect to find them. There are two "styles" you can use for this, the "IP Command Arguments" or "Network/Netmask Directives" formats. My own preference is for Network/Netmask Directives format, because it more closely matches the format used in the interface configuration scripts themselves. For example, if you wanted to assign static outes for interface eth2 on your system:

# /etc/sysconfig/network-scripts/route-eth2
GATEWAY0=192.168.1.2
NETMASK0=255.0.0.0
ADDRESS0=10.0.0.0
	
GATEWAY1=172.16.0.2
NETMASK1=255.255.128.0
ADDRESS1=172.30.8.0
	
GATEWAY2=192.168.1.2
NETMASK2=255.255.252.0
ADDRESS2=192.168.53.0

Each default route has its own declaration of GATEWAY, NETMASK and ADDRESS. These are numbered from 0 up. The IP Command Arguments format would look like this:

# /etc/sysconfig/network-scripts/route-eth2
default 192.168.1.2 dev eth2
10.0.0.0/8 via 192.168.1.2 dev eth2
172.30.8.0/17 via 172.16.0.2 dev eth2
192.168.53.0/22 via 192.168.1.2 dev eth2

Interactive command to add a route would be:

ip route add 172.30.8.0/17 via 172.16.0.2 dev eth2

This is all documented in the Red Hat Enterprise Linux Deployment Guide, section 14.4. Always double check your routes by doing a

netstat -nr

at the console.

Copyright 2004-2019 Phil Lembo