Persistent Static Routes 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.

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# Generated by debian-installer.

# The loopback interface

auto lo
iface lo inet loopback
auto eno2
up ip route add via
#up ip route add via dev eno2
#up ip route add via dev eno2

However, if your interfaces are being managed by Network Manager, then you can do the following:

nmcli device modify ${device_name} \
    ipv4.routes "${destination_network} ${gateway}" \
    ipv4.route-metric 25

For example:
$ sudo nmcli device modify eno2 ipv4.routes "" ipv4.route-metric 25                                                                         Connection successfully reapplied to device 'eno2'.
$ sudo nmcli device modify eno1 ipv4.routes "" ipv4.route-metric 25
Connection successfully reapplied to device 'eno1'.
$ sudo systemctl restart NetworkManager.service


Popular posts from this blog

Check MySQL query history from command line

Installing chocolatey on Windows