FAQ: static routes after restart/reboot in Fedora/RedHat/CentOS

Welcome to Linux Screw! If you're new here, you may want to subscribe our RSS feed.

route 66Static routing is the term used to refer to the manual method used to set up routing. An administrator enters routes into the router using configuration commands. This method has the advantage of being predictable, and simple to set up. It is easy to manage in small networks but does not scale well.

Question: How can I save static routes I set up in my Fedora/RedHat/CentOS Linux after I reboot server?

Answer: In Fedora Linux (or RedHat, CentOS) you can set up static routes for certain network interface (for example eth1) by editing file /etc/sysconfig/network-scripts/route-eth1.

For example, you have to save static route added by the following command:

route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.100.1 dev eth1

To do it, just add the following line to /etc/sysconfig/network-scripts/route-eth1:

ADDRESS0=192.168.0.0
NETMASK0=255.255.255.0
GATE
WAY0=192.168.100.1

 
 
» You might also be interested in the following articles:
15+ “must have” Cisco Cheat Sheets
FAQ: How to install and configure MySQL cluster?
Fully automated Fedora Linux installation manual (create custom installation cd)



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!

4 Responses to “FAQ: static routes after restart/reboot in Fedora/RedHat/CentOS”


  1. 1 confiq

    hey… nice tip… keep those comming :)

  2. 2 artiomix

    Thank you, confiq. Keep commenting! ;)

  3. 3 daveg

    The alternate way of doing it is to put the routes in /etc/sysconfig/static-routes. So the above route would like this like in the static-routes file:

    any net 192.168.0.0 netmask 255.255.255.0 gw 192.168.100.1

    Where any is specified above you can also set specific interfaces (such as eth1).

  4. 4 artiomix

    Thanks for the tip, daveg!

    Here is the part /etc/init.d/interfaces code:


    # 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
    done
    fi

    Looks like any must be at the beginning of each line in /etc/sysconfig/static-routes. At the same time Fedora is able to determine interface name packet should be routed through (like eth1) by destination IP. :)

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word




Friendly Sites:Who is behind Linux Screw?
Aspiring Sysadmin | GeekyBits³ | Bash Cures Cancer | TOTMS
Linux Operating System | Small Linux Deployments | My SysAd Blog
The Danesh Project | ZEPY | Linux config Wiki | Planet Sysadmin
The Sys Admin | {buhay sysad} | a non-geek's linux notes
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem Nosulchik (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››