Using Cloudinit and Netplan with IP’s on a different Network and Gateway

If you ever had to use a hosting provider where you could purchase Additional IP’s or failover IP’s, you would have noticed that sometimes the IP’s used the same gateway as your original IP’s.

  • OVH
  • SoYouStart

The problem is when you use Cloudinit to deploy your VM’s on Ubuntu which uses netplan and unfortunately there isn’t a method to configure netplan through Cloudinit.

I’m using Proxmox and although you can create a custom network configuration for netplan.yml and deploy it as a snippet via cloudinit. This isn’t idea.

Canoical looks to have fixed the bug this year (2023) in January https://github.com/canonical/cloud-init/pull/1931a

However, that most likely relates to the new Ubuntu LTS. I’ve tested this within Ubuntu 20.04 and the appropriate config is in place. Here’s the generated /etc/netplan/50-cloud-init.yaml

[email protected]:~# cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 147.135.0.0/24
            match:
                macaddress: 02:00:00:79:e4:73
            nameservers:
                addresses:
                - 213.186.33.99
                search:
                - plantsbymail.com
            routes:
            -   on-link: true
                to: default
                via: 15.0.0.254
            set-name: eth0
        eth1:
            dhcp4: true
            match:
                macaddress: 8a:ca:d3:4d:c9:28
            set-name: eth1
    Reddit – Dive into anything
    www.reddit.com
    BUG: No routing in VM with cloud init (ubuntu 18.x – 19.4) | Proxmox Support Forum
    It´s possible a bug in the network setting from proxmox to VMs with cloud-init and ubuntu. I have see many forum entries about the same problemas! The big…
    forum.proxmox.com

    https://linuxconfig.org/how-to-add-static-route-with-netplan-on-ubuntu-22-04-jammy-jellyfish-linux