How to Add IPs to your network interface

You have ordered new IP addresses, then chose the server at the same location, yet you still cannot ping it? That is because the IP is not configured on your server’s network interface yet. There are various ways to do that, some are better than others, thus we will show you the simplest approach.

In this example we will use subnet of

191.96.192.54/32

which is assigned to a Cloud Hosting TestServer2 server at Frankfurt using CentOS 7 v2.0.4.

Note: do not forget to stop and then start the Cloud Hosting server after assigning the additional IPs to the server (thank you, our clients, for pointing this out!).

Firstly, to configure the IP, you have to connect to the server, for that, you will need the connection details: main IP, user, and password or SSH key, depending on the way your server is configured. To get this info, go to Terminal > Cloud Hosting, then select the server.

To connect to the server we will use PuTTY.

Copy the password before actually logging to the server, then type root for the user, for the password just press the right mouse button and press enter (the password will be pasted automatically).

Let’s check the current configurations of network interfaces, to do that type

ip a

Furthermore, we need the name of our network interface. In the picture above we can see that it is eth0 and that our main IP is already configured. Now we can add our secondary IP to the interface as an alias. We can check that the secondary IP is not configured or used by pinging it.

To add the IP as an interface alias, we will use this command:

ip addr add 191.96.192.54/32 dev eth0:

For IPv6 add -6, for example:

ip -6 addr add fdxx:xxxx:xxxx:yyyy:zzzz:zzzz:zzzz:zzzz dev eth0:

After this, we can check whether it is pinging:

We can also inspect the network interface on the server using

ip a

command again:

However, there is a downside to this approach – after restart of this server, this configuration is dropped.

On the other hand, we can easily overcome this problem using rc.local script, which is traditionally executed after all the normal system services have started. To edit it, you can use any available editor, in this example, we will use NANO editor. If you do not have it, you can easily install nano with command

sudo apt-get install nano

for Debian and Ubuntu systems, or use

yum install nano

for CentOS systems.
Now, go to /etc using command

cd /etc,

then type

nano rc.local

Paste the commands you want to keep after restart to the file (remember, you can paste in PuTTY by pressing the right mouse button) and save it using shortcut CTRL+X. After that, make sure to remember to type

chmod +x /etc/rc.d/rc.local

and

chmod +x /etc/rc.local

so that your script is executable.

The next step is not necessary, but you can check whether your configurations are saved after restart. To do that, just type

sudo reboot

reconnect to the server, then again use

ip a

to inspect the configuration.

If your configuration is not saved, most frequently users omit the step of making the script executable, thus make sure not to forget that.

Another problem you might face using this approach is that there is no rc.local script – some new distributions have it disabled. You can find information about enabling it here.

What is important to mention, that all IP addresses routed to your server have the same gateway. There is no difference in how you configure additional IP addresses but all of them will have the same gateway. By default, all additional IP ranges are being routed statically to the server’s main IP address. The gateway can be found by going to your servers overview page, Network tab or just type ‘ip r’ when you are inside your server.

Approach 2: Configure full IP range

Moreover, this can be done using IP range approach adding the IP range configuration in a script that would automatically configure the IP range once the network is restarted. For this operation, we need to know the name of the interface (in this example we will use):

eth0

Furthermore, the additional IP has to be assigned to the server via Terminal and the server should be stopped/started before assigning the IPs.

Let’s go to

network-scripts

folder:

cd /etc/sysconfig/network-scripts

Then create a new file:

vi ifcfg-eth0-range0

Note that the

 eth0

is the network interface name and

 range0

is the number of the range to add. Next file would be

 ifcfg-eth0-range1

and etc.

Let’s fill the file with the configuration (the range we are trying to add is 141.98.89.0/29 and for gateway we will use the gateway for the main IP of the server).

To find the gateway of the main IP of the server, simply go to Terminal, select your server, click on

 Network

Now let’s fill the file with configuration:

And do not forget to restart the network service.

systemctl restart network

Now let us inspect the configuration:

Looks great.
Let’s check the connection:

Perfect, the range is now configured on the network interface.

Was this article helpful?

Still need help?

Heficed Slack Community

Get involved in Heficed Slack community. Get updates, ask questions, connect with peers.

Heficed Slack

Need support?

If you need any further help, don't hesitate to send a support request to our support team.