Article overview

Help article

Configuring an internal IP-addresses on a Linux VPS

Once you have added your VPSs to a Private Network, you will first have to set up internal IP addresses before you can make full use of them.

In the examples, the 192.168.0.0/16 range is used. However, you can choose one of the IP ranges defined in the RFC for use within private networks: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. The examples also use nano as an editor, but you are free to use your favorite editor.

This article covers various Linux OS's. For Windows, please see this article.

  • Perform the steps in this article as root, or user with sudo rights.
     
  • In case of incorrect adjustments, you can make your VPS unreachable. Make sure you also have access to your VPS using the console in the control panel (if you do this via SSH). In addition, it is strongly recommended to make a Snapshot in advance which you can fall back on.

CentOS 6

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2

Open your network configuration:

nano /etc/sysconfig/network-scripts/ifcfg-eth1

(eth1 is the name of your private network adapter. ifcfg-eth0 is the adapter of your public network.)


 

Step 3

A default configuration is already set in the configuration file. Add the options below / adjust the existing configuration. Replace the IP behind 'IPADDR' with the IP address that you actually want to use.

Do not adjust the values ​​behind HWADDR and UUID in your existing configuration!

ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.2
NETMASK=255.255.255.0
USERCTL=no

 

Step 4

Save your settings and close your editor (ctrl + x > y > enter). Finally, run the following command to restart the network:

/etc/init.d/networking restart

 

Optional: extra private IPs

If you want to set up more internal IPs, you can create a new file for each additional private IP address:

nano /etc/sysconfig/network-scripts/ifcfg-eth1:1

Please note that if you have already set an extra IP address to eth1:1, you will use the next interface (i.e. eth1:2).

An empty configuration file opens. Enter the following:

DEVICE=eth1:1
BOOTPROTO=static
IPADDR=192.168.1.2
NETMASK=255.255.255.0
ONBOOT=yes

CentOS 7

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2

Check the MacAddress of your private network-adapter. This can be done using the command:

ip a

You'll see output similar to the example below. Your MacAdress can be  Je MacAddres is shown like in the example encircled in red. Please note that you write down the MacAddress for eth1 and not eth0.

centos 7 ip a output


 

Step 3

Open your network configuration file, or create it if it doesn't exist: 

nano /etc/sysconfig/network-scripts/ifcfg-eth1

(eth1 is the name of your private network adapter. ifcfg-eth0 is the adapter of your public network.)   


 

Step 4

Add the options below / adjust the existing configuration. Replace the IP behind 'IPADDR' with the IP address that you actually want to use.

Do not adjust the values ​​behind HWADDR, UUID, etc. if you have an existing configuration!

ONBOOT=yes
HWADDR="52:54:00:e5:4f:1e"
BOOTPROTO=static
IPADDR=192.168.1.1
NETMASK=255.255.255.0
USERCTL=no  

 

Step 5

Save your settings and close your editor (ctrl + x > y > enter).

Finally, run the following command to restart the network: 

systemctl restart network

 

Optional: extra private IPs

If you want to set up more internal IPs, expand the configuration in step 3 with IPADDR0, IPADDR1, etc. and NETMASK0, NETMASK1, etc.: 

ONBOOT=yes 
BOOTPROTO=static 
IPADDR=192.168.1.2 
IPADDR0=192.168.1.3 
NETMASK=255.255.255.0 
NETMASK0=255.255.255.0 
USERCTL=no  

Debian 8 

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2 Open the network configuration: 

nano /etc/network/interfaces

 

Step 3 

Choose an internal IP address that you want to use and enter the following configuration at the bottom of the file (i.e. under the existing configuration): 

auto eth1
iface eth1 inet static
address 192.168.1.2
   netmask 255.255.255.0 

The configuration for eth0 is already included in the file. By adding the above code, you configure your private network adapter eth1 with a static IP address. 


 

Step 4

Save your settings and close your editor (ctrl + x > y > enter). Finally, run the following command to restart the network: 

systemctl restart networking

 

Optional: extra private IPs 

If you want to set up more internal IPs, you do this the same way as when you add extra regular IP addresses (you use this format per IP, so a third IP gets the interface name eth1:1, a fourth eth1:2 etc.): 

auto eth1:0
allow-hotplug eth1:0
iface eth1:0 inet static
   address 192.168.1.3
   netmask 255.255.255.0  

Debian 9

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2 

Open your network configuration:

nano /etc/network/interfaces

 

Step 3 

Add the configuration for ens7 at the bottom of the open file. 

auto ens7
iface ens7 inet static
   address 192.168.1.2
   netmask 255.255.255.0 

So, you add a new interface directly below the existing one (ens3). Do not adjust the existing 'public' interface (ens3). 


 

Step 4 

Save your settings and close your editor (ctrl + x > y > enter). Finally, run the following command to restart the network: 

systemctl restart networking

 

Optional: extra private IPs 

Do you want to set up more internal IPs? You then add an extra (kind of) sub-adapter for each IP address separately in your configuration:

auto ens7:0
allow-hotplug ens7:0
iface ens7:0 inet static
   address 192.168.1.3
   netmask 255.255.255.0

