Skip links

How to Configure an Additional IPv4 on a Debian/Ubuntu Cloudpap VM Using Netplan

View Categories

How to Configure an Additional IPv4 on a Debian/Ubuntu Cloudpap VM Using Netplan

2 min read

Table of Contents

Introduction #

In the dynamic world of cloud computing, the need for additional IP addresses on your virtual machine (VM) can arise for various reasons. Whether you want to host multiple websites or improve network segmentation, this article will guide you through the process of configuring an extra IP address on a Debian/Ubuntu Cloudpap VM using Netplan, a modern network configuration tool.

Prerequisites #

Before you start, ensure you have the following:

  1. A Cloudpap VM running Debian or Ubuntu.
  2. SSH access to your VM. We’ll assume you have root access and your VM IP is 10.10.245.3
  3. An additional IP address. We’ll use 10.10.245.5 as our IP in this case

Let’s get started:

  1. Login to your server via SSH

Begin by establishing an SSH connection to your VM. Use a terminal application on your local computer to log in. Replace 10.10.245.3 with your VM’s actual IP address and root with your SSH username.

ssh [email protected]

You will be prompted to enter your password or provide your SSH key for authentication.

  1. Add an extra IP address using Netplan

Netplan is the modern way to manage network configuration in Debian/Ubuntu-based systems. To add an additional IP address, we’ll modify the Netplan configuration. Create a new Netplan configuration file with your additional IP using your preferred text editor. In this example, we’ll use vim:

sudo vim /etc/netplan/50-cloud-init.yaml

Inside the configuration file, add the following lines, ensuring the indentation is correct:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      addresses:
        - 10.212.245.3/32
      dhcp4: false
      match:
        macaddress: 02:00:00:xx:xx:xx
      routes:
        - to: default
          via: 10.212.245.1
          metric: 100
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      additional_addresses:
        - 102.212.245.5/32

additional_addresses is where you specify the additional IP address, such as 102.212.245.5, and its subnet mask /32 for a single IP address.

Save your changes and exit the text editor.

Apply the Netplan configuration by running:

sudo netplan apply

  1. Test the additional IP

Before using the new IP, verify its functionality by pinging it from an external network or performing other tests.

On your VM, open a terminal and execute the following command:

ping 102.212.245.5

Successful output should be as below

root@vm-xo:# ping -c 4 102.212.246.88
PING 102.212.246.88 (102.212.246.88) 56(84) bytes of data.
64 bytes from 102.212.246.88: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from 102.212.246.88: icmp_seq=2 ttl=64 time=0.056 ms
64 bytes from 102.212.246.88: icmp_seq=3 ttl=64 time=0.069 ms
64 bytes from 102.212.246.88: icmp_seq=4 ttl=64 time=0.031 ms

--- 102.212.246.88 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3058ms
rtt min/avg/max/mdev = 0.018/0.043/0.069/0.020 ms