5

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

7

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.

  • 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). – bd1251252 Mar 27 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.