brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Stop cloud-init from overwriting your netplan file with one small config

Netplan
~/tips/tip-netplan-stop-cloud-init-rewrite

echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

Hand network settings back to you on images where cloud-init manages them.

On many Ubuntu server images, /etc/netplan/50-cloud-init.yaml is written by cloud-init. Edit it by hand and your change can disappear later.

I switch off the network part of cloud-init with a file of its own:

echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

From then on cloud-init leaves the network alone, while the rest of it keeps working. Now copy the generated file to a name that is yours and edit that one:

sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/60-local.yaml
sudo rm /etc/netplan/50-cloud-init.yaml
sudo chmod 600 /etc/netplan/60-local.yaml
sudo netplan generate

Removing the old file avoids two files describing the same interface, which gets confusing fast. Check with generate that the YAML still parses before you reboot.

Careful on a cloud VM: some providers change network details through cloud-init, for instance when you add a second address or resize the machine. With it disabled, that stops happening and you have to edit the file yourself. Keep a serial or web console at hand, since a mistake here can cut your only way in.

Further reading: cloud-init network configuration

More Netplan tips – to: 192.168.3.0/24 hidden: true lacp-rate: fast link-local: [] wakeonlan: true All Netplan tips (21) All topics

Link