You use this format per IP address. A third IP address thus gets the interface name ens7:1, a fourth ens7:2 etc.   


FreeBSD 

Please note! Although fully based on FreeBSD, the instructions below do NOT work for pfSense. For this, you will always have to add private IPs via the interface of pfSense. 

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2 Open the network configuration (Nano is not standard in FreeBSD): 

vi /etc/rc.conf

 

Step 3 

Your private network interface (vtnet1) is probably not yet included in the configuration. Enter the configuration for vtnet1 (the private network interface). Choose an internal IP address that you want to use, for example: 

ifconfig_vtnet1="inet 192.168.1.2 netmask 255.255.255.0"

For example, the result looks like this:

freebsd network configuration with private network


 

Step 4 

Save your settings (:wq!) And run the following command to restart the network: 

/etc/rc.d/netif restart 

You can then test your IP address using a ping command: 

ping 192.168.1.2

Ubuntu 14 

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2 

Open the network configuration: 

nano /etc/network/interfaces  

 

Step 3 

Choose an internal IP address that you want to use and enter the configuration at the bottom of the file:

auto eth1
iface eth1 inet static
   address 192.168.1.2
   netmask 255.255.255.0

The configuration for eth0 is already included in the file. By adding the above code, you configure your private network adapter eth1 with a static IP address.  


 

Step 4 

Save your settings and close your editor (ctrl + x > y > enter). Finally, run the following command to restart the network: 

sudo ifdown eth0 && sudo ifup eth0

This command also immediately includes your private network adapter (eth1). Other commands, such as 'sudo /etc/init.d/networking restart', give an error message and do not implement the change.


Optional: extra private IPs 

If you want to set up more internal IPs, you do this the same way as when you add extra regular IP addresses (you use this format per IP, so a third IP gets the interface name eth1:1, a fourth eth1:2 etc.): 

auto eth1:0
allow-hotplug eth1:0
iface eth1:0 inet static
   address 192.168.1.3
   netmask 255.255.255.0

After this, a restart of your VPS is required. Other commands such as sudo /etc/init.d/networking restart do not actually implement the change.   


Ubuntu 16 

From Ubuntu 16, PredictableNetworkInterfaceNames is used and the eth1 interface for the private network interface is no longer used by default. Instead, this interface will be assigned an "ens" interface if you add it to a private network. 

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2 

Open your network configuration: 

nano /etc/network/interfaces

 

Step 3 

Add the configuration for ens7 at the bottom of the open file. 

auto ens7iface ens7 inet static  address 192.168.1.2  netmask 255.255.255.0

So, you add a new interface directly below the existing one (ens3). Do not adjust the existing 'public' interface (ens3). 


 

Step 4 

Save your settings and close your editor (ctrl + x > y > enter). Finally, run the following command to restart the network: 

systemctl restart networking

 

Optional: extra private IPs 

Do you want to set up more internal IPs? You then add an extra (kind of) sub-adapter for each IP address separately in your configuration: 

auto ens7:0
allow-hotplug ens7:0
iface ens7:0 inet static
  address 192.168.1.3
   netmask 255.255.255.0

You use this construction per IP, so a third IP gets the interface name ens7:1, a fourth ens7:2 etc.


Ubuntu 18 

Ubuntu 18 has moved away from static interfaces (/etc/network/interfaces) and switched to NetPlan. Netplan is a YAML network configuration abstraction for various backends. Your network configuration now takes place in a yaml file, namely /etc/netplan/01-netcfg.yaml. 

 

Step 1

Log in to your VPS using SSH or the VPS console.


 

Step 2 

Open your network configuration:

nano /etc/netplan/01-netcfg.yaml

 

Step 3 

Add the configuration for ens7 at the bottom of the open file. 

Insert your awesome code here!

So, you add a new interface directly below the existing one (ens3). Do not adjust the existing 'public' interface (ens3). 


 

Step 4

Save your settings and close your editor (ctrl + x > y > enter). Finally, run the following command to restart the network: 

netplan apply

 

Optional: extra private IPs 

Any additional IPs can be added directly under the list of 'addresses' in your configuration as shown in the example below. 

ens7:
  dhcp4: no
  addresses:
   - 192.168.1.2/24
   - 192.168.1.3/24

 

Should you have any questions left regarding this article, do not hesitate to contact our support department. You can reach them via the ‘Contact Us’ button at the bottom of this page.

 

If you want to discuss this article with other users, please leave a message under 'Comments'.

 

Do you have a good idea?

Give us your idea! If it's popular we'll add it to the wishlist!

Has this article been helpful?

Create an account or log in to leave a rating.

Comments

Create an account or log in to be able to leave a comment.

0
Matthijs van Beek Admin June 21, 2018 (#1463)

@thunderb1te

Not yet, but this article is on our schedule to receive an overhaul / update (probably late August / early september), in which Ubuntu 18.04 will be included.

0
thunderb1te June 20, 2018 (#1459)

Hebben jullie hier toevallig ook een voorbeeld voor in Ubuntu 18.04?

Are you stuck?

Ask one of our specialists to assist you

Contact us