For Virtual Private Server and Cloud Server running Ubuntu 18.04, Ubuntu 20.04, Debian 10, Debian 11, and Debian 12.

This article explains how to add additional, public IPv4 and IPv6 addresses on a server that has Ubuntu 18.04, Ubuntu 20.04, Debian 10, 11, or Debian 12 installed.

Attention

These instructions are only valid for the Cloud Server or Virtual Private Server. How to add IPv4 addresses and IPv6 addresses on a Dedicated Server is described in the following article:

Adding Public IPv4/IPv6 Addresses on a Dedicated Server (Ubuntu 20.04, 22.04, Debian 10 and 11)


How to configure IPv4 addresses and IPv6 addresses on a Virtual Private Server or Cloud Server that has Ubuntu 22.04 with netplan installed is described in the following article:

Configuring Public IPv4 and IPv6 Addresses on a Linux Server with netplan (Ubuntu 22.04)

How to configure additional, public IPv4 and IPv6 addresses in Ubuntu 18.04, Ubuntu 20.04, Debian 10, 11, or Debian 12:

Requirements
  • You have assigned one or more public IPv4 and/or IPv6 addresses to your server in the Cloud Panel.

  • You are logged into the server.

  • You made a note of the IPv4 addresses and IPv6 addresses of the server.

Viewing the Network Interface

To determine the file name of the network interface, enter the following command:

[root@localhost ~]# ip addr

Example:

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:2b:2c:68 brd ff:ff:ff:ff:ff:ff
    inet 212.227.209.26/32 brd 212.227.209.26 scope global dynamic ens192
       valid_lft 33737sec preferred_lft 33737sec
    inet6 fe80::250:56ff:fe2b:2c68/64 scope link
       valid_lft forever preferred_lft forever

In this example, the name of the network interface is ens192.

Viewing the Default DNS Server(s)

  • To display the DNS servers used, enter the following commands:

    [root@localhost ~]# curl http://169.254.169.254/latest/meta_data/dns/nameservers -Lv

    [root@localhost ~]# curl http://169.254.169.254/latest/meta_data/dns/nameservers6 -Lv

    Afterwards the DNS servers used are displayed at the end of the output. Example:

    [root@localhost ~]# curl http://169.254.169.254/latest/meta_data/dns/nameservers -Lv
    * Trying 169.254.169.254...
    * TCP_NODELAY set
    * Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
    > GET /latest/meta_data/dns/nameservers HTTP/1.1
    > Host: 169.254.169.254
    > User-Agent: curl/7.61.1
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Date: Thu, 08 Sep 2022 12:19:36 GMT
    < Server: Apache
    < Strict-Transport-Security: max-age=63072000; includeSubDomains
    < Vary: Accept-Encoding
    < Access-Control-Allow-Origin: *
    < Access-Control-Allow-Headers: X-TOKEN, X-HASH, X-MICROTIME, X-USER, Content-Type, X-API-TOKEN, Authorization
    < Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
    < Access-Control-Expose-Headers: Error-Msg
    < Cache-control: no-cache, no-store, max-age=0
    < Access-Control-Allow-Origin: *
    < Access-Control-Allow-Headers: X-TOKEN, X-HASH, X-MICROTIME, Content-Type, X-API-TOKEN, Authorization
    < Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
    < Access-Control-Expose-Headers: Error-Msg
    < Transfer-Encoding: chunked
    < Content-Type: text/plain;charset=UTF-8
    <
    212.227.123.16,212.227.123.17
    * Connection #0 to host 169.254.169.254 left intact.

  • Make a note of the DNS servers. In the example above, the DNS servers are displayed above the line * Connection #0 to host 169.254.169.254 left intact.

    If you do not see the DNS servers used after entering the command, enter the following command:

    [root@localhost ~]# resolvectl --no-pager |grep Server

    Afterwards the DNS servers used are displayed at the end of the output. Example:

    root@localhost:/etc/netplan# resolvectl --no-pager |grep Server
    Current DNS Server: 212.227.123.16
           DNS Servers: 212.227.123.16 212.227.123.17 2001:8d8:fe:53:72ec::1

