How to add permanent static routes in Ubuntu Linux

In this tutorial we are going to learn how to add permanent static route in Ubuntu Linux.

For this tutorial I am using Ubuntu Server 16.04, But you can use the following method to add Persistent route in any previous Ubuntu version including Ubuntu Desktop.

What is a Persistent route ?

In Ubuntu, permanent static routes also called as Persistent routes are the static route entries that will not be deleted when the network restart or when the system restart.

Typically in a Linux System, route add and ip route add commands are used to add static routes to the routing table. But those static route entries get deleted from the routing table when either network or system restart.

So how we can make static routes permanent?

Making Static Routes Persistent in Ubuntu Linux

In Ubuntu Linux, in order to make Static Routes Persistent, we need to add route entries to the network interface file (/etc/network/interfaces) using up lines.


Following is the sample Ubuntu network interface configuration file with permanent static route entries.

auto enp0s3
iface enp0s3 inet static
up route add -net netmask gw
up route add -net netmask dev enp2s0

As per the above example, we have added two permanent static route entries using the “up” argument.

the "up" lines are executed when the interface is brought up. So when network restart, those route entries will be added to the routing table automatically.

You need to restart Ubuntu networking, if you add a new route entry to the /etc/network/interfaces file.

service networking restart

You can view the routing table using the ip route show command.

ip route show

Examples - Persistent routes in Ubuntu Linux

up route add -net netmask gw

Gateway for the network is

up route add -net netmask dev eth1

Network route through the network interface eth1.

up route add -host gw

As per the above example, host will route through the gateway

So that is how we add permanent routes in Ubuntu Linux. This method uses to add Persistent route in all Debian Based Linux Distributions.