How to Add a Second IP Address on Red Hat and OS based on Red Hat

Adding a second IP address on Red Hat, CentOS, AlmaLinux, or Rocky Linux may differ from Debian as it often involves using different tools for network configuration. On Red Hat-based systems, the nmcli tool is commonly used, or editing configuration files. Below are the steps for adding a second IP address using nmcli.

Check for the Existence of a Network Interface

Use the following command to check existing network interfaces:

ip addr

Note the interface name, for example, ens18.

Find the Network Connection Name

Use the following command to list available network connections and find the one associated with your interface:

nmcli connection show

Look for the connection name corresponding to your network interface, such as:

NAME   UUID                                  TYPE      DEVICE
ens18  7105c4f0-248c-401b-8aa8-f42749f45b5b  ethernet  ens18

Add the Second IP Using nmcli

Use the nmcli command to add a second IP:

sudo nmcli connection modify <CONNECTION_NAME> +ipv4.addresses <SECOND_IP>/<PREFIX>

Where:

  • <CONNECTION_NAME> is your network connection name (in this example: ens18)
  • <SECOND_IP> is the new IP address
  • <PREFIX> is the subnet mask prefix length

Restart the Network Interface

Restart the network interface to apply the changes:

sudo nmcli connection up <CONNECTION_NAME>

Check the New IP

Verify if the second IP address has been added:

ip addr

Make sure you see the new IP address under your network interface.

Prevent cloud-init from Modifying Network Settings

To avoid interference from cloud-init, which may alter network settings, follow the instructions on this page to restrict cloud-init from making network configuration changes.

Рейтинг: 1 Star2 Stars3 Stars4 Stars5 Stars (1 оцінок, сер. 5.00)
Loading...