≡ Menu

Configure Static Routes In Debian or Red Hat Enterprise Linux

Static routes improves 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.

For example under Red Hat/Fedora Linux you can add static router 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.

Task: Display Current Routing Table Using ip command

By using the ip command, you can setup and view static route. For example, to display current routing table you can type 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:
# route add -net netmask gw dev eth1

Linux Persistence Routes

The drawback of 'ip' or 'route' command is that, when Linux reboots it will forget static routes. So store them in 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:


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
# cat /etc/network/interfaces

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:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
	### static routing ###
        post-up route add -net netmask gw
        pre-down route del -net netmask gw
auto eth1
iface eth1 inet static
        # dns-* options are implemented by the resolvconf package, if installed
        dns-search nixcraft.in

Updated for accuracy.

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 36 comments… add one }

  • Rohit Basu February 17, 2007, 7:52 am

    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 am


    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 am

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

    Append command:
    route add -net netmask dev eth0

    Reboot system:
    Verify route
    route -n

    • Aco August 26, 2013, 7:53 pm

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

  • Rockdalinux May 23, 2007, 8:19 am

    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 July 26, 2007, 12:13 pm


    …shouldn’t that be



  • nixCraft July 26, 2007, 1:24 pm

    thanks for the heads up!

  • Dude! September 20, 2007, 2:47 pm

    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 January 30, 2008, 11:14 am

    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 February 7, 2008, 10:51 am

    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 February 24, 2008, 7:41 am

    Actually its: via YOUR-LOCALHOST-IP-ADDRESS

  • Proglot May 28, 2008, 8:44 am

    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 am

    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 September 3, 2008, 6:21 pm

    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 September 17, 2008, 10:17 am

    thank you!

  • Alan January 5, 2009, 5:51 am

    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 September 8, 2009, 9:19 pm

    Thank’s, is very pretty info.

  • Soundar December 28, 2009, 7:01 am

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

  • Stan January 22, 2010, 6:00 pm

    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 January 22, 2010, 6:20 pm

      @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 March 29, 2010, 2:04 pm

    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 August 31, 2010, 2:56 pm

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

  • wiqar.hussain November 22, 2010, 12:53 am

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

  • Zarg December 20, 2010, 5:44 pm

    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
    myhost.dyndns.org/32 via

    Thank you

    • Stephen February 15, 2011, 8:25 am

      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 March 24, 2011, 9:14 pm

        I done it in a way. I have a crontab every minute do something like
        ping -c1 my_adress.dyndns.org | 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 March 24, 2011, 3:40 am

    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 March 24, 2011, 11:15 pm

    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 not..how would I enable it in static routing in Red Hat Linux?

  • Barry July 22, 2011, 3:12 am

    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 July 22, 2011, 7:14 am
  • Yoni November 27, 2011, 9:38 am

    Thx for the tutorial

  • James July 23, 2012, 1:14 pm

    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 September 5, 2012, 8:12 am


    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 October 10, 2012, 8:52 am

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

  • Ap.Muthu June 28, 2013, 10:40 am

    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 September 30, 2013, 4:03 pm

    on debian, the config can be also on


    … and so on.

Leave a Comment