Score:0

Make ip route add and ip rule add commands persistent on startup

us flag

I need to make the below two lines persistent so that they are available on server reboot now that I have proved that the route and the rules works as expected on AlmaLinux 8 (AlmaLinux is basically the same as CentOS)

ip route add default via x.x.x.x dev eno5 src x.x.x.x table 1
ip rule add from x.x.x.x table 1

Everything I've seen shows I should be able to create a file in /etc/sysconfig/network-scripts/route-eno5 and the default via x.x.x.x dev eno5 src x.x.x.x table 1 and /etc/sysconfig/network-scripts/route-eno5 and add the line from x.x.x.x table 1 but when I save this and reboot those rules are not applied.

Is this not supported on AlmaLinux 8 and done in a different or am I doing something wrong?

Score:3
pt flag

RHEL 8 and later -- and all derived distributions, like CentOS and AlmaLinux -- no longer use the legacy /etc/sysconfig/network-scripts directory. The correct solution is to modify the NetworkManager configuration.

NetworkManager can add both static routes and policy routing rules. There is some relevant documentation here.

On a default CentOS 8(stream) install, my NetworkManager configuration looks like this:

[root@localhost ~]# nmcli c show
NAME         UUID                                  TYPE      DEVICE
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0

If I want to add a policy route to eth0, I would do something like this:

nmcli c mod 'System eth0' \
  ipv4.addresses 10.0.0.10/24 \
  ipv4.routes '0.0.0.0/0 10.0.0.1 table=1' \
  ipv4.route-rules 'priority 100 from 10.0.0.0/24 table 1'

In this example I'm adding a static ip addresses that is different from the one that gets assigned dynamically using DHCP; this may not be necessary in your situation depending on what your local configuration looks like.

After restarting the interface:

nmcli c down 'System eth0'; nmcli c up 'System eth0'

I now have:

[root@localhost ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:c1:f0:62 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.10/24 brd 10.0.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet 192.168.122.164/24 brd 192.168.122.255 scope global dynamic noprefixroute eth0
       valid_lft 3505sec preferred_lft 3505sec
    inet6 fe80::5054:ff:fec1:f062/64 scope link
       valid_lft forever preferred_lft forever

[root@localhost ~]# ip rule show
0:      from all lookup local
100:    from 10.0.0.0/24 lookup 1
32766:  from all lookup main
32767:  from all lookup default

[root@localhost ~]# ip route show table 1
default via 10.0.0.1 dev eth0 proto static metric 100
10.0.0.1 dev eth0 proto static scope link metric 100
Score:0
nl flag

You can use "NetworkManager Text User Interface" (nmtui tool)

# yum install NetworkManager-tui

# nmtui

Go to Edit a connection, select connection... Add routes in Routing section.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.