How to add an additional IP address in Debian and Ubuntu

How to add additional IPv4 address

First, we connect to our server and edit the network adapter configuration file:

nano /etc/network/interfaces

Then at the bottom of the file, specify the following data for IPv4, then press “CTL + X“, write “y” and press Enter:

auto ens3:1
allow-hotplug ens3:1
iface ens3:1 inet static
        address IP address
        netmask network mask

In our case, it looks like this:

After we have saved the changes in the network adapter configuration file, we restart the network service with the command:

service networking restart

And after restarting the network service, we ping the address to see if it is really accessible from outside the server. We made it!

How to add additional IPv6 address to the server

To add additional IPv6 to the server, you must open the network adapter configuration file and write it inside like this:

nano /etc/network/interfaces
up ip -6 addr add IP dev ens3
down ip -6 addr del IP dev ens3

After we have added the address and saved the network adapter configuration file, we restart the network service in the same way as we did with IPv4, using the command:

service networking restart

After network service restart, we run the command line and check if our server is accessible via IPv6 that we just added

As you can see, our IPv6 address is available and works from outside the server.
If you have any questions about setting up, please contact us!