• Help & contact

    For Linux VPS and migrated Cloud Servers with Ubuntu 20.04, 22.04, or Debian 12 with Netplan, which are managed in the Cloud Panel

    This article explains how to add additional public IPv4 addresses to a VPS or a migrated Cloud Server with Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04, or Debian 12 installed.

    The network configuration is carried out in the current images of IONOS for Ubuntu 20.04, 22.04, 24.04 and Debian 12 via Netplan. The network configuration is therefore no longer controlled via the /etc/network/interfaces file as in older distributions, 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.

    Please Note

    How to configure an additional public IPv4 address in Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04, or Debian 12:

    Requirements
    • You have assigned an additional public IPv4 address to your server in the Cloud Panel.

    • You have logged in to the server.

    • You have noted the IPv4 addresses of the server.

    Note

    Instructions on how to establish an encrypted connection to your server are listed in the following articles:

    Establishing an SSH connection to your Linux server on a computer with Microsoft Windows

    Establishing an SSH connection to your Linux server on a Linux computer

    Check whether Netplan is used for the network configuration

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

    • 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 /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 public IPv4 and IPv6 addresses to a Linux server (Ubuntu and Debian)

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

    root@ubuntu:/etc/netplan# 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: ens6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 02:01:e4:95:f5:d9 brd ff:ff:ff:ff:ff:ff:ff
    inet 195.20.234.94/32 scope global dynamic ens6
    valid_lft 463sec preferred_lft 463sec
    inet6 fe80::1:e4ff:fe95:f5d9/64 scope link
    valid_lft forever preferred_lft forever

    Show default DNS server

    To display the DNS servers used, enter the following command:

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

    The DNS servers used 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

    Make a note of the DNS servers.

    Display gateway for IPv4 and IPv6

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

      IPv4:

      root@ubuntu:~# ip route show | grep 'default'

      IPv6:

      root@ubuntu:~# ip -6 route show | grep 'default'

    • Note the IP addresses of the gateways. These are listed directly after the default via part. Example:

      IPv4 gateway

      root@ubuntu:~# ip route show | grep 'default'
      default via 195.20.234.1 dev ens6 proto dhcp src 195.20.234.94 metric 100

      IPv6 Gateway

      root@ubuntu:~# 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 commands:

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

    • 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_CONFIGURATION_FILE.yaml OLD_CONFIGURATION_FILE.yaml.old

      Example:

      [root@localhost ~]# mv 50-cloud-init.yaml 50-cloud-init.yaml.old

    Please Note

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

    • 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

    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

    • Insert the following information:

      network:
        version: 2
        renderer: networkd
        ethernets:
          NETWORK_INTERFACE:
            addresses:
              - MAIN IPv4 ADDRESS/32
              - ADDITIONAL IPv4 ADDRESS/32
              - MAIN IPv6 ADDRESS/64
              - ADDITIONAL IPv6 ADDRESS/64
            nameservers:
              addresses:
                - IP ADDRESS OF NAMESERVER 1
                - IP ADDRESS OF NAMESERVER 2
            routes:
              - on-link: true
                to: default
                via: STANDARD GATEWAY OF THE ACTIVE INTERFACE
        version: 2

      Example:

      network:
        version: 2
        renderer: networkd
        ethernets:
          ens6:
            addresses:
              - 195.20.234.94/32
              - 195.20.234.86/32
              - 2a02:247a:21f:9c00::1/64
              - 2a02:247a:21f:9c00::2/64
            nameservers:
              addresses:
                - 212.227.123.16
                - 212.227.123.17
            routes:
              - on-link: true
                to: default
                via: 195.20.234.1
        version: 2

    • Replace the NETWORK_INTERFACE placeholder with the determined network interface. In this example, this is the network interface ens6.

    • Then enter the main IPv4 address and the additional IPv4 address. To do this, replace the placeholders.

    • Enter the main IPv6 address and the additional IPv6 address. To do this, replace the placeholders.

    Please Note
    • 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 placeholders IP ADDRESS OF NAME SERVER 1 and IP ADDRESS OF NAME SERVER 2 with the determined name servers.

    • Replace the placeholder STANDARD GATEWAY OF ACTIVE INTERFACE with the determined IPv4 gateway.

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

    • To change the permissions of the new configuration file so that the file can only be read and changed by the root account, adapt the following command and then enter it:

      root@localhost:~# sudo chmod 600 /etc/netplan/CONFIGURATION_FILE.yaml

      Example:

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

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

      root@localhost:~# netplan --debug apply

    Please Note

    The changes you have made in the configuration file remain and must be changed by you if they are not correct. Otherwise, the operating system will attempt to load them after a restart.

    • Restart the server so that the changes are applied. 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 login to the server using the remote console and correct the configuration.