Configure Static Routes In Debian or Red Hat Enterprise Linux

Static routes improve the overall performance of your network (especially bandwidth saving). They are also useful in stub networks (i.e. there is only one link to the network). For example, each LAN (located at different offices) is connected to HQ IDC (Internet data center) using single T1/LL/Wan links.
How to configure static routes In a Debian or Red Hat Enterprise Linux
For example under Red Hat/Fedora Linux you can add a static route for eth0 network interface by editing /etc/sysconfig/network-scripts/route-eth0 file. Under Debian Linux add static route by editing /etc/network/interface file.

Display Current Routing Table Using ip command

By using the ip command, you can set up and view static route. For example, to display the current routing table you can type the command:
# ip route show
Sample output: dev eth1 proto kernel  scope link  src dev eth0  proto kernel  scope link  src
default via dev eth0

You can add static route using following command:
ip route add {NETWORK} via {IP} dev {DEVICE}
For example network available via
# ip route add via dev eth1
Alternatively, you can use old good route command too:
# route add -net netmask gw dev eth1

Linux Persistence Routes

The drawback of ‘ip’ or ‘route’ command is that when Linux system reboots it will forget static routes. So store them in a configuration file. Static routing describes a system that does not implement adaptive routing. In these systems routes through a data network are described by fixed paths (statically). These routes are usually entered into the router by the system administrator

Red Hat (RHEL) / CentOS / Fedora Linux Persistence Static Routing

You need to open /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface:
# cat /etc/sysconfig/network-scripts/route-eth0
Sample Output:



A note about CentOS 7.x/RHEL 7.x and permanent static route

On a modern version of CentOS 7 or RHEL 7, you need to create a file named /etc/sysconfig/network-scripts/route-eth0 and update as follows:
# vi /etc/sysconfig/network-scripts/route-eth0
Add a permanent static route: via dev eth0
Save and close the file. You must restart networking service:
# systemctl restart network
# service restart network

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

How do I define static routing for network via router?

Open /etc/sysconfig/network-scripts/route-eth0:
# vi /etc/sysconfig/network-scripts/route-eth0
Append following line: via
Save and close the file. Restart networking:
# service network restart
Verify new routing table:
# route -n

Debian / Ubuntu Linux Persistence Static Routing

Open configuration file /etc/network/interfaces to configure static routes in Debian or Ubuntu Linux:
# cat /etc/network/interfaces
Sample outputs:

auto eth0
iface eth0 inet static
up route add -net netmask gw
down route del -net netmask gw
Debian / Ubuntu Linux static routing for two interfaces:

Here is an updated config file named /etc/network/interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
	### static routing for eth0 that connects to the VLAN ###
        post-up route add -net netmask gw
        pre-down route del -net netmask gw

auto eth1
iface eth1 inet static
        ## default gateway for eth1 and the server ##
        # dns-* options are implemented by the resolvconf package, if installed


Please note that the route command has been deprecated. Please use the ip command or see the following tutorials:

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

