Static Route with Rocky Linux and NetworkManager

Mindwatering Incorporated

Author: Tripp W Black

Created: 01/31 at 06:48 PM

 

Category:
Linux
Configuration

Task: Temporary Static Route Lasting Until Reboot
The example below creates a temporary static route to the 10.0.26.0/24 network via the gateway/host 10.0.25.2
$ sudo /sbin/ip route add 10.0.26.0/24 via 10.0.25.2


Task: Permanent Static Route
The example below creates a permanent static route to the 10.0.26.0/24 network via the gateway/host 10.0.25.2
a. Get the name of the ethernet adapter/NIC using either of the two commands below:
$ sudo ip ro
(example output with a host at IP 192.168.25.177)
192.168.25.0/24 dev ens192 proto kernel scope link src 192.168.25.177 metric 100

or

$ sudo nmcli c s
(example output)
ens192 ab1c2789-a2b3-3456-987a-789ef9012a34 ethernet ens192
lo a123451a-2620-1bc1-6789-0b1cde234567f loopback lo

b. Create the permanent route:
In this example, the NIC is ens192, use the command below to add the new static route
$ sudo nmcli con mod ens192 +ipv4.routes "10.0.26.0/24 10.0.25.2"

c. Restart the network on the NIC using either of the methods below:
$ sudo nmcli con down ens192
$ sudo nmcli con up ens192

or

$ sudo systemctl restart NetworkManager


previous page