A quick note on DHCP client identifiers in pfsense static leases

This has been driving me squirrely and I wanted to post a brain dump somewhere while my memory is fresh in case it helps others (or future me).

DHCP client identifiers (option 61) can be used as an alternative to static DHCP leases being assigned based on MAC addresses. My use case for this is that I dualboot my desktop and want different IP addresses to be handed out depending on which OS I’m using. You can set a static IP on one or more OS, but I’d like to use DHCP for both hosts. MAC spoofing on one or both hosts is an alternative for consideration, but I digress.

The DHCP client identifier is specified in RFC2132 Section 9.14. The “Type” is 0x00 if your client ID is free form text. Alternatively, the client ID can be your MAC address, and in this case the “Type” number should correspond to the RFC1700 Hardware Type Number. For ethernet, the Type is 0x01.

The default in Windows 10 is to use Type 0x01 and your MAC address. One of my dual boot OS’ is Windows 10, so that’s a convenient default that signals both my NIC and my OS at once. If you’re using Windows 10 and want to change it, look at this post for a starting point.

In GNU/Linux this is set by your DHCP client and varies. However, the documentation on how to set/change it tends to be better once you figure out what your DHCP client is. I haven’t properly tested this, but I think for NetworkManager (default DHCP client on Debian 12 with gnome DE), you create a .conf file in /etc/NetworkManager/conf.d and include the following:

[connection]
ipv4.dhcp-client-id=yourclientid

Now, to use a DHCP client ID for static DHCP leases in pfsense, go to Services → DHCP Server and specify a static DHCP lease like normal. I didn’t fill in the MAC address field, or check if MAC addresses and client IDs can be used at the same time for the same static DHCP lease. The formatting of the client ID is really odd though.

First, enter your “Type” value as either octal (\000 for Type 0 in Dec) or hex (\x01 for Type 1 in Dec). You need to provide pfsense both your type and client id in the “Client Id” field. Then you either:

  • Enter the client ID text that the DHCP client outputs (for free form text, like a FQDN or hostname), as-is. Source: issue 6362
  • For a MAC address (the windows 10 default), instead enter it as a series of escaped hex bytes in lowercase: 2C:54:91:88:C9:E3 becomes \x2c\x54\x91\x88\xc9\xe3

If you do that, then pfsense should use your client ID to hand out a static IP and you should be happy. If that’s not working, confirm that your DHCP client is actually sending the client ID that you think it is. Two options:

  • In pfsense, go to Diagnostics → Command Prompt and run cat /var/dhcpd/var/db/dhcpd.leases. The client id (including the type byte) used to establish each DHCP lease is listed as uid in this file. If you can find the client you’re trying to assign a static lease to via the MAC address or the IP that pfsense handed out, then you can see the uid that it provided at the time of the DHCP lease assignment.
  • a packet capture (e.g. I used wireshark on the windows 10 PC I was debugging). In wireshark, the packet is DHCP protocol, the Info says “DHCP Discover…” and if you expand “Dynamic Host Configuration Protocol (Discover)” in the packet content, “Option: (61) Client Identifier” will tell you the type and client ID used.

You may be able to save some headache by following this process to create a new DHCP client id static lease:

  1. Set up the type and client ID on your client device before messing with PFSense. Reboot or otherwise trigger a DHCP renewal once you think your client is sending your desired client ID and type. Confirm that pfsense issued you a DHCP lease (ignore the IP for now).
  2. In pfsense, cat /var/dhcpd/var/db/dhcpd.leases as detailed above, and find the uid that pfsense received. If it matches expectations, copy it. If not, return to step 1.
  3. Create your DHCP static lease in pfsense as detailed above, and paste in the uid you copied as the client ID. No hex or octal conversion needed.
1 Like