🐧 41 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
41 comments… add one
  • Rohit Basu Feb 17, 2007 @ 7:52

    The explanation on static route is good.
    but i found that there is also a file under /etc/sysconfig/network-scripts/static-route.
    If this file is present then what is its use.
    By default there is no file named route-eth0 under /etc/sysconfig/network-scripts/ .

    If i have to add static route in /etc/sysconfig/network-scripts/static-route file then how to do that.

    with regards

  • Darrell May 23, 2007 @ 4:31


    I’ve been trying to figure our how to add a static multicast route.

    I know how to do it manually via the route command.

    route add -net netmask dev eth0
    which give you the following route.

    Destination Gateway Genmask Flags Metric Ref Use Iface * 0 0 0 eth 0

    But i would like to add the route to route-eth0 so i don’t need to apply it manually everytime the server reboots.

    I’ve seen an example format for the file as via

    But i don’t know what the equivalent is for the following route
    route add -net netmask dev eth0

    What do i put after ‘via’ for the above multicast route.

    eg. via ???

  • Rockdalinux May 23, 2007 @ 8:01

    Open /etc/rc.local:
    vi /etc/rc.local

    Append command:
    route add -net netmask dev eth0

    Reboot system:
    Verify route
    route -n

    • Aco Aug 26, 2013 @ 19:53

      I find this method preferable because the syntax doesn’t chance. Same route command.

  • Rockdalinux May 23, 2007 @ 8:19

    And yes you can use: via YOUR-ROUTER-IP-ADDRESS

    For example my subnet routed via, so I have following line in my route-eth0 via

  • Irrelevant Jul 26, 2007 @ 12:13


    …shouldn’t that be



  • 🐧 nixCraft Jul 26, 2007 @ 13:24

    thanks for the heads up!

  • Dude! Sep 20, 2007 @ 14:47

    Thanks for the info – why can’t they include info about the ./network-scripts/route-eth0 file in the man file for route? :-S

  • venkateshwarlu Jan 30, 2008 @ 11:14

    hi this is venkateshwarlu. iam working in sysadmin in media. heare is using dell linux server. i have give the public ip and private ip.
    but not corctly understanding in
    ” static routing ”



  • Rohit Basu Feb 7, 2008 @ 10:51

    Static routing is some thing which are not ging to change. If there is one inbound port one outbound port every thing is static one.

    It says you are defining a rule for a network to go outside world.
    So it will never be broadcasted to search a path.
    It will be fast and optimum bandwidth utilisation.

    Anywat you if donot know how to write rules, can make a linux box as transparent routing.

  • bselectron Feb 24, 2008 @ 7:41

    Actually its: via YOUR-LOCALHOST-IP-ADDRESS

  • Proglot May 28, 2008 @ 8:44

    Actually script recognize 2 formats of route- files. The older one is just continued command line pararameters for ‘ip route add’ command and new one use


    The simplest way is to figure out what ‘ip’ command will do a trick and put it without ‘ip route add’ into /etc/sysconfig/network-scripts/route-eth0
    i.e. dev eth1
    to multicast dev eth1 via

  • Proglot May 28, 2008 @ 9:08

    by the way to see all you routes use
    ip route list table all
    for more information issue
    ip route help
    for example if you have a 2 internet lines and want to do load balance route then do not set default gateway in configuration, but add in one of the route files (let’s say /etc/sysconfig/network-scripts/route-ppp1) something like:
    default dev ppp0 nexthop ppp1

  • Stuart Gathman Sep 3, 2008 @ 18:21

    If i have to add static route in /etc/sysconfig/network-scripts/static-route file then how to do that.


    eth0 host
    eth0 net netmask gw

    The first line provide a host route to an interface for proxy arp.
    The second line provides a VPN gateway.

  • sql Sep 17, 2008 @ 10:17

    thank you!

  • Alan Jan 5, 2009 @ 5:51

    Hi everyone,

    Can you help me with this, how to configure Red Hat Linux to work with a load balancer router? I’m not familiar with the Red Hat Linux. Thanks.

  • Catalinux Sep 8, 2009 @ 21:19

    Thank’s, is very pretty info.

  • Soundar Dec 28, 2009 @ 7:01

    thanks, bydefualt route-eth0 file will not be there, need to be created

  • Stan Jan 22, 2010 @ 18:00

    I have a pptp connection and have added the following in /etc/sysconfig/network-scripts/route-ppp0


    when the tunnel is established subnet is reachable but not as it tries to go out the def gw become reachable if i manually add by (but looses route if pptp drops) :

    route add gw

    I must be messing something up here….anyone can shed light pls ? 🙂

    • 🐧 nixCraft Jan 22, 2010 @ 18:20

      @Stan: create /etc/ppp/ip-up.d/route-traffic and add your route command. For example, I router via ppp0 so my file is as follows:

      route add -net dev ppp0
      Save and close the file. And set permissions:
      chmod +x /etc/ppp/ip-up.d/route-traffic


  • john Mar 29, 2010 @ 14:04

    hey guys ,,
    I have a problem, I’m trying to configure a Debian board (Olimex) to do the routing but all my trys failed even though it seems my network is connected well

    I can ping from my pc the both interfaces which the board are connected to but the problem I can’t ping any IP outside ?!?!?!

    anyone can help and let me know what missing ?!!!!!

  • Joel Aug 31, 2010 @ 14:56

    How command can I use to list the multicast coming out of my redhat server?

  • wiqar.hussain Nov 22, 2010 @ 0:53

    i like the redhat and i trying to learn the redhat window so pleas help me in this ok thanks

  • Zarg Dec 20, 2010 @ 17:44

    I would like to know how I can add permanently a dyndns host in my routing table(I have two network interfaces…). I have some hosts with fixed ip addresses in my /etc/sysconfig/network-scripts/route-eth0 that I have added with via
    but if I can not ad in this file via

    Thank you

    • Stephen Feb 15, 2011 @ 8:25

      Can’t be done. Otherwise your host would have to resolve the dyndns name each time it routed a packet !!

      Find out what range your ISP is allocating the dyndns host within and add a route for that.

      • Zarg Mar 24, 2011 @ 21:14

        I done it in a way. I have a crontab every minute do something like
        ping -c1 | grep from | cut -d’ ‘ -f 4 | cut -d’:’ -f1′ > /tmp/new_ip
        diff /tmp/old_ip /tmp/new_IP && route del default gw eth0 route add -net `echo /tmp/new_ip` -mask &&cat /tmp/old_ip > /tmp/old_ip && route add default gw eth0 route add -net `echo /tmp/new_ip` -mask

  • rockysyas Mar 24, 2011 @ 3:40

    If you read /etc/init.d/network (rhel),you can find this:
    # Add non interface-specific static-routes.
    if [ -f /etc/sysconfig/static-routes ]; then
    grep “^any” /etc/sysconfig/static-routes | while read ignore args ; do
    /sbin/route add -$args
    so, /etc/sysconfig/static-routes is your best chose!
    vi /etc/sysconfig/static-routes
    any -net netmask gw
    any -host gw

  • Anthony Mar 24, 2011 @ 23:15

    does via IP dev eth0 in the route-eth0 script route all mutlicast addresses? For example I need to multicast on 224 and 235 addresses …if would I enable it in static routing in Red Hat Linux?

  • Barry Jul 22, 2011 @ 3:12

    My server ABC has got two nics connected to different subnets. How do I add static route to send traffic to particular interface?

    For example, I have 5 another servers with ip-address 10.216.98.XX and all have their own gateway because they all are at different locations. Now I want to ass route which sends/receive all traffic from these servers to eth0 on my ABC server.

    Thanks in advance.

  • Barry Jul 22, 2011 @ 7:14
  • Yoni Nov 27, 2011 @ 9:38

    Thx for the tutorial

  • James Jul 23, 2012 @ 13:14

    I have a problem with my static routes.

    I have a route to a network through both of my NICs which are configured for seperate /24 networks.

    My eth0 has a default gateway. So I need to add the static route for Eth1. via

    I restart network services and see the route in netstat -nr.

    However, when I unplug the Eth1 cable, the route is STILL IN THE TABLE. Which means the packets will not go out Eth1 even when there is a route. When I issue the ifdown eth1 command, finally the route is removed from the routing table and pings can go out eth0.

    How can I get this to happen automagically?


  • R. Sriram Sep 5, 2012 @ 8:12


    I have 3 servers in cluster and want to update the ntp server. I am running Red Hat on all the servers.
    Do I need to stop the cluster, update the ntp server and start the ntpd service in each server and then bring the cluster up or I can update the ntp server with out disturbing the cluster? Would really appreciate some inputs.


  • bahram Oct 10, 2012 @ 8:52

    hi I went help to config centOS 0.4 to Linux routing for network WAN

  • Ap.Muthu Jun 28, 2013 @ 10:40

    It would be useful to stick with the listed subnets for the example.
    All possibilities are in vain:

    # ip route show dev eth0 proto kernel scope link src dev eth1 proto kernel scope link src dev eth0 scope link
    default via dev eth1

    # ip route add via dev eth1
    RTNETLINK answers: File exists

    # ip route add via dev eth0
    RTNETLINK answers: Network is unreachable

    # ip route add via dev eth0
    RTNETLINK answers: File exists

    # ip route add via dev eth1
    RTNETLINK answers: Network is unreachable

    # route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface * U 0 0 0 eth0 * U 0 0 0 eth1 * U 0 0 0 eth0
    default UG 0 0 0 eth1

  • sinergiasincontrol Sep 30, 2013 @ 16:03

    on debian, the config can be also on


    … and so on.

  • TKJ Pekalongan Mar 24, 2016 @ 13:04

    Thanks for this tutorials, it’s help me a lot. I’m configuring 2 network using Debian Linux as router in Network1 dan using Mikrotik in Network2.

    TKJ Pekalongan
    TKJ SMK Gondang

  • ricky gunawan Oct 20, 2016 @ 3:02

    after reboot
    this routing automatic remove
    why ?

  • sanjib Mar 30, 2017 @ 7:08

    I have entered ips, netmask, gw in /etc/sysconfig/network-scripts/enp130s0f2 then save it and restart the service. But when i route -n, it is not showing the changes.
    Could u please help me ?

  • Jan Sep 27, 2017 @ 19:24

    I am using a VPN. By default all of my internet traffic is routed through that. However, for work I use an SSH server that probably has some IP based filtering and doesn’t allow me to connect via the VPN. Therefore I would like to route the IP adres of the SSH server outside the VPN.

    I’ve added the following route where is the IP of the SSH server and wlp1s0 is my wifi interface.
    ip route add via dev wlp1s0

    However this doesn’t seem to work. Any ideas? I’m unable to do a traceroute on the SSH server’s IP however ping seems to work.

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