[lxc-users] Networking LXD containers

Kean Sum Ooi keansum at gmail.com
Fri Mar 11 08:12:31 UTC 2016


Hi Steve,

Do you mean LXC containers? On Ubuntu?

PS:
https://wiki.debian.org/LXC/SimpleBridge
http://askubuntu.com/questions/231666/how-do-i-setup-an-lxc-guest-so-that-it-gets-a-dhcp-address-so-i-can-access-it-on
https://www.flockport.com/lxc-macvlan-networking/

There are at least two ways to do this. Bridging (container is visible
from host) or macvlan (container is not visible from host).

1. Bridging
On the host we bridge to eth0, edit /etc/network/interfaces:
auto br0
iface br0 inet dhcp
  bridge_ports eth0

Restart the host. You should now see br0 with ifconfig.

Next in the config file for your container (eg. for privileged mode by
default it's in /var/lib/lxc/<your_container>/config)

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
# give a dummy hwaddr
lxc.network.hwaddr = 00:16:3e:86:62:10

To get more information about the config file, PS:
$ man lxc.container.conf

Start up your container and it should be bridged to your LAN (so
accessible from other nodes on your LAN).

2. macvlan
On the host create the macvlan to your eth0 network interface.
$ sudo ip link add mvlan0 link eth0 type macvlan mode bridge
$ sudo ifconfig mvlan0 up
The mvlan0 does not need an IPv4 address as it has a IPv6 address by
default, but if you need to give it an IP address can try this:
$ sudo dhclient -v mvlan0

You should see mvlan0 with ifconfig.

Next in the config file for your container

lxc.network.type = macvlan
lxc.network.macvlan.mode = bridge
lxc.network.flags = up
lxc.network.link = mvlan0
# dummy hwaddr
lxc.network.hwaddr = 00:16:4e:75:b0:ca
lxc.network.mtu = 1500
# Get mask and broadcast address from "ifconfig eth0"
lxc.network.ipv4 = 192.168.10.50/24 192.168.10.255
# Get gateway from "route -n"
lxc.network.ipv4.gateway = 192.168.10.254

Start up your container and it should be bridged to your LAN (so
accessible from other nodes on your LAN but now since it's macvlan not
from the host).

Hope it helps. Thanks



More information about the lxc-users mailing list