[lxc-users] Determining a container's MAC address

Robert Pendell shinji at elite-systems.org
Tue Sep 1 18:04:59 UTC 2015


On Tue, Sep 1, 2015 at 11:59 AM, Peter Steele <...> wrote:
> On 09/01/2015 08:36 AM, Andrey Repin wrote:
>>
>> If your conf file is missing lxc.network.hwaddr, it was either removed, or
>> a container was not created using standard template. You can add it manually
>> with any suitable value.
>
>
> You are correct, I am not using a standard template. The command I am using
> to create my containers is
>
> lxc-create -t /bin/true -n <name> --dir=<custom-path>/rootfs
>
> I populate the container manually with a custom template I've made based on
> CentOS 7.1. The lxc-create command generates the expected config file under
> /var/lib/lxc/<name> is created, but it's missing an entry for
> lxc.network.hwaddr. I'll try creating a container with the stock CentOS
> template and make sure there are no other missing entries in my config that
> might be relevant.
>

Just as a point of reference it doesn't auto insert the mac address
for me either and generated mac address doesn't seem to follow the
default format.  I may be doing something wrong though.  My test
involves creating an unprivileged container using the default
template.

Note: My creation command is prefixed by "TMPDIR=/tmp" as it works
around the default secure tmpdir on my installation.  I've just never
been bothered to remove the module since it doesn't affect 99% of what
I do.  Just redefines TMPDIR as /tmp for the purpose of the script.

Command used: TMPDIR=/tmp lxc-create -t download -n testcont
Container created: Ubuntu Trusty amd64
Result: No default hwaddr defined in the configuration.

I then did a test privileged container and found that used the
lxc-ubuntu template instead.  It also had the hwaddr entry everyone
was expecting.  I checked the script and there is a line that
explicitly adds it.  This isn't present in lxc-download at all.

    # if there is exactly one veth network entry, make sure it has an
    # associated hwaddr.
    nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
    if [ $nics -eq 1 ]; then
        grep -q "^lxc.network.hwaddr" $path/config || sed -i -e
"/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr =
00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')"
$path/config
    fi

Configs as generated on latest lxc are available on my pastebin:
https://pastebin.com/TttZ7HFy

Package policy:
shinji at icarus:/usr/share/lxc/templates> apt-cache policy lxc
lxc:
  Installed: 1.1.3+master~20150828-1940-0ubuntu1~trusty
  Candidate: 1.1.3+master~20150828-1940-0ubuntu1~trusty
  Version table:
 *** 1.1.3+master~20150828-1940-0ubuntu1~trusty 0
        500 http://ppa.launchpad.net/ubuntu-lxc/daily/ubuntu/
trusty/main amd64 Packages
        100 /var/lib/dpkg/status
     1.0.7-0ubuntu0.2 0
        500 http://mirrors.linode.com/ubuntu/ trusty-security/main
amd64 Packages
        500 http://mirrors.linode.com/ubuntu/ trusty-updates/main amd64 Packages
     1.0.3-0ubuntu3 0
        500 http://mirrors.linode.com/ubuntu/ trusty/main amd64 Packages


Robert Pendell
shinji at elite-systems.org
A perfect world is one of chaos.
Keybase: http://keybase.io/shinji257


More information about the lxc-users mailing list