So I wanted to have a setup where, I have the host which has static IP. Some containers work as webservers - these have static ip. Other containers which for testing need local private subnet but need to NAT to access internet. My setup is xenial.
lxc --version
2.0.11
Step 1: Setup bridged for your for baremetal host with ethernet enp0s10
/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address public-ip.address
netmask .....
network ....
broadcast ....
gateway ....
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers .............
dns-search .............
## bridge options
bridge_ports enp0s10
## auto enp2s0
iface enp0s10 inet manual
Step 2:
launch your container xenial-public . Attach
lxc config device add xenial-public eth3 nic name=eth3 nictype=bridged parent=br0
Step 3: Edit your container via lxc exec xenial-public bash
to give it a different public ipaddress
/etc/network/interfaces.d/50-cloud-init.cfg
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
auto lo
iface lo inet loopback
# The primary network interface
auto eth3
iface eth3 inet static
address public-ip.address
netmask .....
network ....
broadcast ....
gateway ....
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers .............
dns-search .............
Step 4: Go back to the host. Create a local lxdbr0
bridge. . This was necessary for me as I did not configure a lxdbr0
when doing lxd init.
sudo dpkg-reconfigure -p medium lxd
Answer names and range for private subnet.
Now launch any image, it will automagically get the local private subnet,
lxc launch ubuntu:xenial xenial-private
Did test this and works OK for me. Thanks (helped me migrate from Virtualbox).
One small question: will this work when I upgrade the host xenial to bionic. Will netplan do the magic?