How to assign multiple IP addresses to network adapter on Linux Cloud Servers

2021-12-13 By Ryan 17940 Views linux ip networking
8 reviews

Users may need to set up multiple IP addresses to the same network interface for hosting various SSL sites and avoid firewalls or being blacklisted in SPAM filters, etc. This is very useful for setting up multiple virtual sites in Apache using a single network interface with different IP addresses on a single subnet network.


This guide will help you to configure multiple IP addresses on Linux cloud servers.





AlmaLinux/Rocky Linux/CentOS


  1. Check the current IP address of the server using the below command.

    # ip addr
    

    linuxmultiip1

    In the above example, the IP address is 146.196.54.248, you can find your server IP address on eth0 adapter.

  2. Run the below command to view the network configuration file contents.

    # cat /etc/sysconfig/network-scripts/ifcfg-eth0
    

    linuxmultiip2

  3. Create the sub-interface configuration files under /etc/sysconfig/network-scripts/ and add the configurations as below, then save and exit the file.

    **ifcfg-eth0:0**
    
    BOOTPROTO=static
    DEFROUTE=yes
    DEVICE=eth0:0
    DNS1=8.8.8.8
    IPADDR=192.168.2.2
    NETMASK=255.255.255.0
    ONBOOT=yes
    STARTMODE=auto
    TYPE=Ethernet
    USERCTL=no
    

    linuxmultiip3

    NOTE: In this example, 192.168.2.2 is the secondary IP address and you can replace it with the original additional IP address.


    **ifcfg-eth0:1**
    
    BOOTPROTO=static
    DEFROUTE=yes
    DEVICE=eth0:1
    DNS1=8.8.8.8
    IPADDR=192.168.2.3
    NETMASK=255.255.255.0
    ONBOOT=yes
    STARTMODE=auto
    TYPE=Ethernet
    USERCTL=no
    

    linuxmultiip4

    NOTE: In this example, 192.168.2.3 is the secondary IP address and you can replace it with the original additional IP address.

  4. Reboot the server to reflect the changes. Once rebooted, then log in to the server using SSH and run the below command to display the IP addresses.

    # ip addr
    

    linuxmultiip5

  5. The additional IP addresses will be configured in the eth0:0 and eth0:1 sub interface as in the above screenshot. In this way, you can add a bunch of IP addresses to a Single Network Interface.





Ubuntu 20.04LTS


  1. Check the current IP address of the server using the below command.

    # ip addr  
    

    linuxmultiip6

    In the above example, the IP address is 146.196.54.248, you can find your server IP address on ens3 adapter.

  2. Run the below command to view the network configuration file contents.

    # cat /etc/netplan/50-cloud-init.yaml
    

    linuxmultiip7

  3. Add the additional IP address to the addresses field in the configuration file once you open the file in a suitable editor such as vi or nano.

    # vi /etc/netplan/50-cloud-init.yaml
    

    linuxmultiip8

    NOTE: In this example, 192.168.1.3 is the secondary IP address and you can replace it with the original additional IP address.

  4. Save the changes execute the command netplan apply.

    # netplan apply
    

    linuxmultiip9

  5. Restart the networking process to reflect the changes using the command.

    # systemctl restart networking.service
    

    linuxmultiip10


    Then try to check the interface IP address whether it is reflecting

    # ip addr
    

    linuxmultiip11

  6. Repeat the above steps in case if it requires adding more IP addresses to the NIC interface.





Debian / Ubuntu18


  1. Check the current IP address of the server using the below command.

    # ip addr  
    

    linuxmultiip12

    In the above example, the IP address is 146.196.54.248, you can find your server IP address on ens3 adapter.

  2. Run the below command to view the network configuration file contents.

    # cat /etc/network/interfaces
    

    linuxmultiip13

  3. Open the configuration file here which is located in /etc/network/interfaces.

    # nano /etc/network/interfaces
    


    Here, for the additional IP address, you would require to enter the configuration in the following format, where interface-name is the adapter name shown in ip addr output (E.g. ens3) and the additional IP address is the IP address you wish to add.

    iface <interface-name> inet static  
    address <additional-ip address="">
    


    In the Cloud Servers, the entry will be:

    linuxmultiip14

    NOTE: In this example, 192.168.0.3 is the secondary IP address and you can replace it with the original additional IP address.

  4. Save the changes and restart the network process.

    # systemctl restart networking.service
    

    linuxmultiip15

    To verify the changes, check the interface IP address whether it is reflecting

    # ip addr
    

    linuxmultiip16

  5. Repeat the above steps in case if it requires adding more IP addresses to the NIC interface.


Related tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.