How to set DHCP user-class opt 77 for a container or VM?


Been able to validate the ISC DHCP configuration by using:
dhclient eth0
in a container, but during boot the instance it gets incorrect options due to the dhcpd-eval process not getting the user-class option.

I’ve set this via cloud-init in:
{LXDprofile} > config > user-data > write_files ... > /etc/dhcp/dhclient.conf
but I suspect that this method is deprecated and not hitting any Google results.

Any ideas how this can be done with LXD containers and VMs via a profile/cloud-init? Would it have to do with networkd/netplan & UserClass=?


With some more testing…

DHClient works fine but seems deprecated and isn’t being used by Ubuntu.

Netplan doesn’t seem to support DHCP sending user/vendor classes unless I am missing something. Hope I am and someone can enlighten me:

Networkd does seem to work but I think Netplan gets in the way.

Removed Netplan (not ideal)
apt remove

Created /etc/systemd/network/




Enabled networkd:
systemctl enable systemd-networkd.service
systemctl start systemd-networkd.service

In the following ISC KB article, I see there are a couple of matches to watch out for, so I tested using their “foobar” example:
The if statement is being executed because it’s detecting the “user-class” option being sent by networkd and running the debug directive and I’m getting this in the log:
dhcpd[6609]: #006foobar
however I cannot get the if statement to match what the value of the debug output is with any of these because I don’t understand this format coming from the debug:

if ( exists user-class ) and (option user-class = "foobar" 
or option user-class = "\x06foobar"
or option user-class = "\#006foobar"
or option user-class = "006foobar"
) ); { log (debug, option user-class); ..... }

The desired outcome here is to use the user-class to determine what DHCP options are passed to the container/VM. The user-class is pushed to the container/VM via a {LXDprofile} > config > cloud-config or some other way.

Netplan bug raised:

In the interim, using fqdn options with dhcpd-eval which seem to be working.

LXD Profile for Development instances

  user.user-data: |
      - hostnamectl set-hostname "$(hostname -s)"
      - netplan apply

ISC dhcpd-eval

  if exists fqdn.domainname and (
    option fqdn.domainname = "") { ...

Perhaps there is a better way to get LXD / cloud-init to set the domain part of the instance hostname ?


1 Like