You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

This guide will explain how to add a secondary IP address to a network interface on RHEL / CentOS 7/8 server. There are different ways of adding a secondary IP address to a RHEL / CentOS network interface. This guide will discuss manually creating a network configuration file and using Network Manager CLI tool – nmcli.

Add Secondary IP address Manually

The first method involve creating a sub-interface configuration file and populating network information into it. In my RHEL 8 server, my network interface has the following details.

# ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:8f:8c:86 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.198/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
valid_lft 1891sec preferred_lft 1891sec
inet6 fe80::4d61:1d19:14a4:a8dc/64 scope link noprefixroute
valid_lft forever preferred_lft forever

The network interface I’ll assign a secondary IPv4 address is enp1s0. This interface configuration file is located inside the /etc/sysconfig/network-scripts directory.

$ cat /etc/sysconfig/network-scripts/ifcfg-enp1s0

Let’s create a sub-interface configuration file.

sudo yum -y install vim
sudo vim /etc/sysconfig/network-scripts/ifcfg-enp1s0:1

Don’t ignore :1 at the end. Then add IP configuration data.

DEVICE=enp1s0:1
Type=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=192.168.122.11
PREFIX=24

Reboot your server to confirm secondary IP address.

sudo reboot

After system restart, check IP information for the interface.

# ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:8f:8c:86 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.197/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
valid_lft 3503sec preferred_lft 3503sec
inet 192.168.122.11/24 brd 192.168.122.255 scope global secondary noprefixroute enp1s0:1
valid_lft forever preferred_lft forever
inet6 fe80::4d61:1d19:14a4:a8dc/64 scope link noprefixroute
valid_lft forever preferred_lft forever

You can see we have two Ip addresses assigned to the interface – 192.168.122.197/24 and the secondary IP we assigned 192.168.122.11/24.

Confirm that you can access the server via secondary IP address.

$ ssh 192.168.122.11 
The authenticity of host '192.168.122.11 (192.168.122.11)' can't be established.
ECDSA key fingerprint is SHA256:5RuWUmEmb9WoXB6QSivSfvDj5DeaJrxT7N+GVTl/TA8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.122.11' (ECDSA) to the list of known hosts.
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Sat Mar 23 11:03:35 2019 from 192.168.122.1
[[email protected] ~]$ ip ad | grep enp1s0
2: enp1s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
inet 192.168.122.197/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
inet 192.168.122.11/24 brd 192.168.122.255 scope global secondary noprefixroute enp1s0:1

Add Secondary IP address using nmcli

The second method for those using NetworkManager service it to use nmcli command line tool. We will modify the same interface as shown earlier.

Check existing network connection profiles.

$ nmcli connection show 
NAME UUID TYPE DEVICE
enp1s0 498869bb-0d88-4a4c-a83a-c491d1040b0b ethernet enp1s0

Mark the interface you want to add a secondary IP address then proceed to modify its configuration.

sudo nmcli con mod enp1s0 +ipv4.addresses "192.168.122.11/24"

The +ipv4.addresses option is used to assign a secondary IP address.

Reboot your server to confirm secondary IP address.

sudo reboot

Confirm secondary IP assignment.

$ ip ad
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:8f:8c:86 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.197/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
valid_lft 3546sec preferred_lft 3546sec
inet 192.168.122.11/24 brd 192.168.122.255 scope global secondary noprefixroute enp1s0
valid_lft forever preferred_lft forever
inet6 fe80::4d61:1d19:14a4:a8dc/64 scope link noprefixroute
valid_lft forever preferred_lft forever

You have successfully added a secondary IP address to an interface on RHEL / CentOS 8 Linux server. You can read more related articles on below links.

How To Configure 802.1q VLAN Tagging on RHEL / CentOS 7/8 & Fedora Interface

How to Create a Linux Network Bridge on RHEL / CentOS 8

Install and Configure OpenVPN Server on RHEL / CentOS 8

How to Install Netdata on RHEL 8 / CentOS 8

Install and Configure Telegraf on RHEL / CentOS 8

Best CCNA R&S (200-125) Certification Preparation Books 2019

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF