Ubuntu container, MAC address, and DHCP

garyd9

Member
Nov 10, 2023
44
3
8
I'm having a bit of a hard time getting an Ubuntu 22.04 container (made from the proxmox provided ubuntu 22.04 template) working properly in regards to DHCP and IP addresses. The container is configured with a single network device and specific MAC address of 1:2:3:4:5:6 (MAC edited for privacy.) I then set IPv4 to DHCP.

On my DHCP server (Windows server 2016), I have a reservation for that specific mac address to IP 192.168.0.11.

When I boot the container, the container is getting an IP address of 192.168.0.128 and reporting it's MAC address to the DHCP server as "9cc62074000100012ce135ac4e7f9cc62074" This looks to me like one of those things used to spoof MAC addresses for privacy. So, in the container, I edit the /etc/dhcp/dhcpclient.conf and add "send dhcp-client-identifier hardware". I shut down the container, delete the DHCP lease, and start it back up. It comes back up again with a .128 ipv4 address and still showing a strange client identifier (not the mac address)

If I run "dhclient -r" followed by "dhclient" in the container (to release and then get a new DHCP address, THEN it reports the correct client identifier (the actual mac address) and gets the proper IP number.

At any time, if I attach to the container and run "ip a", I see the proper MAC address.

(I could, of course, use a static IP, but I have certain monitors that depend on the reserved DHCP lease being active.)

Any help or suggestions?


Edit: See post #4 for more. It seems that "dhcp-client-identifier hardware" is ignored by dhclient.
 
Last edited:
I shut down the container, delete the DHCP lease, and start it back up.
You probably have already done it, but the way the sentence is phrased yo delete the lease on the server, did you delete /var/lib/dhcp/* ?
 
You probably have already done it, but the way the sentence is phrased yo delete the lease on the server, did you delete /var/lib/dhcp/* ?
No, but "dhclient -r" should delete that when it releases. In addition, it still is sending a client identifier that isn't the MAC address (but is different from the previous client identifier) to the DHCP server.
 
The crazy thing is that pve (or lxc?) _seems_ to be initializing the network interface either before the container fs is initialized, or not using the normal mechanisms for the distro. I just tried with dhcp.conf containing an explicit MAC address:

send dhcp-client-identifier 1:0a:0b:0c:0d:0e:0f

When I boot the container, a randomized client identifier is sent to my dhcp server. If I then run "dhclient -r" followed by "dhclient", it then sends the specified client identifier (in this case, 0a:0b:0c:0d:0e:0f)

This means there's no way I can use DHCP reservations with an Ubuntu container!
 
(I'm in serious love with containers... they let me do very fast testing that would be annoying and painful with full VM's)

...and more information:

If I use a debian 12 container, the value in dhcp.conf is respected on the first boot up of the container. (If I don't hardcode the MAC address in the dhcp.conf, the client identifier sent to DHCP is a long string that contains the mac address along with many other characters - but is at least consistent across boots.)

This suggests an issue with the way the network is initialized in the Ubuntu 22.04 template... Perhaps someone from proxmox can chime in and tell me that I'm wrong (and why.)
 
(I'm in serious love with containers... they let me do very fast testing that would be annoying and painful with full VM's)
Depending on your needs, Docker may be even faster. You can also template a lot in PVE so that you can spin up a VM as easy as a container.
 
I ran into this problem using a Ubuntu 24.04 container. It is worth that the Ubuntu 24.04 container uses neither dhcpcd nor dhclient out of the box to configure network interfaces. so re-configuring either of these tools as suggested in this thread will not truly produce the desired outcome. Since the container is using systemd-networkd to implement the DHCP client functionality, this must be reconfigured instead. This could be achieved by editing /etc/systemd/network/ifname.network, but this file is managed by PVE. To avoid risk of overwrite, additional configuration snippets may be added under a /etc/systemd/network/ifname.network.d subdirectory. In this case, I created /etc/systemd/network/eth0.network.d/00-clientid_mac.conf with the following content:

[DHCPv4]
ClientIdentifier = mac

This can even be done before first boot of the container by mounting it on the PVE host with the following shell commands (just substitute your conainer id for 102):

pct mount 102
mkdir /var/lib/lxc/102/rootfs/etc/systemd/network/eth0.network.d
echo -e "[DHCPv4]\nClientIdentifier = mac" > /var/lib/lxc/102/rootfs/etc/systemd/network/eth0.network.d/00-clientid_mac.conf
chown -R --reference=/var/lib/lxc/102/rootfs/etc/systemd/network /var/lib/lxc/102/rootfs/etc/systemd/network/eth0.network.d
pct unmount 102

When the container comes up, as long as it is configured to receive an IPv4 address via DHCP it should make its DHCP request using the MAC address shown in the PVE container config as its DHCP client ID.

References
Additional network configuration of Ubuntu container in PVE
Ubuntu Manpage: systemd.network
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!