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.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

Leave a comment

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