How to add a static route permanently on Linux

A static route is defined by statically configuring a next-hop router IP address for a specific destination network. You can add a static route by using "route add" command. However, a static route so added is not persistent across reboots. If you would like to add a static route permanently on Linux, do the following.

In this example, I assume that you wish to define a static route for network 10.10.0.0/16 via 10.10.5.5 on eth0.

To add a static route permanently on CentOS, Fedora or RHEL:

$ sudo echo "10.10.0.0/16 via 10.10.5.5" >> /etc/sysconfig/network-scripts/route-eth0

To add a static route permanently on Ubuntu or Debian:

$ sudo echo "up route add -net 10.10.0.0/16 gw 10.10.5.5 dev eth0" >> /etc/network/interfaces

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

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

Current day month ye@r *