Child pages
  • Adding Multiple IP Addresses in CentOS 7
Skip to end of metadata
Go to start of metadata
Note: In this article we are using private IP addresses (192.168.0.0) as an example. On your servers you’ll more than likely be adding IP addresses that are publicly routed and available. If you wish to purchase additional IPs for your 100TB bare metal server, feel free to contact our Sales team, they’ll be happy to help you out.

Introduction

At certain times you will want or need to assign or add additional IP addresses to your server. Fortunately this is a relatively easy process. This how-to guide shows you the easiest way of adding those additional IP addresses to your CentOS 7 server.

This article is specific to CentOS 7 because compared to previous releases of CentOS 7 uses NetworkManager, which handles network interfaces and IP addresses slightly differently. In reality, even though it is different, this new method is easier. Previously, you had to create a new interface alias for each new IP address that you wanted to assign to the same NIC. With CentOS 7 it’s just a matter of adding a few lines to your pre-existing configuration file.
 

View currently assigned IPs

In order to view the IP addresses that are currently assigned to your NIC, run the following command:

ip addr

This command will show all of the currently configured network interfaces as well as the vital network information related to them, such as the current IP address, netmask, gateway and broadcast addresses. If you’re not sure what netmask, gateway and broadcast addresses are, don’t worry, it’s not necessary for this guide.

The output should be similar to the following:

 

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

   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 ::2/128 scope global

      valid_lft forever preferred_lft forever

   inet6 ::1/128 scope host

      valid_lft forever preferred_lft forever

2: p2p1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

   link/ether 78:45:c4:17:fa:74 brd ff:ff:ff:ff:ff:ff

   inet 192.168.0.20/24 brd 192.168.0.255 scope global dynamic p2p1

      valid_lft 84707sec preferred_lft 84707sec

   inet6 fe80::7a45:c4ff:fe17:fa74/64 scope link

      valid_lft forever preferred_lft forever

As you can see, I have several interfaces that are currently configured. The one that we will focus on for this guide is the second interface entitled p2p1 (on your system the interfaces might have a different name, such as eth0, eth1, etc).

Add additional IPs to your network interface

Now, in order to add additional IP addresses you’ll need to edit the configuration file (from hereon called “config file”) for this specific interface. On CentOS 7, the interface config files are located in /etc/sysconfig/network-scripts/ and they are all prefixed with ifcfg-. So, go ahead and open up the config file for your interface (be sure to replace p2p1 with the actual name of your interface).


vi /etc/sysconfig/network-scripts/ifcfg-p2p1


The output may look like the following:

 

TYPE="Ethernet"

BOOTPROTO="static"

NAME="p2p1"

IPADDR="192.168.0.20"

UUID="113b3841-d06d-4a3c-89e8-1a49105a904a"

ONBOOT=yes

HWADDR="78:45:C4:17:FA:74"

The line that you will want to pay attention to is the “IPADDR” line (highlighted above). That is the initial IP address that is assigned to your server, and it should be pingable from outside. In order to add an additional IP address, simply add a line below that titled IPADDR1, such as I have below.

 

TYPE="Ethernet"

BOOTPROTO="static"

NAME="p2p1"

IPADDR="192.168.0.20"

IPADDR1=”192.168.0.21”

UUID="113b3841-d06d-4a3c-89e8-1a49105a904a"

ONBOOT=yes

As you can see, I’ve added the line IPADDR1=”192.168.0.21” which assigns that new IP to the p2p1 interface. In order for our changes to take effect we need to restart the network service using the following command.

systemctl restart network

Once the network has been restarted successfully, you should be able to ping that new IP address from another location. You can test this by using ping in a Windows cmd prompt or another Linux machine’s terminal. You should see output similar to what is shown below:
 

ping 192.168.0.21

Pinging 192.168.0.21 with 32 bytes of data:

Reply from 192.168.0.21: bytes=32 time<1ms TTL=64

Reply from 192.168.0.21: bytes=32 time<1ms TTL=64

Reply from 192.168.0.21: bytes=32 time<1ms TTL=64

Reply from 192.168.0.21: bytes=32 time<1ms TTL=64

 

Congratulations, you’ve successfully assigned an additional IP to your server’s network interface!