How to add a static route permanently on Linux

Last updated on November 21, 2020 by Dan Nanni

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 or ip route add command. However, any static route so added is not persistent across reboots. If you would like to configure a permanent static route on Linux, do the following.

In this example, it is assumed that you want to configure a static route for network that is reachable via next hop on eth0.

Add a static route permanently on CentOS/RHEL/Fedora

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

Add a static route permanently on Ubuntu/Debian

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

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (BTC Wallet: 1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Xmodulo © 2020 ‒ About ‒ Powered by DigitalOcean