When you order an extra IPv4 address or add an extra IPv6 address to your IP addresses via the TransIP control panel, these cannot be automatically added to your VPS via DHCP. Additional IP addresses are added manually to the network interfaces.
In this article, we explain how you can statically add an extra IPv4 or IPv6 address to your Ubuntu 22.04 VPS. For this, an extra IPv4 and/or IPv6 address is required (depending on which you'd like to add / configure). Don't have an extra address yet? The following articles explain how you can get one:
- Ordering an extra IPv4 address in the control panel
- Creating an extra IPv6 address in the control panel
Click here for a complete overview of all our tutorials for adding an extra or static IPv4 or IPv6 address to various Linux distros. For adding an IPv4 or IPv6 address to a Windows VPS, see this article.
- This manual is about public IP addresses. In this manual, you will find more information about setting up internal addresses (for your private network).
- A VPS includes 1 IPv4 address by default, but you can expand this to a maximum limit of 20 IPv4 addresses.
- Each VPS has a /64 IPv6 range at its disposal by default, where IP addresses can be added as desired. A /64 IPv6 range contains a total of 18,446,744,073,709,551,616 IP addresses, so the likeliness that you will not have enough is quite small! The default gateway falls outside of the /64 range so as netmask you always use a /48 range.
Adding an IPv4 address in Ubuntu 22.04
Step 1
Connect to the VPS via the VPS console or via SSH.
Step 2
Once logged in you see the current network interfaces and the set IPs by means of the command:
ip a
You will be shown an overview as below.
Step 3
Please note: Did you use our fast installs feature for VPS and chose for installation via SSH-keys, one time password, or cloud-config user data? Then, additional steps are required. Click 'Fast installs proces' below to view these steps.
Fast installs proces
For Fast Installs we make use of Cloud Init. Cloud Init automatically overwrites your netwerk configuration. For this reason Cloud Init or its control over the network (either choice is fine) must be disabled as follows:
Disabling Cloud Init network management
Open/create the following file:
nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Give the file the following contents. Afterwards, save and close your file (ctrl + x > y > enter).
network:
config: disabled
In order to prevent confusion in the future, we recommend renaming Cloud Init's network configuration file to 01-netcfg.yaml. You can do so using the command:
mv /etc/netplan/50-cloud-init.yaml /etc/netplan/01-netcfg.yaml
You may now proceed with the rest of step 3 from this point.
Disabling Cloud Init
Cloud Init is only used for the initial installation of your VPS. It can't hurt as such to disable it altogether. All that's required to disable Cloud Init is the creation of the following file:
touch /etc/cloud/cloud-init.disabled
In order to prevent confusion in the future, we recommend renaming Cloud Init's network configuration file to 01-netcfg.yaml. You can do so using the command:
mv /etc/netplan/50-cloud-init.yaml /etc/netplan/01-netcfg.yaml
You may now proceed with the rest of step 3 from this point.
Should the changes not take affect after completing this tutorial, the following command may be required:
dpkg-reconfigure cloud-init
Now add the extra IPv4 address in the network interfaces. First, open the network configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
A configuration file opens that looks like the screenshot below (nano is slightly modified in the current, newer version).
In the file, adjust the values as follows:
ethernets: ens3: dhcp4: no dhcp6: yes addresses: - 149.210.181.124/24 - 149.210.189.113/24 routes: - to: default via: 149.210.181.1
- Under 'addresses', enter your primary IPv4 address with the range /24 addition (in our example 149.210.181.124/24).
- Enter additional IPv4 addresses on a new line using the same syntax, e.g.: - 149.210.189.113/24
- The IPv4 addresses that you enter under 'Addresses' can be found in your control panel.
- The value behind 'via' is the gateway of your primary IP. Do not enter additional gateways for secondairy IP's
Save the changes and exit nano (ctrl + x> y> enter).
Step 4
To be able to use the new IP address you process the changes using the following command:
sudo netplan apply
Step 5
If you run ip a again you will see the newly added IPv4 address. You can test this IP address by performing a ping test from another computer / IP.
Are you not seeing your new configuration? Check if a file exists called 01-network-manager-all.yaml in /etc/netplan/ using the command:
ls /etc/netplan/
If yes, rename the file using the command:
sudo mv /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all-yaml.backup
Repeat step 4 and 5. You should now see the correct configuration.
Adding an IPv6 address in Ubuntu 20.04
Step 1
Once logged in you see the current network interfaces and the set IPs by means of the command:
ip a
You will be shown an overview as below.
Step 2
Please note: Did you use our fast installs feature for VPS and chose for installation via SSH-keys, one time password, or cloud-config user data? Then, additional steps are required. Click 'Fast installs proces' below to view these steps.
Fast installs proces
For Fast Installs we make use of Cloud Init. Cloud Init automatically overwrites your netwerk configuration. For this reason Cloud Init or its control over the network (either choice is fine) must be disabled as follows:
Disabling Cloud Init network management
Open/create the following file:
nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Give the file the following contents. Afterwards, save and close your file (ctrl + x > y > enter).
network:
config: disabled
In order to prevent confusion in the future, we recommend renaming Cloud Init's network configuration file to 01-netcfg.yaml. You can do so using the command:
mv /etc/netplan/50-cloud-init.yaml /etc/netplan/01-netcfg.yaml
You may now proceed with the rest of step 2.
Disabling Cloud Init
Cloud Init is only used for the initial installation of your VPS. It can't hurt as such to disable it altogether. All that's required to disable Cloud Init is the creation of the following file:
touch /etc/cloud/cloud-init.disabled
In order to prevent confusion in the future, we recommend renaming Cloud Init's network configuration file to 01-netcfg.yaml. You can do so using the command:
mv /etc/netplan/50-cloud-init.yaml /etc/netplan/01-netcfg.yaml
You may now proceed with the rest of step 2.
Should the changes not take affect after completing this tutorial, the following command may be required:
dpkg-reconfigure cloud-init
Now add the extra IPv6 address in the network interfaces. First, open the network configuration file:
sudo nano /etc/netplan/01-netcfg.yaml
A configuration file opens that looks like the screenshot below (nano is slightly modified in the current, newer version).
In the file, adjust the values as follows:
ethernets: ens3: dhcp4: yes dhcp6: no addresses: - 2a01:7c8:aab5:4cd::1/48 - 2a01:7c8:aab5:4cd::2/48 routes: - to: default via: 2a01:7c8:aab5::1
First enter your primary IPv6 address with the range /48 addition (in our example 2a01:7c8:aab5:4cd::1/48). Enter additional IPv4 addresses on a new line using the same syntax, e.g.: - 2a01:7c8:aab5:4cd::1/48
The IPv6 addresses that you enter under 'Addresses' can be found in your control panel. The value behind 'via' is the gateway of your primary IPv6 address.
Save the changes and exit nano (ctrl + x > y > enter).
Step 3
To be able to use the new IP address you process the changes using the following command:
sudo netplan apply
Step 4
If you run ip a again you will see the newly added IPv4 address. You can test this IP address by performing a ping test from another computer / IP.
Are you not seeing your new configuration? Check if a file exists called 01-network-manager-all.yaml in /etc/netplan/ using the command:
ls /etc/netplan/
If yes, rename the file using the command:
sudo mv /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all-yaml.backup
Repeat step 4 and 5. You should now see the correct configuration.
This concludes our tutorial on adding (static) IPv4 and IPv6 addresses to Ubuntu 22.04