Adding a public IPv4 addresses to a VPS or a migrated Cloud Server (Ubuntu 24.04, 22.04, 20.04, and Debian 12 with Netplan)
Please use the “Print” function at the bottom of the page to create a PDF.
For Linux VPS and migrated Cloud Servers with Ubuntu 24.04, 22.04, 20.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 24.04, Ubuntu 22.04, Ubuntu 20.04, or Debian 12 installed.
The network configuration is carried out in the current images of IONOS for Ubuntu 24.04, 22.04, 20.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
If you have installed one of the following distributions before migrating your Cloud Server, you must configure the network using the /etc/network/interfaces file:
Ubuntu 18.04, Debian 10, 11, and Debian 12
How to configure an additional, public IPv4 or IPv6 address in Debian 11 without Netplan is described in the following article:
Adding public IPv4 and IPv6 addresses on a cloud server (Debian 11)If you are using Ubuntu 22.04 or Ubuntu 20.04 and these distributions were installed before Cloud Server was migrated, you must check whether Netplan is being used. To do this, change to the /etc/netplan directory and check whether there is a configuration file in this directory. To do this, enter the following commands:
[root@localhost ~]# cd /etc/netplan
[root@localhost ~]# lsIf the /etc/netplan directory does not exist, netplan has not been installed. In this case, do not install Netplan, but configure the network using the /etc/network/interfaces file. How to do this is described in the following article:
Adding public IPv4 and IPv6 addresses on a Cloud Server (Ubuntu 20.04, Ubuntu 18.04, Debian 10, 11, and Debian 12 without Netplan)How to add IPv4 addresses and IPv6 addresses on a Cloud Server is described in the following article:
Adding public IPv4 and IPv6 addresses on a Linux server (Ubuntu 22.04 and 20.04)
How to configure an additional public IPv4 address in Ubuntu 24.04, Ubuntu 22.04, Ubuntu 20.04, Debian 11, 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 with your computer 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 command:
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 on 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.
Show gateway for IPv4
To display the default gateway of the active interface, enter the following command:
[root@localhost ~]# ip route show | grep 'default'
Make a note of 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
Add IPv4 address
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/netplanIf there is a configuration file in this directory, rename it. To do this, enter the following command and replace the placeholders.
root@localhost ~]# mv CONFIGURATION_FILE.yaml 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:
NETWORKINTERFACE:
addresses:
- MAIN IPv4 ADDRESS/32
- ADDITIONAL IPv4 ADDRESS/32
- MAIN 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: 2Example:
network:
version: 2
renderer: networkd
ethernets:
ens6:
addresses:
- 195.20.234.94/32
- 195.20.234.86/32
- 2a02:247a:21f:9c00::1/64
nameservers:
addresses:
- 212.227.123.16
- 212.227.123.17
routes:
- on-link: true
to: default
via: 195.20.234.1
version: 2Replace the NETWORKINTERFACE 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.
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/50-cloud-init.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 log in to the server using the remote console and correct the configuration.
Further information
Further information about netplan can be found here:
http://manpages.ubuntu.com/manpages/bionic/man5/systemd.network.5.html
How to add IPv4 addresses and IPv6 addresses to a dedicated server is described in the following articles:
Adding a public IPv4 address on a dedicated server (Ubuntu 20.04)
Adding a public IPv4 address on a dedicated server (Ubuntu 18.04 and Debian 9)
Adding a public IPv4 address on a dedicated server (Debian 10)
Adding a public IPv6 address on a dedicated server (Ubuntu 18.04 and Debian 9)
Adding a public IPv6 address on a dedicated server (Debian 10)