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 or credit card

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean