Red Hat Enterprise Linux Static Routing Configuration For v 4.x/5.x/6.x/7.x

I have two network interfaces connected to two different routers as follows:

[a] eth0 LAN network – gateway IP –

[b] eth1 ISP assigned network – gateway IP –

I can only ping to public server but not to another servers inside my LAN? I am not able to route traffic via How do I configure static routing under Red Hat Enterprise Linux 5.x/6.x/7.x or CentOS Linux 5.2/6.x/7.x?

Under Red Hat Enterprise Linux or CentOS Linux you need to define static routing using the route command or ip command. The configuration is stored under /etc/sysconfig/network-scripts/route-eth0 for eth0 interface.

Update route using route command

Type the following command:
# route add -net netmask gw eth0
# route -n

OR use the ip command to update/set new routing for you:
# ip route add via
# ip r

# ip route add via dev eth0
# ip r

RHEL 7/CentOS 7.x can use the following syntax to set static routing:
# nmcli connection modify eth0 +ipv4.routes " via"

Create static routing file for CentOS/RHEL version 4.x/5.x/6.x and older only

The drawback of above route command is that, when RHEL/CentOS server reboots it will forget static routes. So store them in a configuration file for eth0 interface:
# echo ' via' >> /etc/sysconfig/network-scripts/route-eth0
Restart networking:
# service network restart
Verify new changes:
# route -n
# ip r
# ip a
# ping
# ping
# ping
# traceroute
# traceroute

How to add a new static route on CentOS/RHEL version 7.x and above

To see current ip settings run:
# ip a
# ip r

Create a file named /etc/sysconfig/network-scripts/route-enp6s0 to route traffic for sub/net via for enp6s0 interface:
# echo " via dev enp6s0" >> /etc/sysconfig/network-scripts/route-enp6s0
Finally restart the networking:
# systemctl restart network
# ip r
# ping
# ping
# ping

Further readings:
  • man pages ip, route command

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

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

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts