For Cloud Server and Virtual Private Server

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

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

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)

How to configure IPv4 addresses and IPv6 addresses on a Virtual Private Server or Cloud Server running Ubuntu 18.04, Ubuntu 20.04, Debian 10, 11, or Debian 12 is described in the following article:

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:

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

  • You are logged into the server.

  • You have taken note of the IPv4 addresses and IPv6 addresses of the server.

Checking if Netplan Is Used for Network Configuration

To check if your server already uses 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 already installed, you will see information such as the following:

    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 directory /etc/netplan.

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

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

    [root@localhost ~]# ls

Please 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)

Determining the Network Interface

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

Showing the Default DNS Servers

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

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

    IPv6 gatewayroot@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.

Adding IPv4 and IPv6 Addresses

  • Check if there is not 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 since this file is needed 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_CONFIG_FILE.yaml OLD_CONFIG_FILE.yaml.old

  • Create the file /etc/netplan/01-netcfg.yaml with the editor vi. 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 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 command mode, your keyboard input is interpreted as a command.

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

  • Include 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 FOR NAMESERVER_1
              - IP-ADDRESS FOR 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 placeholder NETWORKINTERFACE with the determined network interface. In the example above, the network interface is ens192. Then enter the main IPv4 address, the additional IPv4 addresses and and the main IPv6 address and the additional IPv6 addresses. Replace the placeholders shown above in caps.

Attention
  • The indentations belong to syntax of YAML format. Therefore, make sure that they are observed 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 OF NAME SERVER 1 and IP ADDRESS OF NAME SERVER 2 with the determined name servers.

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

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

  • To change the permissions of the 01-netcfg.yaml file so only the root account can read and modify the file, type 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 /etc/netplan/01-netcfg.yaml file remain and must be changed by you if they are not correct. Otherwise, the operating system will try to load them after a reboot.

Please Note

If for example, an error message similar to the one below, is shown after entering the netplan --debug apply command, it 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 to 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

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

    root@localhost:~# systemctl reboot

  • To verify that the additional IPv4 address is configured correctly, enter the following command:

    root@localhost:~# ip addr

Please Note

If the server becomes unreachable due to a configuration error, you can use the KVM console to correct the configuration. For instructions on how to use the KVM console, see the following article:

Using KVM Console for Server Access (Cloud Server and Virtual Server Cloud)

Additional Information

You can find more information about netplan in the following articles:

http://manpages.ubuntu.com/manpages/bionic/man5/systemd.network.5.html

https://netplan.io/examples/