Caustic
Caustic

Reputation: 979

Can't change mac address of docker containter

I have tried the following

docker run -e lxc --lxc-conf="lxc.network.hwaddr=00:0C:29:88:30:CC" -i -t centos ifconfig

But as you can see from my outuput it does not chnage the mac address

eth0: flags=3<UP,BROADCAST>  mtu 1500
    inet 172.17.0.6  netmask 255.255.0.0  broadcast 0.0.0.0
    inet6 fe80::42:acff:fe11:6  prefixlen 64  scopeid 0x20<link>
    ether 02:42:ac:11:00:06  txqueuelen 1000  (Ethernet)
    RX packets 1  bytes 90 (90.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 1  bytes 90 (90.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10<host>
    loop  txqueuelen 0  (Local Loopback)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 0  bytes 0 (0.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I am running docker 1.3 on Ubuntu and the container generated from a centos7 image

Client version: 1.3.2
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): 39fa2fa
OS/Arch (client): linux/amd64
Server version: 1.3.2
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): 39fa2fa

I would appreciate any help to successfully change my mac address in my container.

Upvotes: 0

Views: 2583

Answers (3)

Francesco Giacomini
Francesco Giacomini

Reputation: 41

If you look at the docker code at https://github.com/docker/docker/blob/v1.4.1/vendor/src/github.com/docker/libcontainer/netlink/netlink_linux.go#L528 you see that only non-broadcast local mac addresses are accepted. Search for "Organizationally Unique Identifier" in https://en.wikipedia.org/wiki/MAC_address for an explanation. In practice this means that the second character of the MAC has to be 2, 6, A or E.

If you run docker run --mac-address=00:0C:29:88:30:CC centos ifconfig you should see an error message that comes from the code pointed at above.

Upvotes: 2

user4352479
user4352479

Reputation:

first,check your system has lxc-start command ? if have lxc-start command #stop docker service ,use command run docker service sudo docker -d -e lxc ,look have any error is report. if have not lxc-start command apt-get install lxc-docker

Upvotes: 0

mgaido
mgaido

Reputation: 3055

The way I do this is to run the container in privileged mode, then running ifconfig in the container to set it. But if you are looking for a solution which let you do that in the running command, I think you have to wait for other responses...

Upvotes: 1

Related Questions