Problem Description:
I want to switch from DHCP to static IP for the server’s ethernet nic. For that, I followed several guides and modified the /etc/netplan/50-cloud-init.yaml like this:
Most of the settings are taken into account, but dhcp4 is somehow set to true again.
I tried with networkd renderer, but same result.
Also a netplan generate and reboot does not change it.
I first tried with networkd renderer, switched to NetworkManager just to leave no stone unturned.
Now I switched backed and gave it another with networkd but no change.
I see that you mentioned that in your original post. Sorry for the noise.
The only thing I can think of as potentially different between our 24.04.3 servers is the cloud-init stuff. I have it disabled, but my notes on this are vague. I have the file /etc/cloud/cloud-init.disabled.
Normally I use dhcp, but always allocate the same IP address via MAC from my DHCP server. Anyway, I tried static, and it worked as expected:
root@s19:/etc/netplan# cat 50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot.
# Doug: Huh???
#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
renderer: networkd
ethernets:
enp3s0:
dhcp4: no
bridges:
br0:
macaddress: 3c:7c:3f:0d:99:83
interfaces: [ enp3s0 ]
# dhcp4: yes
dhcp4: no
addresses: [192.168.111.136/24]
# gateway4: 192.168.111.1
routes:
- to: default
via: 192.168.111.1
nameservers:
addresses: [192.168.111.1]
dhcp6: no
link-local: [ ]
parameters:
stp: true
forward-delay: 4
thanks for your efforts to test and verify the correct behavior on your system!
I tried again on my, but still no success.
I tried to analyze where this could come from by strace-ing the netplan apply command. The only culprit I saw was /run/netplan/enp2s0.yaml which contained a dhcp4: true. Out of sheer desperation I patched this file to look similar to my /etc/netplan/50-cloud-init.yaml and voilà - after netplan apply there was no dhcp anymore. But only until the next boot. After that, all was like before.
I am thinking about giving up and using DHCP with a fixed IP from my router/dhcp-server.
Do you think it is worth to open a bug for Netplan?
That you have the file /run/netplan/enp2s0.yaml is both interesting and probably a good clue.
I have no such file and no /run/netplan directory at all. Does the information in this Q&A provide any insight?
That’s very interesting! Early boot SSH to unlock crypted drives is exactly what I use. I would never have thought of that being related to the Netplan static % DHCP problem. Thanks a lot for this catch!
Problem is not solved with that, but at least understood a little better.
For now I will stay with the fixed IP from DHCP server solution and not invest more into this.