How to add secondary IP addresses to your server

If you request additional IPv4 addresses, also known as secondary IP addresses, you will need to add them to your server manually if your server is not covered by our managed hosting or by paying for a one-time server administration ticket.

Go to your system:

Linux Systems

Red Hat/AlmaLinux/Rocky Linux/Oracle Linux

This was developed for Network Scripts. RHEL 8+ defaults to Network Manager. Change to Network Scripts before following this section.

Connect to your server and navigate to /etc/sysconfig/network-scripts/ using the command cd /etc/sysconfig/network-scripts/ and locate your primary interface config file. You can use the ls command to show all files in this directory. To know which network interface is your public network interface, you can use the ip a command and find your public IP address.

Depending on your system, this could be eth0 or have an ens# name (for example, ens18) or more commonly enp#s## (for example enp0s18) name.

Make a copy of the appropriate ifcfg file and add an incrementing :# for each additional IP address. For example, we are using ifcfg-ens18 and adding another IP, use the command: cp ifcfg-eno18 ipcfg-ens18:0 and press enter/return.

Edit the newly created file with vi or nano (use nano if you're not comfortable or familiar with vi).

nano ifcfg-eno18:0

Edit the file accordingly:

Delete the items marked in red (PROXY_METHOD, BROWSER_ONLY, DEFROUTE, IPV4_FAILURE_FATAL, IPV6INIT, IPV6_AUTOCONF, IPV6_DEFROUTE, IPV6_FAILURE_FATAL, IPV6_ADDR_GEN_MODE, and UUID).

Change the items marked in yellow to the new values (example: NAME=ens18 would become NAME=ens18:0, etc.) and add your network configuration.

Do not change anything not highlighted.

Repeat this process for each additional IP, incrementing the number. So for example, for the next IP, use the command cp ifcfg-eno18 ipcfg-ens18:1 and so on. If you are adding a /29 network (5 usable IPs), you would need to repeat this process so you have the files ipcfg-ens18:0 through ipcfg-ens18:4. Edit each of the files like you did above.

Restart the network service and watch for any errors. If the service fails to re-connect, access your server through the console to diagnose.

systemctl restart network

Or you can reboot your server to apply the new IPs.

Debian/Ubuntu (Non-Netplan)

Open /etc/network/interfaces file. An example is below.

auto lo
iface lo inet loopback

auto eth0 iface eth0 inet static address 192.168.0.42 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 gateway 192.168.0.1

Below the line auto eth0 add auto eth0:1. Under the block iface eth0, add another identical block but with the interface name eth0:1. Add the secondary IP address, mask, and gateway accordingly. Your file should look something like this, just with your values:

auto lo
iface lo inet loopback

auto eth0
auto eth0:1
auto eth0:2
auto eth0:3 iface eth0 inet static address 192.168.0.42 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 gateway 192.168.0.1
iface eth0:1 inet static address 192.168.200.2 network 192.168.200.0 netmask 255.255.255.0 broadcast 192.168.200.255 gateway 192.168.200.1
iface eth0:2 inet static address 192.168.200.3 network 192.168.200.0 netmask 255.255.255.0 broadcast 192.168.200.255 gateway 192.168.200.1
iface eth0:3 inet static address 192.168.200.4 network 192.168.200.0 netmask 255.255.255.0 broadcast 192.168.200.255 gateway 192.168.200.1

Restart the networking service or reboot your server to apply. If the service fails to re-connect or start, access your server through the console to diagnose.

Ubuntu (with Netplan)

If you have Netplan, there are two cases in which to apply additional IP addresses. In the first case, all IPs are part of the same subnet. For example, your server's initial IP is 192.168.1.156/24 but then you are issued 192.168.1.53/24 as a secondary IP. In this case, use Case 1. If your IPs are part of different subnets, which is typical if you request more than 5 secondary IPs (your server's primary IP is 192.168.1.156/24 but you are issued 192.168.34.104/29 as secondary IPs), then you will need to use Case 2.

Note: The commands in this section should be ran as root. If you do not have a root user, start each command with sudo.

Case 1

Edit your main netplan file (the name will be dependent on how Ubuntu was installed). Check in /etc/netplan/ for any possible names should the command below not work.

nano /etc/netplan/01-netcfg.yaml

Edit the file to include your additional IP addresses (changes are bold):

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: false
      addresses:
        - 192.168.1.156/24
        - 192.168.1.53/24
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
      routes:
        - to: default
          via: 192.168.1.1

Run the command netplan try to test the changes. If the changes are valid, the counter will continue to tick down. Press Enter to save and apply the changes. If the counter stops or your connection drops, the changes will be reverted after 120 seconds.

Case 2

Create a new netplan file (do not edit your existing netplan file).

nano /etc/netplan/02-netcfg.yaml

Add the secondary network configuration to it:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: false
      addresses:
        - 192.168.34.106/29
- 192.168.34.107/29
- 192.168.34.108/29
- 192.168.34.109/29
- 192.168.34.110/29 nameservers: addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: default via: 192.168.34.105

Note: Make sure you update the values with your assigned IPs.

Save the file and exit nano. Run the command netplan try to test the changes. If the changes are valid, the counter will continue to tick down. Press Enter to save and apply the changes. If the counter stops or your connection drops, the changes will be reverted after 120 seconds.

Windows Server

Access your TCP/IP settings by right clicking on the Start button > selecting Network Connections > click Change Adapter Options > and then right click on your Public network connection and click Properties.

Then select TCP/IPv4 and click Properties.

Click on Advanced.

Add each IP and the gateway for the subnet to the IP addresses and default gateways sections, respectively. You only need to add the subnet's gateway once.

Click on OK three times. Your secondary IP addresses are now installed.

Article Information
  • Article ID: 354
  • Category: Networking
  • Viewed 259 times.
  • Rating:
    (0)
  • Was this article helpful?
  • Yes No
Did you find this article helpful?