11

In some tutorials (Here and Here) about netplan dhcp4 appear in the following way:

network:
 version: 2
 renderer: networkd
 ethernets:
   enp2s0:
    dhcp4: no

or

    dhcp4: yes

But in netplan examples and blog ubuntu sometimes appear in the following way:

    dhcp4: true

or

    dhcp4: false

And in other examples it appears as not/yes

What is the correct way to set dhcp in Ubuntu 18.04 (yes/no or true/false)? Thanks

3 Answers 3

14

Netplan configuration syntax is YAML, and the dhcp4 setting takes a boolean value.

According to http://yaml.org/type/bool.html the acceptable values are y/n, yes/no, true/false and on/off, written either with all lowercase, with an Initial Capital, or with ALL CAPS.

So all of the ways you listed are correct.

The canonical ("the most correct" if a distinction must be made) form would be lower-case y/n.

However, the definition says:

A Boolean represents a true/false value. Booleans are formatted as English words (“true”/“false”, “yes”/“no” or “on”/“off”) for readability and may be abbreviated as a single character “y”/“n��� or “Y”/“N”.

So you can use any of those forms, whichever you find easiest to read.

1
  • Thank you for this reference. I was confused while reading over the documentation examples on netplan.io -- they should simply pick a convention to avoid unnecessary confusion among those not familiar with YAML (yet).
    – bjd2385
    Commented Mar 27, 2019 at 5:49
1

In newer versions of netplan it seems no as value for a config parameter is NOT working anymore.

Even worse, it seems to imply true.

So i recommend replacing it with false, which at least solved my case.

1

I had this same question when I had two servers both running Ubuntu 22.04.2 and one of them was not getting a DHCP IPv6 address.

On comparing both the configs, the server that was working had

dhcp6: yes

and the server that was not working had

dhcp6: true

after changing to yes, and running netplan apply Voilà! I had an IPv6 address. When it was true I would have to run dhclient -6 <iface> to get the v6 address manually, so I knew netplan was simply not executing the dhclient call.

Based on telcoM's answer if y/n is the most correct representation, they seem to have switched it to only accepting y/n|yes/no. After reading sascha.arthur's answer which advised to change to false, as no didn't work for them made this even more confusing.

I recommend trying both scenarios. I'm currently at netplan 0.105 (check with apt list --installed | grep netplan).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .