Add loopbackinterface

Hi,

I’m in the planning of migration from Centos7 to Rocky, and I have encountered a problem regarding to loopback interfaces.

We are using OSPF/quagga to anycast IPv4, but in Rocky my setup from Centos7 is not working, here is my ifcfg-file and the error message generated in messages:

[root@rocky /]# cat /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
BOOTPROTO=none
BROADCAST=192.168.10.10
IPADDR=192.168.10.10
NETMASK=255.255.255.255
NETWORK=192.168.10.10
ONBOOT=yes
[root@rocky /]#
[root@rocky /]# cat /var/log/messages | grep lo:0
Sep 6 15:38:34 rocky NetworkManager[936]: [1630935514.8332] ifcfg-rh: invalid DEVICE name ‘lo:0’: interface name contains an invalid character
Sep 6 15:45:40 rocky NetworkManager[949]: [1630935940.8859] ifcfg-rh: invalid DEVICE name ‘lo:0’: interface name contains an invalid character
Sep 6 15:47:14 rocky NetworkManager[940]: [1630936034.8836] ifcfg-rh: invalid DEVICE name ‘lo:0’: interface name contains an invalid character
Sep 6 15:56:36 rocky NetworkManager[943]: [1630936596.7909] ifcfg-rh: invalid DEVICE name ‘lo:0’: interface name contains an invalid character
[root@rocky /]#

Any ideas ?

Hi,

According to this RH link: How to assign an additional/alias IP addresses to a network card (NIC)? - Red Hat Customer Portal it’s apparently not ideal to do interface aliases anymore, I expect this is why this problem has occured. They recommend by adding something like this instead:

IPADDR1=127.0.0.1
PREFIX1=8
IPADDR2=192.168.10.10
PREFIX2=32

alternatively instead of PREFIX1/PREFIX2:

NETMASK1=255.0.0.0
NETMASK2=255.255.255.255

As an alternative, on my system for a test I did this:

[root@rocky ~]# ifconfig -a
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.72  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::5054:ff:fea2:c971  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:a2:c9:71  txqueuelen 1000  (Ethernet)
        RX packets 77  bytes 10089 (9.8 KiB)
        RX errors 0  dropped 10  overruns 0  frame 0
        TX packets 63  bytes 8498 (8.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.10.10  netmask 255.255.255.255
        loop  txqueuelen 1000  (Local Loopback)

I created a systemd script and then enabled this to start at boot:

[root@rocky ~]# cat /etc/systemd/system/lo_subint.service 
[Unit]
Description=lo0
After=network.target

[Service]
Type=simple
ExecStart=ifconfig lo:0 192.168.10.10 netmask 255.255.255.255
User=root
Group=root
Restart=always
RestartSec=5
TimeoutStopSec=60
TimeoutStartSec=10
StartLimitInterval=120
StartLimitBurst=5

[Install]
WantedBy=multi-user.target

bit of a hack with the systemd method, still searching for a better way.

So I managed to get it working exactly as you wanted. Not so clear cut, but here we go:

Install the old legacy network-scripts and enable the legacy network service:

dnf install network-scripts
systemctl enable network

Create the interface file exactly as below:

[root@rocky ~]# cat /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
NAME=lo:0
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=192.168.10.10
NETMASK=255.255.255.255
NETWORK=192.168.10.10
BROADCAST=192.168.10.10

Reboot, and check your network:

[root@rocky ~]# ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.72  netmask 255.255.255.0  broadcast 192.168.122.255
        inet6 fe80::5054:ff:fea2:c971  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:a2:c9:71  txqueuelen 1000  (Ethernet)
        RX packets 275  bytes 26289 (25.6 KiB)
        RX errors 0  dropped 24  overruns 0  frame 0
        TX packets 169  bytes 21436 (20.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 8  bytes 592 (592.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 592 (592.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.10.10  netmask 255.255.255.255
        loop  txqueuelen 1000  (Local Loopback)

Same person notes that ifconfig is out of favor and one should use tools from iproute2 (if not using NetworkManager’s UIs).

One should note that the base loopback (lo) is special. I have a feeling that it is configured and enabled on boot even if no service manages (NIC) interfaces. If NM does not touch anythin lo*, then that explains why you need the more blunt network.service.

Furthermore, firewalld.service is not suitable for a router.
In CentOS 7 you had better control with iptables.service, which is deprecated in 8.
CentOS 8 has nftables.service, because the kernel has nftables. Use that.
There should be a script that translates (most) iptables rulesets into nft’s syntax.

Yep agreed, was just searching to help provide info and a solution for them. They wanted a sub-interface so lo:0, similar when creating extra interfaces like enp1s0:0 or enp1s0:1 with different ip addresses. Although as noted, recommended is IPADDR2, IPADDR3 in the config files and not use the alias type interfaces anymore. ifconfig has been legacy for quite a while now, similar like netstat, route add default gw instead of ip addr add dev enp1s0 and ip route add.

Incidently, as I found out, just by installing network-scripts doesn’t actually revert to the old legacy type functionality until the old network service isn’t enabled and started. Also, prior to installing it, ifcfg-lo didn’t exist, and yet after install, ifcfg-lo then appeared, so seems to put a load of files in place to help allow using the legacy alias type interfaces like the original poster was wanting. I also realise that in the future the network-scripts package might disappear altogether so then that won’t be an option anymore to resolve such an issue.

I expect a lot of it could be done with nmcli as well.

So there are a couple of options to do it really:

  1. Use the preferred method adding IPADDR1, IPADDR2, IPADDR3, etc to the /etc/sysconfig/network-scripts/ifcfg-xxx file.
  2. Create a systemd script to use net-tools and the ifconfig command which would create the lo:0 or enp1s0:0 interfaces like the old school/legacy way.
  3. Install network-scripts, and just create the interface file with the respective details that I found later, which then returned the functionality to how he was expecting prior to upgrade.

Anyway just helping as there’s a number of ways to do a lot of things in Linux, some more preferred than others :slight_smile:

1 Like

That creates a question:
How to handle the task with NetworkManager, or is the additional loopback address even the “new normal” way to “anycast IPv4” for OSPF/quagga, etc?