Close
    logoMevspace Docs
    English

    How to configure additional IPv4 addresses for dedicated servers?

    Reading time: 8 min

    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 maskAbbreviated 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

    Adding a purchased IPv4 address to a dedicated server with a shared gateway.

    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 (formerly Skynode) panel in the Dedicated Server tab.

    additional ipv4 address panel shared gateway

    Above is a sample picture with information about the IPv4 Customer has in the Mevspace (formerly Skynode) panel with the same network gateway.

    1
    Login to SSH console.
    2
    To bind an IPv4 address to the network interface, use the command in the console:
    ip addr add <ip address>/<subnet mask, e.g. 25> dev <interface, to which
    address 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.

    3
    To assign an additional IPv4 address to the network interface after the dedicated server startup, add it to

    /etc/network/interfaces:

    post-up ip addr add <ip address>/<subnet mask e.g. 25> dev <interface, to
    which you want to add the address to, e.g. eth0>

    Example:

    post-up ip addr add 172.20.0.10/25 dev eth0
    4
    Example

    /etc/network/interfaces file:

    auto eth0
    iface eth0 inet static
    address 172.20.0.5
    netmask 255.255.255.128
    gateway 172.20.0.1
    post-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:

    additional ipv4 address panel different gateway

    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.

    1
    Login to SSH console.
    2
    After logging in, plug the IPv4 address into the interface:
    ip addr add <ip address>/<subnet mask, e.g. 25> dev <interface, to which
    address you want to add, e.g. eth0>

    Example:

    ip addr add 172.20.0.10/25 dev eth0
    3
    Create routing tables:
    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.

    4
    After adding the routing table, add a default gateway for it:
    ip route add default via <gateway address> table <gateway_name>

    Example:

    ip route add default via 172.20.0.129 table additional_ip
    5
    Then add the purchased address to the table:
    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.

    6
    To assign an additional IPv4 address to the network interface after the dedicated server startup, create a virtual interface

    /etc/network/interfaces:

    post-up ip rule add from <ip address>/32 table additional_ip
    post-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 which
    address you want to add, e.g. eth0>

    Example:

    post-up ip rule add from 172.20.0.10/32 table additional_ip
    post-up ip route add default via 172.20.0.129 table additional_ip
    post-up ip addr add 172.20.0.10/25 dev eth0
    7
    Example file

    /etc/network/interfaces:

    auto eth0
    iface eth0 inet static
    address 172.20.0.5
    netmask 255.255.255.128
    gateway 172.20.0.1
    post-up ip addr add 172.20.0.10/25 dev eth0
    post-up ip rule add from 172.20.0.10/32 table additional_ip
    post-up ip route add default via 172.20.0.129 table additional_ip

    Done! Your IPv4 address is now configured.

    Adding a purchased IPv4 address to a dedicated server with a shared gateway for CentOS.

    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 (formerly Skynode) panel in the Dedicated Servers tab.

    additional ipv4 address panel shared gateway

    Above is a sample image with information about the customer's IPv4s in the Mevspace (formerly Skynode) panel with the same network gateway.

    1
    Log in to the console using SSH.
    2
    To bind an IPv4 address to the network interface use in the the command in console:
    ip addr add <ip address>/<subnet mask, e.g. 25> dev <interface, to which
    address 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.

    3
    To assign an additional IPv4 address to the network interface after the dedicated server startup, create a virtual interface:
    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=static
    ONBOOT=yes
    NM_CONTROLLED=no
    IPADDR=<ip address>
    NETMASK=<subnet mask>

    Example:

    DEVICE=eth0:0
    BOOTPROTO=static
    ONBOOT=yes
    NM_CONTROLLED=no
    IPADDR=172.20.0.10
    NETMASK=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:

    additional ipv4 address panel different gateway

    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.

    1
    Log in to the SSH console and run the following commands:
    sudo yum install NetworkManager-config-routing-rules
    sudo systemctl enable NetworkManager-dispatcher.service
    sudo systemctl start NetworkManager-dispatcher.service
    2
    To attach an IPv4 address to the network interface, use in the console command:
    ip addr <ip address>/<subnet mask, e.g. 25> dev <interface, to which
    address 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.

    3
    Create a routing table:
    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.

    4
    To assign an additional IPv4 address to the network interface after the dedicated server startup, create a virtual interface:
    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=static
    ONBOOT=yes
    NM_CONTROLLED=no
    IPADDR=<ip address>
    NETMASK=<subnet mask>

    Example:

    DEVICE=eth0:0
    BOOTPROTO=static
    ONBOOT=yes
    NM_CONTROLLED=no
    IPADDR=172.20.0.10
    NETMASK=255.255.255.128

    Save the file and exit: CTRL + O, Enter, CTRL + X.

    5
    To add a network gateway for this address create a file:
    nano /etc/sysconfig/network-scripts/route-<network interface name>

    Example:

    nano /etc/sysconfig/network-scripts/route-eth0
    6
    Paste the following text into it:
    default via <gateway address of secondary IP address> table <name of
    routing table we created>

    Example:

    default via 172.20.0.129 table additional_ip

    Attention: Add each network address gateway on separate lines.

    7
    Create a file:
    nano /etc/sysconfig/network-scripts/rule-<network interface name>

    Example:

    nano /etc/sysconfig/network-scripts/rule-eth0
    8
    Paste the following content into the created file:
    from <additional IP address> table <routing table, to which we want to
    add 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.

    9
    Perform a reboot of the server or network manager:

    reboot

    or

    systemctl restart NetworkManager.service

    Done! Your IPv4 address is configured.

    Previous
    Tutorials
    Next
    How to install Windows 10 with KVM?