For Cloud Server

This article explains how to add additional public IPv4 and IPv6 addresses to a Cloud Server that has Ubuntu 22.04 and netplan installed.

The network configuration is carried out in the images of IONOS for Ubuntu 22.04 via netplan. The network configuration is no longer controlled via the /etc/network/interfaces file, but via files with the file extension .yaml, which are located in the /etc/netplan directory. If there are several files in this directory, they are loaded in lexical order.

Note

How you can 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 and Virtual Private Server with Ubuntu 22.04. 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)

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 18.04, Ubuntu 20.04, Debian 10, 11 or Debian 12 installed:

Adding public IPv4 and IPv6 addresses on a Linux server (Ubuntu 18.04, Ubuntu 20.04, Debian 10, 11 and Debian 12)

How to configure additional, public IPv4 and IPv6 addresses in Ubuntu 22.04:

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.

Check whether netplan is used for the network configuration

To check whether your server is already using netplan for network configuration, enter the following command:

  • To check if the netplan.io package is installed on your Ubuntu or Debian system, enter the following command:

    [root@localhost ~]# dpkg -l | grep netplan.io

    If the netplan.io package is installed, you will see the following information, for example:

    root@localhost:~# dpkg -l | grep netplan.io
    ii netplan.io 0.105-0ubuntu2~22.04.3 amd64 YAML network configuration abstraction for various backends

  • Change to the /etc/netplan directory.

    [root@localhost ~]# cd /etc/netplan

  • Check whether there is already a configuration file in this directory. To do this, enter the following command:

    [root@localhost ~]# ls

Note

If the netplan.io package is not installed and the /etc/netplan directory does not exist, netplan has not been installed. In this case, do not install netplan, but follow the steps described in the following article:

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

Identify Network Interface

Identify the file name of the network interface. To do this, enter the following command:

[root@localhost ~]# ip addr

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

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:08:a5:c6 brd ff:ff:ff:ff:ff:ff:ff
altname enp11s0
inet 217.160.141.60/32 metric 100 scope global dynamic ens192
inet6 2001:8d8:1801:5d2::1/64 scope global dynamic noprefixroute
valid_lft 3443sec preferred_lft 3443sec
inet6 fe80::250:56ff:fe08:a5c6/64 scope link
valid_lft forever preferred_lft forever

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 above example, the DNS servers are displayed above the line * Connection #0 to host 169.254.169.254 left intact.

  • If the DNS server for IPv6 is not displayed, enter the following command:

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

    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

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:~# ip route show default
    default via 10.255.255.1 dev ens192 proto dhcp src 217.160.141.60 metric 100

    IPv6 Gateway

    root@localhost:~# ip -6 route show | grep 'default'
    default via fe80::1 dev ens192 proto ra metric 100 expires 4sec pref high


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

Add IPv4 and IPv6 addresses

  • Check whether there is already a configuration file in this directory. To do this, enter the following command:

    [root@localhost ~]# ls /etc/netplan

Attention!

If the directory contains the file 00-Public_network.yaml, do not rename it, as this file is required for the public network.

  • If there is a configuration file in this directory, rename it. To do this, enter the following command and replace the placeholders.

    [root@localhost ~]# mv OLD_CONFIGURATIONFILE.yaml OLD_CONFIGURATIONFILE.yaml.old

  • Create the file /etc/netplan/01-netcfg.yaml with the vi editor. To do this, enter the following command:

    [root@localhost ~]# vi /etc/netplan/01-netcfg.yaml

Notes
  • 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 exit vi and save the file, enter the command :wq and then press Enter.

  • Insert the following information:

    network:
    version: 2
    renderer: networkd
    ethernets:
    NETWORKINTERFACE:
    addresses:
    - MAIN IPv4 ADDRESS/32
    - ADDITIONAL IPv4 ADDRESS_1/32
    - MAIN IPv6 ADDRESS/64
    - ADDITIONAL IPv6 ADDRESS_1/64 
    gateway4: GATEWAY FOR IPv4
    nameservers:
    addresses:
    - IP ADDRESS OF NAMESERVER_1
    - IP ADDRESS OF NAMESERVER_2 
    routes:
    - to: default
    via: GATEWAY FOR IPv4
    - to: default
    via: GATEWAY FOR IPv6

    Example:

    network:
    version: 2
    renderer: networkd
    ethernets:
    ens192:
    addresses:
    - 85.215.105.86/32
    - 85.215.109.181/32
    - 2a01:239:0:805d::1/64
    - 2a01:239:0:805d::2/64
    gateway4: 10.255.255.1
    nameservers:
    addresses:
    - 212.227.123.16
    - 212.227.123.17
    routes:
    - to: default
    via: 10.255.255.1
    - to: default
    via: fe80::1

  • Replace the NETWORKINTERFACE placeholder with the network interface you identified. In the example above, this is the network interface ens192. Then enter the main IPv4 address, the additional IPv4 addresses and the main IPv6 address and the additional IPv6 addresses. To do this, replace the placeholders.

Attention
  • The indentations are part of the syntax of the YAML format. Therefore, make sure that these are adhered to correctly. Otherwise, the configuration cannot be applied correctly and the server may no longer be accessible.

  • Always use the space bar for the indentations.

  • Replace the placeholder GATEWAY FOR IPv4 with the determined IPv4 gateway.

  • Replace the placeholders IP ADDRESS FROM NAMESERVER 1 and IP ADDRESS FROM NAMESERVER 2 with the name servers you identified.

  • Replace the placeholder GATEWAY FOR IPv6 with the IPv6 gateway you identified.

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

  • To change the permissions of the 01-netcfg.yaml file so the file can only be read and changed by the root account, enter the following command:

    root@localhost:~# sudo chmod 600 /etc/netplan/01-netcfg.yaml

  • To check the configuration file, enter the following command:

    root@localhost:~# netplan --debug apply

Attention

The changes you have made in the file /etc/netplan/01-netcfg.yaml will remain and have to be changed by you if they are not correct. Otherwise the operating system will attempt to load them after a restart.

Note

If, for example, an error message similar to the one below is displayed after entering the netplan --debug apply command, this indicates that there is a problem with the indentation in the /etc/netplan/01-netcfg.yaml file:

root@localhost:# netplan --debug apply
** (generate:1617): DEBUG: 16:52:11.664: starting new processing pass
/etc/netplan/01-netcfg.yaml:2:10: Invalid YAML: mapping values are not allowed in this context:
version: 2

In this case, correct the indentation and try again.

  • To avoid conflicts, it is necessary that you uninstall ifupdown. To uninstall ifupdown and all other dependent packages and delete the configuration and/or data files of ifupdown, enter the following command:

    root@localhost:~# sudo apt-get autoremove --purge ifupdown

  • Restart the server to apply the changes. To do this, enter the following command:

    root@localhost:~# systemctl reboot

  • To check whether the additional IPv4 address has been configured correctly, enter the following command:

    root@localhost:~# ip addr

Note

If the server is no longer accessible due to a configuration error, you can correct the configuration using the KVM console. You can find instructions on how to use the KVM console in the following article:

Using the KVM console for server access (Cloud Server and Virtual Server Cloud)