How to configure additional IPv4 addresses for dedicated servers?
What is an IP address?
An IPv4 address (Internet Protocol version 4) is necessary for IP communication. Each host is assigned with a unique IP address number, e.g. 10.10.0.254, which allows communication participants to recognize each other.
What is a default gateway and network address?
A default gateway is a network device that sends network packets from one local network to another external network as a transition point. For a default gateway to connect to an external network, the default gateway address, IP address, and subnet mask must be set. These are crucial parts of the TCP/IP network configuration.
A device without a default gateway address specified can only exchange packets on the local network. The gateway sends and receives packets of selected protocols addressed to itself, e.g. IPv4, and interprets them. It then becomes an intermediary server necessary, for example, as protection against external networks.
Therefore, to configure additional IPs correctly, you must distinguish between IPs with a shared gateway and others:
With shared gateway (different class) - when the gateway address of the secondary IP address is the same as the gateway address of the dedicated server
Gateway address of the primary IP address: 95.214.53.1
Gateway address of secondary IP address: 95.214.53.1
With different gateway (different class) - when the gateway address of the secondary IP address is different from the gateway address of the dedicated server.
Gateway address of the primary IP address: 95.214.53.1
Gateway address of secondary IP address: 91.223.3.129
What is a subnet mask?
With a subnet mask you can determine which part of an IP address is the address of a network and a subnetwork and which part is the address of a machine participating in the data exchange on that subnetwork.
A subnet mask is a 32-bit number consisting of 0 and 1. However, it is more often written in 8-bit versions, decimal and separated by dots, e.g. 255.255.255.128
All routers and computers in a given subnet must know the value of the mask. Comparing the subnet mask with an individual IP address tells the router the part of the address that identifies the subnetwork, and the part that identifies the device to which the address is assigned.
The abbreviated notation for the mask, which specifies the number of initial bits with the value 1, looks like this 185.16.37.46/24
Subnet mask | Abbreviated notation |
---|---|
255.255.252.0 | /22 |
255.255.254.0 | /23 |
255.255.255.0 | /24 |
255.255.255.128 | /25 |
255.255.255.192 | /26 |
255.255.255.224 | /27 |
255.255.255.240 | /28 |
255.255.255.248 | /29 |
255.255.255.252 | /30 |
255.255.255.254 | /31 |
255.255.255.255 | /32 |
For systems: Debian 8/9/10, Ubuntu 16/18
All details about the IP address you obtained: its address, gateway, mask, and MAC address can be found in the Mevspace panel in the Dedicated Server tab.
Above is a sample picture with information about the IPv4 Customer has in the Mevspace panel with the same network gateway.
ip addr add <ip address>/<subnet mask, e.g. 25> dev <interface, to whichaddress you want to add, e.g. eth0>
Example:
ip addr add 172.20.0.10/25 dev eth0
Attention: For the purpose of this guide, addresses from the private class are used. This method works only with operating systems Debian 8/9/10, Ubuntu 16/18.
/etc/network/interfaces
:
post-up ip addr add <ip address>/<subnet mask e.g. 25> dev <interface, towhich you want to add the address to, e.g. eth0>
Example:
post-up ip addr add 172.20.0.10/25 dev eth0
/etc/network/interfaces
file:
auto eth0iface eth0 inet staticaddress 172.20.0.5netmask 255.255.255.128gateway 172.20.0.1post-up ip addr add 172.20.0.10/25 dev eth0
Done! Your IPv4 address is configured.
Adding a purchased IPv4 address to a dedicated server with a different gateway.
For systems - Debian 8/9/10, Ubuntu 16/18
In case the additional IP address has a different gateway than the gateway of the primary IP address of the dedicated server as shown in the picture below:
When the gateway address of the additional IP address is different from the gateway address of the dedicated server you need to add a routing table.
ip addr add <ip address>/<subnet mask, e.g. 25> dev <interface, to whichaddress you want to add, e.g. eth0>
Example:
ip addr add 172.20.0.10/25 dev eth0
echo "id_table name_table" >> /etc/iproute2/rt_tables
Example:
echo "100 additional_ip" >> /etc/iproute2/rt_tables
Attention: If you have different network gateways in additional IP addresses you must repeat the action of adding routing tables same amount of times as quantity of IP addresses with different network gateways you have. If the network gateways are identical for several addresses, you should create routing tables only once for each gateway. The table names must be different for each unique gateway.
ip route add default via <gateway address> table <gateway_name>
Example:
ip route add default via 172.20.0.129 table additional_ip
ip rule add from <ip address>/32 table <table_name>
Example:
ip rule add from 172.20.0.10/32 table additional_ip
Attention: You must separately add each additional IP address to the routing table with the appropriate gateway for it.
/etc/network/interfaces
:
post-up ip rule add from <ip address>/32 table additional_ippost-up ip route add default via <gateway address> table <table_name>post-up ip addr add <ip address>/<mask, e.g. 25> dev <interface, to whichaddress you want to add, e.g. eth0>
Example:
post-up ip rule add from 172.20.0.10/32 table additional_ippost-up ip route add default via 172.20.0.129 table additional_ippost-up ip addr add 172.20.0.10/25 dev eth0
/etc/network/interfaces
:
auto eth0iface eth0 inet staticaddress 172.20.0.5netmask 255.255.255.128gateway 172.20.0.1post-up ip addr add 172.20.0.10/25 dev eth0post-up ip rule add from 172.20.0.10/32 table additional_ippost-up ip route add default via 172.20.0.129 table additional_ip
Done! Your IPv4 address is now configured.
For systems: CentOS 7/8
All the data about the received IP address: its address, gateway, mask and MAC address can be found in the Mevspace panel in the Dedicated Servers tab.
Above is a sample image with information about the customer's IPv4s in the Mevspace panel with the same network gateway.
ip addr add <ip address>/<subnet mask, e.g. 25> dev <interface, to whichaddress you want to add, e.g. eth0>
Example:
ip addr add 172.20.0.10/25 dev eth0
Attention: For the purpose of this guide, addresses from the private class were used.
nano /etc/sysconfig/network-scripts/ifcfg-eth0:<id of virtual interface>
Example:
/etc/sysconfig/network-scripts/ifcfg-eth0:<id of virtual interface>
Paste:
DEVICE=eth0:<id of virtual interface>BOOTPROTO=staticONBOOT=yesNM_CONTROLLED=noIPADDR=<ip address>NETMASK=<subnet mask>
Example:
DEVICE=eth0:0BOOTPROTO=staticONBOOT=yesNM_CONTROLLED=noIPADDR=172.20.0.10NETMASK=255.255.255.128
Save the file and exit: CTRL + O
, Enter
, CTRL + X
.
Done! Your IPv4 address is now configured.
Adding a purchased IPv4 address to a dedicated server with a different gateway for CentOS.
For systems - CentOS 7/8
In case the additional IP address has a different gateway than the gateway of the primary IP address of the dedicated server as shown in the image below:
Above is a sample image with information about clients IPv4 with different network gateways.
When the gateway address of the additional IP address is different from the gateway address of the dedicated server you need to add an additional routing table.
sudo yum install NetworkManager-config-routing-rulessudo systemctl enable NetworkManager-dispatcher.servicesudo systemctl start NetworkManager-dispatcher.service
ip addr <ip address>/<subnet mask, e.g. 25> dev <interface, to whichaddress you want to add, e.g. eth0>
Example:
ip addr add 172.20.0.10/25 dev eth0
For the purpose of this guide, addresses from the private class were used.
echo "id_table table_name" >> /etc/iproute2/rt_tables
Example:
echo "100 additional_ip" >> /etc/iproute2/rt_tables
Attention: If you have different network gateways in additional IP addresses you must repeat the action of adding routing tables the same amount of times as the quantity of IP addresses with different network gateways you have. If the network gateways are identical for several addresses, you should create routing tables only once for each gateway. The table names must be different for each unique gateway.
nano /etc/sysconfig/network-scripts/ifcfg-eth0:<id of virtual interface>
Example:
/etc/sysconfig/network-scripts/ifcfg-eth0:0
Paste:
DEVICE=eth0:<id of virtual interface>BOOTPROTO=staticONBOOT=yesNM_CONTROLLED=noIPADDR=<ip address>NETMASK=<subnet mask>
Example:
DEVICE=eth0:0BOOTPROTO=staticONBOOT=yesNM_CONTROLLED=noIPADDR=172.20.0.10NETMASK=255.255.255.128
Save the file and exit: CTRL + O
, Enter
, CTRL + X
.
nano /etc/sysconfig/network-scripts/route-<network interface name>
Example:
nano /etc/sysconfig/network-scripts/route-eth0
Attention: IP Routes must be placed in route-eth0 file (main interface configuration), not in separate config files for aliases (route-eth0:0 isn’t a valid config file).
default via <gateway address of secondary IP address> table <name ofrouting table we created>
Example:
default via 172.20.0.129 table additional_ip
Attention: Add each network address gateway on separate lines.
nano /etc/sysconfig/network-scripts/rule-<network interface name>
Example:
nano /etc/sysconfig/network-scripts/rule-eth0
Attention: IP Rules must be placed in the rule-eth0 file (main interface configuration), not in separate config files for aliases (rule-eth0:0 isn’t a valid config file).
from <additional IP address> table <routing table, to which we want toadd address>
Example:
from 172.20.0.10 table additional_ip
Attention: You must add each additional IP address to the routing table separately with the appropriate gateway for it, on separate lines.
reboot
or
systemctl restart NetworkManager.service
Done! Your IPv4 address is configured.