[SOLVED] LXC MAC address


I’m running web server on Ubuntu Xenial in LXC container.
Everything works well on first sight but not so good in detail…
To run server I need static IP for container (port forwarding and so on) so I wanted to use “standard” model of binding IP to MAC in Omnia network settings. Problem is that system in LXC container get random MAC on reboot and according to that it has new random IP - binding IP to MAC is useless here.

So I hawe two questions:

  1. Is here some way to permanently bind one MAC address to LXC container? (not tested macchanger on guest system, yet)
  2. If MAC - LXC binding is not possible how to set IP manually without risk of IP collision when new device is connected to wireless or wired interface?

Thank everyone even for help or even showing right direction.

EDIT: Solved
This lxc.network.hwaddr=xx:xx:xx:xx:xx:xx must be added in LXC config file but when you run LXC container from mSATA or other kind of hard drive then you can make same mistake as me:

  1. foo_container need config file in /srv/lxc/foo_container/ to be controlable from webUI
  2. when you run foo_container from external memory (ssd, usb disk…) you need config here:
    /path/to/foo_container/config for configuration to be loaded by foo_container
    Because of copying of config files I was making changes only in /srv/lxc/foo_container/config using Omnia webUI.
    So don’t do same mistake as me and DO NO’T COPY config file from one to second placement!!!
    Symlink is realy good way to make it working as you want.
1 Like

yes, if you want to relocate your LXC containers off the built-in storage, the easiest way to go about this is to symlink /srv/lxc to a directory on your external storage (be it connected via msata card or usb)

mkdir /exteral_storage/lxc
mv /srv/lxc /srv/lxc.out
ln -sf /external_storage/lxc /srv/lxc

you’ll then be able to use the webgui to create and manage lxc containers but they’ll be stored wherever you set up.


Thanks, nice tip. I want to avoid high wear of internal flash so using msata card but I slightly forgot to use “magic” of symlinks… :smiley:

Or you can change it in “/etc/lxc/lxc.conf”:

# cat /etc/lxc/lxc.conf 
lxc.lxcpath = /srv/lxc

I don’t tested if LuCi understand the change.

LuCI doesn’t follow the changed path in lxc.conf unfortunately. You have to do it by symlink if you want to use LuCI.

Note, I only tested this pre-update, maybe it was fixed after the update, since my symlink works I haven’t gone back and tried again.

For me it worked, LuCI created the machine in /data/lxc.

I haven’t tried changing lxc.conf, symlink works well.
And creating container from LuCI results in stable MAC address generated during container creation.