How to set a static IP address under OS Linux

Some time ago we published a guide on how to set a static IP address in the Windows operating system on your VPS. The reason for publishing this process is the fact that IP addresses are assigned to VPS by DHCP. However, the DHCP protocol is not intended for deployment, and therefore it is suitable to set a static IP address for a virtual server.


This process is not limited only to VPS, but may also be used for physical servers and it is written for the Ubuntu Server 14.04 LTS distribution. The process will work the same on other distributions which are based on the Debian distribution.


In the details of your virtual server under the Server parameter module you will find the setting for your primary IPv4 and IPv6 address. The primary IP address is the address specified as the first one in the Server parameter module and it is not marked with a star.


Detail of virtual server service


Detailed information about the IPv4 address including options to set reverse DNS record may be found in the lower section of the page under the IPv4 tab after you click on it.


More details about static IP


Before you start editing any file it is recommended to back up the edited file!
Do not forget to save each change made to the edited file!


Switch to superuser mode on your server and open the following file in your favourite text editor: /etc/network/interfaces, for example with the command:


# nano /etc/network/interfaces

IPv4 address configuration

Search for the following line in the /etc/network/interfaces file:


iface eth0 inet auto

Change the line to:


iface eth0 inet static


Then insert the following line into the file:


iface eth0 inet static
address [IPv4 address of your server]
netmask [Mask of your IPv4]
gateway [Gateway of your IPv4]

Configuring several IPv4 addresses

Several IP addresses may be assigned to the server, but this does not mean that you can avoid setting up a static IP address. DHCP will always assign only one primary IP address. The list of all IPv4 addresses assigned to your server may be found in the service detail in the Server parameter module or in the lower section of the page under the IPv4 tab.


Configuration of IPv4



Use your favourite editor again to open /etc/network/interfaces and find the following line in the file:


auto eth0

In order to be able to configure several IPv4 addresses on one network interface, you need to create a so-called virtual interface. You may create as many virtual interfaces as there are IPv4 addresses that you need to configure.


auto eth0
auto eth0:1
auto eth0:2
auto eth0:3
…...
….
..
auto eth0:x

Configure the primary IPv4 address using the previous guide. Each additional IP address is configured separately.


iface eth0:1 inet static
address [next IPv4 address of your server]
netmask [Mask of next IPv4 address of your server]

iface eth0:x inet static
address [next IPv4 address of your server]
netmask [Mask of next IPv4 address of your server]

IPv6 address configuration

Search for the following line in the /etc/network/interfaces file:


iface eth0 inet6 auto

Change the line to:


iface eth0 inet6 static

Sometimes this line may not be present in the configuration file. In such a case, create it and add the following text:


iface eth0 inet6 static
address [IPv6 address of your server]
netmask [Mask of your IPv6, usually 64]
gateway [gateway of your IPv6]
pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/autoconf
pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra
pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra_defrtr
pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra_pinfo
pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra_rtr_pref

Configuring several IPv6 addresses

Configuring several IPv6 addresses for one interface is much easier than for the IPv4 protocol. You will find the list of all IPv6 addresses or rather the assigned IPv6 subnet in the service details, but this time in the lower section of the page under the IPv6 tab.


Configuration of IPv6


To see the detailed configuration for the assigned IPv6 subnet, click on the name of the IPv6 subnet.


Detail of IPv6 subnet


You may add other IPv6 addresses into our configuration file – ideally, this should be done immediately after the primary IPv6 is set. We recommend entering one address per one line.


up /sbin/ifconfig eth0 inet6 add [next IPv6 address of your server]/[Mask of your IPv6, usually 64]
up /sbin/ifconfig eth0 inet6 add [next IPv6 address of your server]/[Mask of your IPv6, usually 64]
up /sbin/ifconfig eth0 inet6 add [next IPv6 address of your server]/[Mask of your IPv6, usually 64]
up /sbin/ifconfig eth0 inet6 add [next IPv6 address of your server]/[Mask of your IPv6, usually 64]
....
...
..
up /sbin/ifconfig eth0 inet6 add [next IPv6 address of your server]/[Mask of your IPv6, usually 64]

DNS configuration

In order to configure DNS servers, you need to edit another two additional files. First, use your favourite text editor to open the following file: /etc/resolvconf/resolv.conf.d/head, for example with the command:


# nano /etc/resolvconf/resolv.conf.d/head

and add the following lines


options rotate
options timeout:2

Now open the following file for editing again: /etc/resolvconf/resolv.conf.d/tail, for example with the command:


# nano /etc/resolvconf/resolv.conf.d/tail

and add lines containing the addresses of the DNS servers. You will find the addresses of DNS servers once again in the client section, in the details of the IPv4 address or in the IPv6 subnet.


nameserver 87.236.197.113
nameserver 87.236.198.211
nameserver 87.236.197.68
nameserver 2a01:5f0:1031:2::1
nameserver 2a01:5f0:1030:2::1
nameserver 2a01:5f0:1030:3::1
nameserver 2a01:5f0:1031:3::1

Network interface restart

To save the changes, either for IPv4 or for IPv6, you need to restart the relevant network interface. You may do so via the following command:


# /etc/init.d/networking restart

Author: Jirka Dvořák


Customer
support

By using this site you agree to the use of cookies for analytics and personalised content. More...
Agree