© Copyright The Linux Foundation 2023: DO NOT COPY OR DISTRIBUTE
28.10. LABS 1
Exercise 28.4: Adding a Static Route using nmcli
We are going to add a static IPv4 route address to your system and make it persistent. We will do this without editing files
under /dev directly, using nmcli.
1. Begin by examining your current routing tables, using ip route:
$ ip route
default via 172.16.2.2 dev ens33 proto static metric 100
169.254.0.0/16 dev ens33 scope link metric 1000
172.16.2.0/24 dev ens33 proto kernel scope link src 172.16.2.135 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
2. Add a new route using nmcli:
$ sudo nmcli conn mod "Auto Ethernet" +ipv4.routes "192.168.100.0/24 172.16.2.1"
3. Note it has not yet taken effect:
$ ip route
default via 172.16.2.2 dev ens33 proto static metric 100
169.254.0.0/16 dev ens33 scope link metric 1000
172.16.2.0/24 dev ens33 proto kernel scope link src 172.16.2.135 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
4. Reload the interface to have it take effect and show it has:
$ sudo nmcli conn up "Auto Ethernet"
Connection successfully activated (D-Bus active path:
,→ /org/freedesktop/NetworkManager/ActiveConnection/25)
$ ip route
default via 172.16.2.2 dev ens33 proto static metric 100
169.254.0.0/16 dev ens33 scope link metric 1000
172.16.2.0/24 dev ens33 proto kernel scope link src 172.16.2.135 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
192.168.100.0/24 via 172.16.2.1 dev ens33
5. Reboot and verify the route has taken effect (i.e., it is persistent: If so remove it:
$ ip route
default via 172.16.2.2 dev ens33 proto static metric 100
169.254.0.0/16 dev ens33 scope link metric 1000
172.16.2.0/24 dev ens33 proto kernel scope link src 172.16.2.135 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
192.168.100.0/24 via 172.16.2.1 dev ens33
$ sudo nmcli conn mod "Auto Ethernet" -ipv4.routes "192.168.100.0/24 172.16.2.1"
$ sudo nmcli conn up "Auto Ethernet"
V 2023-06-30 © Copyright The Linux Foundation 2023 All rights reserved.
© Copyright The Linux Foundation 2023: DO NOT COPY OR DISTRIBUTE
2 CHAPTER 28. NETWORK DEVICES AND CONFIGURATION
Connection successfully activated (D-Bus active path:
,→ /org/freedesktop/NetworkManager/ActiveConnection/3)
$ ip route
default via 172.16.2.2 dev ens33 proto static metric 100
169.254.0.0/16 dev ens33 scope link metric 1000
172.16.2.0/24 dev ens33 proto kernel scope link src 172.16.2.135 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
6. Note you can set a route with ip from the command line but it won’t survive a reboot as in:
$ sudo ip route add 192.168.100.0/24 via 172.16.2.1
...
You can verify that a route established this way is not persistent.
V 2023-06-30 © Copyright The Linux Foundation 2023 All rights reserved.