How to add and remove an alias IP Address for RHEL8+

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 8 and 9
    • NetworkManager

Issue

  • Error: '/etc/sysconfig/network-scripts/ifcfg-eth0:test' is not an active connection

Resolution

  • Sample environment:
    IP: 198.51.100.10
    Alias IP: 198.51.100.1
# nmcli c add con-name eth0 type ethernet ifname eth0 ipv4.method manual ipv6.method disable ipv4.addresses 198.51.100.10/24
  • Method 1: Use a dummy interface
# nmcli c add type dummy ifname eth0-dummy con-name eth0-dummy ipv4.method manual ipv6.method disable ipv4.addresses 198.51.100.1/24
# cat << 'EOF' > /etc/NetworkManager/dispatcher.d/30-eth0-dummy
#!/bin/bash
if [ "$1" == "eth0-dummy" ] && [ "$2" == "up" ]; then
    /usr/sbin/arping -q -A -c 1 -w 3 -I eth0 198.51.100.1
    sleep 2
    /usr/sbin/arping -q -U -c 1 -w 3 -I eth0 198.51.100.1
fi
EOF
# chmod +x /etc/NetworkManager/dispatcher.d/30-eth0-dummy

This will add the 198.51.100.1 alias to eth0-dummy:
# nmcli con up eth0-dummy

This will remove the alias from eth0-dummy:
# nmcli con down eth0-dummy
  • Method 2: Similar functionality can be added by creating a clone of the interface and assigning the alias to that.
# nmcli c clone --temporary eth0 eth0-01
# nmcli c mod eth0-01 +ip4 198.51.100.1/24

This will add the 198.51.100.1 alias to eth0:
# nmcli c up eth0-01

This will remove the alias from eth0:
# nmcli c down eth0-01

Or the alias IP Address can be added and removed as follows:

To add:
# nmcli con mod eth0 +ipv4.addresses 198.51.100.1/24
# nmcli con up eth0
To remove:
# nmcli con mod eth0 -ipv4.addresses 198.51.100.1/24
# nmcli con up eth0

Note: "nmcli c up/down" removes all IP addresses of the connection profile for a moment. It slightly affects network communication.

For RHEL7 and earlier refer to How to assigne aliases IP addresses to network cards in prior to RHEL8

Root Cause

In prior releases alias IP Addresses could be added and removed with ifup/ifdown. But this was deprecated in RHEL8. So the following will fail:

# ifup eth0:test
Error: '/etc/sysconfig/network-scripts/ifcfg-eth0:test' is not an active connection
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.