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 10.10.0.0/16 that is reachable via next hop 10.10.5.5 on eth0.

Add a static route permanently on CentOS/RHEL/Fedora

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

Add a static route permanently on Ubuntu/Debian

$ sudo echo "up route add -net 10.10.0.0/16 gw 10.10.5.5 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