Adding public IPv4 and IPv6 addresses to a VPS, VPS+, or a migrated Cloud Server (Debian 12 and 13)
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 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 Debian 12 or Debian 13. This is required if you want to assign two IPv4 addresses and at least one IPv6 address to the server. If only one IPv4 address and one or two IPv6 addresses are assigned to your server, these IP addresses are configured automatically in the operating system.
In the current IONOS images for Debian 12 and Debian 13, network configuration is handled using Netplan. As a result, the network configuration is no longer managed through the file /etc/network/interfaces as in older distributions, but through files with the .yaml file extension located in the /etc/netplan directory. If multiple files are present in this directory, they are loaded in lexical order.
Please Note
With older Debian 12 images, it may be necessary to configure the network using the /etc/network/interfaces file. Instructions can be found in the following article: Adding public IPv4 and IPv6 addresses to a Cloud Server (Debian 12)
Requirements
- You have assigned one or more additional public IPv4 addresses and, if applicable, one or more IPv6 addresses to your server in the Cloud Server.
- You have logged in to the server.
- You have made a note of the server’s IPv4 and IPv6 addresses.
Note
You can find instructions on how to establish an encrypted network connection to your server using your computer in the following articles:
Setting up an SSH connection to your Linux server from a Microsoft Windows computer
Setting up an SSH connection to your Linux server from a Linux computer
Check whether Netplan is being used for network configuration
This step is only required for Debian 12.
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; instead, follow the steps described in the following article: Adding public IPv4 and IPv6 addresses to a Cloud Server (Ubuntu 18.04 and 20.04, and Debian 10, 11, and 12)
Detect network interface
Find out the 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@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: 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
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
Make a note of the name of the interface configured for your primary IPv4 address.
Display default DNS servers
To view the DNS servers being used, enter the following command:
[root@localhost ~]# resolvectl --no-pager | grep Server
The DNS servers in use will then be 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 and IPv6
To display the default gateway of the active interface, enter the following command:
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 immediately after the ‘default via’ section. Example:
IPv4 gateway
ip route show | grep 'default'
default via 195.20.234.1 dev ens6 proto dhcp src 195.20.234.94 metric 100IPv6 gateway
[root@localhost ~]# ip -6 route show | grep 'default'
default via fe80::1 dev ens6 proto ra metric 100 expires 4sec pref highIn this example, fe80::1 is the IPv6 gateway.
Add IPv4 and IPv6 addresses
Change to the /etc/netplan directory and identify the name of the configuration file.
[root@localhost ~]# cd /etc/netplan
[root@localhost ~]# ls /etc/netplanIf the file 00-Public_network.yaml is present in this directory, do not rename it, as this file is required for the public network. If there is a configuration file with a different filename 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 using 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 enter insert mode by pressing the [i] key. In this mode, the characters you type are inserted into the text immediately. To switch to command mode, press [ESC] afterwards. When you are in command mode, your keystrokes are interpreted as commands.
Please Note
Indentation is part of the YAML format’s syntax. Therefore, please ensure that it is used correctly. Otherwise, the configuration may not be applied correctly and the server may no longer be accessible. Always use the space bar for indentation.
Insert the following information:
network:
version: 2
renderer: networkd
ethernets:
NETWORK_INTERFACE:
addresses:
- PRIMARY_IPV4_ADDRESS/32
- ADDITIONAL_IPV4_ADDRESS/32
- PRIMARY_IPV6_ADDRESS/64
- ADDITIONAL_IPV6_ADDRESS_1/64
nameservers:
addresses:
- IP_ADDRESS_OF_NAMESERVER_1
- IP_ADDRESS_OF_NAMESERVER_2
routes:
- on-link: true
to: default
via: DEFAULT_GATEWAY_OF_THE_ACTIVE_INTERFACEExample:
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- Replace the placeholder NETWORK_INTERFACE with the network interface you have identified. In this example, this is the network interface ens6.
- Next, enter the primary IPv4 address and the secondary IPv4 address. To do this, replace the placeholders.
- Enter the primary IPv6 address and the secondary IPv6 address. Replace the placeholders accordingly.
- Replace the IP_ADDRESS_OF_NAMESERVER_1 and IP_ADDRESS_OF_NAMESERVER_2 placeholders with the DNS servers you identified.
- Replace the DEFAULT_GATEWAY_OF_THE_ACTIVE_INTERFACE placeholder with the IPv4 gateway you identified.
- To exit vi and save the file, enter the command :wq and then press the Enter key.
To change the permissions of the new configuration file so that it can only be read and modified 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
Any changes you make to the configuration file will be retained and must be amended by you if they are incorrect. Otherwise, the operating system will attempt to load them after a restart.
Restart the server so that the changes take effect. 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 via the remote console and correct the configuration. For further information, please refer to the following article: Using the remote console to access the server
Additional information
Further information on Netplan can be found in the following articles: