devplayer0/docker-net-dhcp

MAC address defining doesn't work

NiXuB86 opened this issue · 7 comments

I tried to start container with predefined MAC address to setup static DHCP lease for container:
docker run --rm -ti --network shared-net --mac-address 66:5e:28:93:6f:60 alpine
In container MAC address defines successfully:

/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
112: shared-bridge0@if113: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 66:5e:28:93:6f:60 brd ff:ff:ff:ff:ff:ff
inet 192.168.28.101/24 brd 192.168.28.255 scope global shared-bridge0
valid_lft forever preferred_lft forever

But on my router it shows another MAC: 5e:f0:e1:a0:7d:17 for lease with this IP: 192.168.28.101.
I think that DHCP client that runs on host using random MAC every time.
And new random MAC is used when container created/restarts.
Or I can set static IP address, but I don't know how to do this with this docker network driver.
What I'm want to do is to connect docker container to linux bridge managed by systemd-networkd and set IP address to it. And I don't want to use pipework script for this because when host/container restarts it needs to be executed again.

Ah, looks like this is due to the fact that Docker only assigns the requested MAC address when moving the interface into the container.

Can we make another flag to define MAC for DHCP client?

Can we make another flag to define MAC for DHCP client?

Not necessary, I've updated NetworkDriver.CreateEndpoint to manually apply the MAC address before running udhcpc (when one is supplied).

Let me know if this fixes the issue for you!

Ok, thanks! I will check this in a few hours

Everething is working fine, man you incredible!!! I tried to setup this for 2 weeks)

Everething is working fine, man you incredible!!! I tried to setup this for 2 weeks)

Glad it helped 😄