How to add secondary IP address using nmcli
On an AlmaLinux 9 server, I wanted to add secondary IPs to a server. First, I checked the network interface device name used in the server with the command
ip a
The current public IP address was assigned to the network interface with the name enp13s0. To see how it is configured, I run
cd /etc grep -irl enp13s0
That showed the server am using Network Manager to configure the IP address
[root@node4 etc]# grep -irl enp13s0 NetworkManager/system-connections/enp13s0.nmconnection [root@node4 etc]#
You can add additional IP adding using nmcli command.
nmcli con mod DEVICE_NAME +ipv4.addresses "IP_ADDR/24"
Example
nmcli con mod enp13s0 +ipv4.addresses "67.222.158.35/24" nmcli con mod enp13s0 +ipv4.addresses "67.222.158.36/24" nmcli con mod enp13s0 +ipv4.addresses "67.222.158.37/24" nmcli con mod enp13s0 +ipv4.addresses "67.222.158.38/24" nmcli con mod enp13s0 +ipv4.addresses "67.222.158.39/24" nmcli con mod enp13s0 +ipv4.addresses "67.222.158.40/24" nmcli con mod enp13s0 +ipv4.addresses "67.222.158.41/24"
To make the IPs online, run
nmcli con up enp13s0
Now ip a command lists all secondary IP addresses
[root@node4 etc]# ip a show enp13s0 2: enp13s0:mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 74:56:3c:31:38:0a brd ff:ff:ff:ff:ff:ff inet 67.222.158.34/24 brd 67.222.158.255 scope global noprefixroute enp13s0 valid_lft forever preferred_lft forever inet 67.222.158.35/24 brd 67.222.158.255 scope global secondary noprefixroute enp13s0 valid_lft forever preferred_lft forever inet 67.222.158.36/24 brd 67.222.158.255 scope global secondary noprefixroute enp13s0 valid_lft forever preferred_lft forever inet 67.222.158.37/24 brd 67.222.158.255 scope global secondary noprefixroute enp13s0 valid_lft forever preferred_lft forever inet 67.222.158.38/24 brd 67.222.158.255 scope global secondary noprefixroute enp13s0 valid_lft forever preferred_lft forever inet 67.222.158.39/24 brd 67.222.158.255 scope global secondary noprefixroute enp13s0 valid_lft forever preferred_lft forever inet 67.222.158.40/24 brd 67.222.158.255 scope global secondary noprefixroute enp13s0 valid_lft forever preferred_lft forever inet 67.222.158.41/24 brd 67.222.158.255 scope global secondary noprefixroute enp13s0 valid_lft forever preferred_lft forever inet6 fe80::7656:3cff:fe31:380a/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@node4 etc]#
To list all network interface devices using nmcli, run
[root@node4 etc]# nmcli connection show NAME UUID TYPE DEVICE enp13s0 4ca2de2f-1f4d-38e2-84fc-4d17aafc2514 ethernet enp13s0 docker0 521f050e-7870-43b3-a6ca-618d45116b03 bridge docker0 [root@node4 etc]#
Back to IP