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 google.com
# traceroute google.com
# 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 google.com

Further readings:
  • man pages ip, route command

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • kangsirodj Nov 8, 2008 @ 6:33

    please tell me, what for this command ? I am using centos 4 :
    echo 1 > /proc/sys/net/ipv4/ip_forwarding

    is it any relations with static routing ?

    thank you

  • 🐧 nixCraft Nov 8, 2008 @ 6:37

    It will turn on routing on Linux i.e. it will set Linux a router device.

    • Laith Jan 4, 2015 @ 18:49

      Is it related to the static route? I mean do I have to execute this command incase of static route? Or use it on another scenarios?

  • vinay Jan 24, 2009 @ 14:59

    How to cinfigure ADSL modem connection on linux

  • Srinivas D Apr 7, 2009 @ 10:31

    Thanks a ton, the static route commands provided are very helpful. More over they are friendly to update my knowledge.

  • Arshad Jan 8, 2010 @ 6:00

    please inform me about the ststic routing between lans

  • Sagar Shivnani Sep 26, 2011 @ 12:35

    Very helpful :)

  • StoneCut Apr 19, 2012 @ 7:23

    Hi, maybe you can help with my routing issue. We have a SLES Squid server with following IP configuration:
    eth0: / 24
    -> eth0 also has a second IP address / 24
    eth1: / 24

    Squid is listening on both 10.0.20.x addresses. We cannot change these, unfortunately.

    So far we have been using as default gateway but we’d like to switch to instead. However we tried setting as default gateway and then added a route “ ->”. This way we want to direct ALL traffic to the new gateway.

    Problem: Squid works fine for all clients EXCEPT those that are in the 10.0.18.x subnet – no webpage loads.

    Can anyone help ?

  • G-Man Jun 6, 2012 @ 4:09


    I have two Service that support the identical informix Database.
    the Applcation Authinecates ssh on eth0 but replicates on eth1.
    the ip addresses are set to the same subnet on serv1 and server2 Example
    Server 1
    eth0 IP
    eth1 IP

    Server 2
    eth0 IP
    eth1 ip

    the problem is every thing run in and out of eth0. the database replcation fails
    how can I setup a static route from eth0 to eth0 and eth1 to eth1 Example:
    Svr1 th0/ to route to Svr2 eth0/
    Srv1 eth1/ to Srv2 eth1/
    via the gateway Srv1/ and Srv2/
    can this be done?

  • Bhageerathan Jul 20, 2012 @ 13:45

    I have configured ipvsadm on segment

    LB IP
    real servers are and
    port 80

    I can able to browse my website through other segments. but am not able to browse using LB in inside this same network i can browse if i use real server IP directly inside this segment….
    Any solution please…..

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum