For Cloud Server with 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 to a server that has Ubuntu 18.04, Ubuntu 20.04, Debian 10, 11 or Debian 12 installed.

Note

How to establish an encrypted network connection to your server using Secure Shell (SSH) is explained in the following articles:

Computers with Windows operating systems

Computers with Linux operating systems

Attention

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

Adding a public IPv4 address on a dedicated server (Ubuntu 20.04, 22.04, Debian 10 and 11)

Adding a public IPv4 address on a Dedicated Server (Ubuntu 20.04)

Adding a public IPv6 address on a Dedicated Server (Ubuntu 20.04)


The following article describes how to configure IPv4 addresses and IPv6 addresses on a Cloud Server that has Ubuntu 22.04 with netplan installed:

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:

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

  • You are logged in to the server.

  • You have noted down the IPv4 addresses and IPv6 addresses of the server.

Identify Network Interface

To identify 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: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.

Show Default DNS Server

  • 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

    The DNS servers are then 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, Authorisation
    < 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, Authorisation
    < 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

  • Note down 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 the DNS servers used are not displayed after entering the command, enter the following command:

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

    The DNS servers are then displayed at the end of the output. Example:

    [root@localhost ~]# resolvectl --no-pager |grep Server
    Current DNS Server: 212.227.123.16
    DNS Servers: 212.227.123.16 212.227.123.17

Display 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'

  • Note down 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


    In this example, fe80::1 is the IPv6 gateway.

Install Net-tools Package

Install the net-tools package. This package is a collection of important programmes 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

Add IPv4 and IPv6 addresses

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

    [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 address/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 address/64
    gateway fe80::1

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

  • To configure the additional IPv4 address(es), add 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 identified.

Note

The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press [ESC]. If you use command mode, your keyboard input is interpreted as a command.

  • To configure additional IPv6 addresses, add the following entry or entries below the entry for the main IPv6 address:

    iface <Interface_Device> inet6 static
    address Additional IPv6 address_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 you have determined.

    The following example shows a complete entry that is used to configure the main IPv4 and the main IPv6 address as well as an additional IPv4 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.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, enter the command :wq and then press Enter.

Add DNS Server

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 vi editor.

    [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, execute the following command:

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

Note

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

Restart Server and Check Configuration

  • To reboot the server, enter the following command:

    [root@localhost ~]# systemctl reboot

  • Log in to the server again.

  • To check whether the desired IPv4 and IPv6 addresses have been configured correctly, enter the command ip addr show:

    [root@localhost ~]# ip addr show

Note

If the server is no longer accessible due to a configuration error, you can log in to the server using the KVM console and correct the configuration.