Viewing the Gateway for IPv4 and IPv6

  • To display the default gateway of the active interface, enter the following commands:

    IPv4:

    [root@localhost ~]# ip route show | grep 'default'

    IPv6:

    [root@localhost ~]# ip -6 route show | grep 'default'

  • Make a note of the IP addresses of the gateways. These are listed directly after the default via part. Examples:

    IPv4 Gateway

    [root@localhost ~]# /etc/netplan# ip route show | grep 'default'
    default via 10.255.255.1 dev ens192 proto dhcp src 82.165.247.234 metric 100

    IPv6 Gateway

    [root@localhost ~]# /etc/netplan# ip -6 route show | grep 'default'
    default via fe80::250:56ff:fe8b:5f29 dev ens192 proto ra metric 100 expires 4sec pref high

 

       The gateway in this example is: fe80::1

Installing the Net-tools Package

Install the net-tools package. This package is a collection of important programs for controlling the network subsystem.

To install net-tools, enter the following commands:

[root@localhost ~]# apt-get update
[root@localhost ~]# apt-get upgrade
[root@localhost ~]# apt-get install -y net-tools

Adding IPv4 and IPv6 Addresses

  • Open the file /etc/network/interfaces with the editor vi.

    [root@localhost ~]# vi /etc/network/interfaces

  • Replace the existing entries with the following information:

    source /etc/network/interfaces.d/*

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug <Interface_Device>

    iface <Interface_Device> inet static
        address Main IPv4-Adresse/32
        gateway 10.255.255.1
        up route add -net 10.255.255.1 netmask 255.255.255.255 dev <Interface_Device> 

    iface <Interface_Device> inet6 static
        address Main IPv6-Adresse/64
        gateway fe80::1

  • Replace the placeholder <Interface Device>  in all places with the interface device you determined. Then enter the main IPv4 address and the main IPv6 address.

  • To configure the additional IPv4 address(es), insert the following entry(s) below the entry for the main IPv4 address:

    iface <Interface_Device> inet static
        address Additional IPv4-Address_1

    iface <Interface_Device> inet static
        address Additional IPv4-Address_2

  • Replace the Additional IPv4 Address part with the desired additional IPv4 address.

  • Replace the placeholder <Interface Device>  with the interface device you determined.

Note

The vi editor has an insert mode and a command mode. You can enter the insert mode by pressing the [i] key. In this mode, the entered characters are immediately inserted into the text. To enter the command mode, press [ESC] afterwards. When you use the command mode, your keyboard inputs are interpreted as a command.

  • To configure additional IPv6 addresses, insert the following entry(s) below the entry for the main IPv6 address:

    iface <Interface_Device> inet6 static
        address Additional IPv6-Adresse_1
        gateway fe80::1

    iface <Interface_Device> inet6 static
        address Additional IPv6-Address_2
        gateway fe80::1

  • Replace the Additional IPv6 address part with the desired additional IPv6 address.

  • Replace the placeholder <Interface_Device> with the interface device that you determined.

    The following example shows a complete entry that is used to configure the main IPv4 address, the main IPv6 address, and an additional IPv4 address and an additional IPv6 address.

    source /etc/network/interfaces.d/*

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug ens192

    iface ens192 inet static
        address 82.165.103.128/32
        gateway 10.255.255.1
        up route add -net 10.255.255.1 netmask 255.255.255.255 dev ens192 

    iface ens192 inet static
        address 212.227.193.228/32

    iface ens192 inet6 static
        address 2001:8d8:1800:334::1/64
        gateway fe80::1

    iface ens192 inet6 static
        address 2001:8d8:1800:334::2/64
        gateway fe80::1

  • To exit vi and save the file, type the command :wq then press Enter.

Adding DNS Servers

To add the DNS servers, proceed as follows:

Ubuntu 18.04, Ubuntu 20.04, Debian 10 and Debian 11
  • Open the file /etc/systemd/resolved.conf with the editor vi.

    [root@localhost ~]# vi /etc/systemd/resolved.conf

  • Then enter the DNS servers in the following format:

    DNS=<DNS-Server1> <DNS-Server2> <DNS-Server3>

  • If the # symbol is listed at the beginning of this entry, delete it. Otherwise, the setting will not be applied.

  • Save the file.

  • To apply the setting, run the following command:

    [root@localhost ~]# systemctl restart systemd-resolved

Please Note

For Cloud Servers and Virtual Private Servers with Debian 12, the DNS servers do not need to be added.

Restarting the Server and Checking the Configuration

  • To restart the server, enter the following command:

    [root@localhost ~]# systemctl reboot

  • Log into the server again.

  • To verify that the desired IPv4 and IPv6 addresses are configured correctly, enter the ip addr show command:

    [root@localhost ~]# ip addr show

Please Note

If the server becomes unreachable due to a configuration error, you can log in to the server using the KVM console and correct the configuration.