Adding additional IPv4 to CentOS

Note:

This guide is applicable only for KVM based VPSes, for OpenVZ based VPSes please click here

To View Network Gateway and Netmask

Before configuring an additional IP, you’ll need the gateway and netmask details of your server.

To know the gateway and netmask of your IP address, please see this guide here

Configuring additional IPv4

First, we need to find the name of the network interface on our server,

To find the name of the network interface, simply run the following cmd,

ip a

This will give you an output similar to,

[root@test-server ~]# ip a
 1: lo: <LOOPBACK,UP,LOWER_UP> 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether 54:52:00:d7:74:ed brd ff:ff:ff:ff:ff:ff
     inet 104.194.215.70/24 brd 104.194.215.255 scope global noprefixroute dynamic ens3
        valid_lft 20732392sec preferred_lft 20732392sec
     inet6 fe80::5652:ff:fed7:74ed/64 scope link noprefixroute
        valid_lft forever preferred_lft forever

Here, we see that we have eth0 as our network interface, from the above example,

Other similar interfaces could be ens3, enp0s3 and many more.

If that's the case, you will have to replace eth0 with the interface name you have in your server for the following steps further in this guide.

Edit/Create the interfaces file

Each additional IP requires its own interface file.

For the first additional IP, create a file named:

nano /etc/sysconfig/network-scripts/ifcfg-eth0:1

Replace eth0 with your actual interface name (if different).

And add the following into it. (Replace the IP_ADDRESS,GATEWAY,NETMASK with your IP details)

DEVICE=eth0:1
BOOTPROTO=static
IPADDR=IP_ADDRESS
GATEWAY=GATEWAY
NETMASK=NETMASK
ONBOOT=yes

DEVICE: must match your interface name with :1 for the first additional IP. IPADDR: your new IPv4 address. GATEWAY: gateway for your VPS (usually the same as your primary IP’s gateway). NETMASK: subnet mask, typically 255.255.255.0 for /24 networks. ONBOOT: ensures the IP is activated when the VPS reboots.

Bring the New IP Online

Once the interfaces file is updated run,

ifup eth0:1

If successful, the new IP will immediately become active. You can verify using:

ip a

Restart Network Services (CentOS 8 / AlmaLinux 8 / RockyLinux 8)

On newer distributions, you may need to restart NetworkManager for changes to apply:

systemctl restart NetworkManager

If that doesn’t work, try:

nmcli networking off  && nmcli networking on

Or simply reboot your VPS:

reboot

After this, your additional IPv4 should be active and reachable.

To add more IPs,

  1. change ifcfg-eth0:1 to ifcfg-eth0:2, ifcfg-eth0:3, ifcfg-eth0:4 etc
  2. change DEVICE=eth0:1 to DEVICE=eth0:2, DEVICE=eth0:3, DEVICE=eth0:4 etc in the files

Verification

After completing all steps, confirm your IPs are working by:

ip a

CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS