Atlantic.Net Blog

How to Add A Private IP to a Debian Server

Verified and Tested 02/27/2021

Introduction

In this How-to, we will learn how to configure a private IP address on a Debian Server. Private networking is a great way to keep the traffic between your servers internal and not accessible publicly. It allows you to communicate between your servers without using your Cloud bandwidth as well. It is also faster than public traversal as it will not require leaving the network to reach the destination server. At this time, private networking within our Cloud will only be able to communicate with same region servers.

Verifying your Private IP range with our Cloud Control Panel

First, we will need to find out what your private IP range is:

Sign into your Cloud Control Panel:

Once logged in, click on “Private IPs.”

Navigating to your Private IPs

On the Private IP page, you will see the IP range allocated to your account. Under “IP” are the Private IPs available to use.

Private IP page

Once you have the private IP range to use, we will add it to our Debian server.

Adding the Private IP address to your Debian Server

Log in to your server and use your text editor to open /etc/network/interfaces. In this tutorial, we will be using nano.

nano /etc/network/interfaces

We will need to add the private IP address as an additional IP on the secondary interface.

Note: by default, each Cloud Server comes with two interfaces. To find your secondary interface, run either command ifconfig or ip addr. In the below example, the primary interface is ens3 and the secondary interface is ens4. Your interface name may vary depending on the version of Debian. The secondary interface, unless set up prior to this, will not have an IP address associated with it.

root@debianserver:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group defaul t qlen 1
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 inet 127.0.0.1/8 scope host lo
 valid_lft forever preferred_lft forever
 inet6 ::1/128 scope host
 valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP gr oup default qlen 1000
 link/ether xx:x:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
 inet 172.16.1.1/24 brd 172.16.1.255 scope global ens3
 valid_lft forever preferred_lft forever
 inet6 0000::0000:0000:0000:0000/64 scope link
 valid_lft forever preferred_lft forever
3: ens4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff

We will need to add the following under the last interface configuration in /etc/network/interfaces.

auto ens4
iface ens4 inet static
 address XX.XX.XX.XX <--- Private IP address
 netmask 255.255.255.0 <--- Subnet Mask for Private IP range

After you have added the new private IP, save and exit.

You will need to restart networking for the changes to take effect. For Debian 8 and 9, this can be done via systemd

systemctl restart networking

Prior versions will use upstart.

service networking restart

After restarting the networking, you should be able to run either the ip addr or ifconfig command to verify the private IP is configured and came up just fine.

You should see an output similar to this:

root@debianserver:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 inet 127.0.0.1/8 scope host lo
 valid_lft forever preferred_lft forever
 inet6 ::1/128 scope host
 valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
 inet 172.16.1.1/25 brd 172.16.1.255 scope global ens3
 valid_lft forever preferred_lft forever
 inet6 0000::0000:0000:0000:0000/64 scope link
 valid_lft forever preferred_lft forever
3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
 inet 10.10.10.3/24 brd 10.10.10.255 scope global ens4
 valid_lft forever preferred_lft forever
 inet6 fe80::200:aff:fef5:2776/64 scope link
 valid_lft forever preferred_lft forever

Now you have successfully added a Private IP to your Debian Server! Don’t forget to check out our many other articles and keep checking back for more.

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year