Netplan configuration to disable DHCP is overwritten

Ubuntu Version:
24.04.3 server

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:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp2s0:
      dhcp4: false
      dhcp6: false
      addresses: [192.168.178.2/24]
      routes: 
        - to: default
          via: 192.168.178.1  
      nameservers:
        addresses: [192.168.178.1, 1.1.1.1, 8.8.8.8] 

After netplan apply I get this from netplan get:

Network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp2s0:
      critical: true
      addresses:
      - "192.168.178.2/24"
      nameservers:
        addresses:
        - 192.168.178.1
        - 1.1.1.1
        - 8.8.8.8
      dhcp-identifier: "mac"
      dhcp4: true
      dhcp6: false
      routes:
      - to: "default"
        via: "192.168.178.1"

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 found some related questions on AskUbuntu, e.g. Netplan config file not disabling dhcp, but these do not help.

There are no other files in /etc/netplan/ and no subdirectories.
netplan --debug does not show any hints.

Any ideas how to solve or analyze the issue?

Thanks a lot!

1 Like

Your system is listed as 24.04.3 server, so I think your renderer should be networkd

1 Like

Hi dsmythies,

thanks for your answer.

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.

Very sad!

Best regards!

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

and:

root@s19:/etc/netplan# netplan get
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
  bridges:
    br0:
      addresses:
      - "192.168.111.136/24"
      nameservers:
        addresses:
        - 192.168.111.1
      dhcp4: false
      dhcp6: false
      macaddress: "3c:7c:3f:0d:99:83"
      interfaces:
      - enp3s0
      parameters:
        forward-delay: "4"
        stp: true
      routes:
      - to: "default"
        via: "192.168.111.1"
      link-local: []

Hi dsmythies,

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?

Best regards!

There is already a bug: DHCPv4 client launched even when explicitly disabled

Any other ideas how to analyze it?

Best regards!

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.

THANKS A LOT and have a wonderful day!

This topic was automatically closed after 30 days. New replies are no longer allowed.