bytebybyte
bytebybyte

Reputation: 53

lxd (ubuntu 16.10) container mac address

I am running the latest Ubuntu (16.10) with LXD containers. Containers are configured with bridged networking, and they receive their own IP addresses from the DHCP server. I have configured them with the following:

lxc profile device add default eth0 nic nictype=bridged parent=br0

lxc network attach br0

Now, I need to set hardware addresses (MAC) manually for each of the containers, so their corresponding static IPs never change. However, I am having a hard time of doing so with lxc. Do I just set them in the corresponding /etc/network/interfaces, or is there a better (lxd/lxc) way of doing it?

Upvotes: 4

Views: 8977

Answers (3)

Josh Enders
Josh Enders

Reputation: 123

lxc config device override <instance name> eth0 hwaddr=00:11:22:aa:bb:cc

The override command copies the NIC config from the profile into the instance and then modifies the config key(s) you provide.

via Thomas Parrott

Upvotes: 1

Boris Epstein
Boris Epstein

Reputation: 57

Here's what worked for me on Centos 7.8. I think this is a solution that is distro-agnostic and thus likely most resilient.

In the container directory ( /var/lib/lxc/<container_name> ) edit the config file as follows:

    Template used to create this container: /usr/share/lxc/templates/lxc-download
    # Parameters passed to the template: 
    # For additional config options, please look at lxc.container.conf(5)
    # Distribution configuration
    lxc.include = /usr/share/lxc/config/ubuntu.common.conf
    lxc.arch = linux64
    # Container specific configuration
    lxc.rootfs = /var/lib/lxc/web0/rootfs
    lxc.utsname = web0
    # Network configuration
    lxc.network.type = veth
    lxc.network.flags = up
    lxc.network.link = virbr0
    **lxc.network.hwaddr = 6a:d4:d2:a7:9b:4e**

Note the last line. This is what I added - and that seems to maintain the MAC address constant.

Upvotes: 1

Theodor
Theodor

Reputation: 103

Each container will keep the same MAC address as it was at first launch time. To get its value:

lxc config show container_name
  or, more precise
lxc config get container_name volatile.NIC_NAME.hwaddr

This is not like in case of pure lxc when you had to manually set it in /var/lib/lxc/container_name/config.

But, if you really need to use your own set of MAC addresses(assuming eth0 is nic for container):

lxc config set container_name volatile.eth0.hwaddr yo:ur:ma:ca:dd:ress

Upvotes: 8

Related Questions