Adding public IPv4 and IPv6 addresses to a VPS, migrated Cloud Server, or VPS+ (Ubuntu 20.04, 22.04, 24.04, and Debian 12 with Netplan)
Please use the “Print” function at the bottom of the page to create a PDF.
Valid for Linux VPS, migrated Cloud Servers, and VPS+ running Ubuntu 22.04, Ubuntu 24.04, Debian 12, or Debian 13, managed in the Cloud Panel.
This article explains how to add additional public IPv4 and IPv6 addresses to a VPS, a migrated Cloud Server, or a VPS+ running Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04, Debian 12, or Debian 13.
In current IONOS images for Ubuntu 22.04, Ubuntu 24.04, Debian 12, and Debian 13, network configuration is handled via Netplan. Consequently, network configuration is no longer controlled via the /etc/network/interfaces file, as was the case in older distributions, but rather through files with the .yaml extension located in the /etc/netplan directory. If multiple files are present in this directory, they are loaded in lexical order.
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
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 100IPv6 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/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 OLD_CONFIGURATION_FILE.yaml OLD_CONFIGURATION_FILE.yaml.old
Example:
[root@localhost ~]# mv 50-cloud-init.yaml 50-cloud-init.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
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: 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
- 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: 2Replace 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.
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.
Additional information
Further information about Netplan can be found here:
https://manpages.ubuntu.com/manpages/bionic/man5/systemd.network.5.html