Assigning additional IP to NIC
In this guide, we’ll walk you through a few simple steps showing you the process of assigning your newly purchased IP range to your network interface card (NIC). There are many ways to do so, but we’ll only focus on the simplest and safest approach. This guide will cover the process of assigning IP ranges to NIC on Ubuntu, CentOS and Debian Linux.
Assingning additional IP ranges to Ubuntu 18 – Ubuntu 20
To assign a new IP range to Ubuntu 18.04 and newer, we’ll be using netplan.
Log into your server via the Heficed terminal or SHH and change the directory to to /etc/netplan
First, we’ll have to choose the network interface card we wish to assign the additional IP range to. To list all available network interfaces type ifconfig
In this example, the only NIC available to us is ens3. Let’s assign 18.104.22.168/29 to it.
Next, using your favorite text editor create a new .yaml file named 01-network-manager-all.yaml
In the newly created file, type:
network: version: 2 ethernets: ens3: dhcp4: false addresses: - 22.214.171.124/24 - 126.96.36.199/29 - 188.8.131.52/29 - 184.108.40.206/29 - 220.127.116.11/29 - 18.104.22.168/29 gateway4: 22.214.171.124 nameservers: addresses: - 126.96.36.199 - 188.8.131.52
Keep in mind that you should respect a proper indentation for each line since the prefixed number of spaces for each line is important, no TAB‘s are allowed. Not adhering to this, may lead up to an error message similar to: Invalid YAML at /etc/netplan/01-network-manager-all.yaml line 5 column 4: did not find expected key
Once you’ve made sure that the indentations are correct, press ctrl+x then y then enter to save the configuration file. Our next step is to test if the configuration file is accepted by netplan. We can do that by typing the following command:
If no mistakes we’re made in our configuration file, we should be presented with a message saying “Configuration accepted“.
Next, let’s apply the new configuration to netplan:
The only thing left to do is to stop/start the server to allow outgoing traffic. You can do that directly from your Heficed terminal. Now that our server is restarted, let’s check if the new configuration was successfully applied to our NIC. We can do that by typing:
The output should provide you with all IP addresses currently assigned to your NIC.
Lastly, let’s check if we can reach each individual IP via ping:
ping -c4 184.108.40.206
Success, the new range is configured on your network interface.
Assingning additional IP ranges to NIC at CentOS
We’ll be assigning 220.127.116.11/29 to our CentOS7 cloud server.
First, let’s change the directory and make a copy of our network configuration file:
cd /etc/sysconfig/network-scripts && cp ifcfg-eth0 ifcfg-eth0-range0
Edit the file by adding the missing lines as in the example below.
Press ESC then: and type wq to save the changes and exit the text editor. Next, we’ll have to restart our network service in order for the changes to take place.
service network restart
We can see our newly configured IP addresses by typing out the ip a command:
We can see that our new configuration has been applied successfully. Remember to always stop/start the cloud server via the Heficed terminal after you add a new IP range. Once that’s out of the way, let’s test if we’re able to reach outside destinations via our new IP’s
ping -S 18.104.22.168 google.com
Assigning to Debian Linux
Let’s assign 22.214.171.124/29 to our Debian 9 cloud server. For this guide, we strongly suggest you to connect to your server via SSH in order to save time.
To begin with, we should backup the current network interface configuration file. We can do that by simply copying and renaming the file.
sudo cp /etc/network/interfaces /etc/network/interfaces_bak
Next, we have to find the network interface we’ll be assigning the new range to. We can do that by typing ifconfig.
In this case, we’ll be adding it to the interface named eth. Edit the configuration with your favorite text editor, we’ll be using nano in this example.
The unedited configuration file will look something like this:
We’ll now have to configure the additional IP’s by adding the following lines:
auto eth0:0 iface eth0:0 inet static address 126.96.36.199/29 auto eth0:1 iface eth0:1 inet static address 188.8.131.52/29
Once all IP’s are added, reboot the server for changes to be applied
Log back into your server and check if the IP’s have been added to your network interface by typing ip a
Now, let’s do some ping testing to confirm everything is working fine. To ping outside networks using one of the newly configured IP’s type:
ping -S 184.108.40.206 google.com
You may as well use your personal machine to ping one of the addresses to check if inbound traffic is reaching your server.
Was this article helpful?
If you need any further help, don't hesitate to send a support request to our support team.