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.
Example:
# /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 172.16.0.0/12 via 192.168.0.1
#up ip route add 172.30.0.0/16 via 192.168.0.1 dev eno2
#up ip route add 172.29.0.0/16 via 192.168.0.1 dev eno2
However, if your interfaces are being managed by Network Manager, then you can do the following:
Example:
# /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 172.16.0.0/12 via 192.168.0.1
#up ip route add 172.30.0.0/16 via 192.168.0.1 dev eno2
#up ip route add 172.29.0.0/16 via 192.168.0.1 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 "172.16.0.0/12 192.168.0.1" ipv4.route-metric 25 Connection successfully reapplied to device 'eno2'.
$ sudo nmcli device modify eno1 ipv4.routes "172.16.0.0/12 192.168.0.1" ipv4.route-metric 25
Connection successfully reapplied to device 'eno1'.
$ sudo systemctl restart NetworkManager.service
Comments
Post a Comment