Reputation: 21
This is my first time when I am setting up LXD to run multiple containers. I have done all the configuration steps but my container not getting IP address from DHCP server which is running inside my organization. Please help me out.
I am using Bridge interface profile. Below are changes I have made:
root@DMG-LXD-TVM2:~# vi /etc/network/interfaces
auto br0
iface br0 inet dhcp
bridge-ports ens32
bridge-ifaces ens32
iface ens32 inet dhcp
root@DMG-LXD-TVM2:~# lxc list
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
| Continer1 | RUNNING | | | PERSISTENT | 0 |
IP and interface details what i setup on my ubuntu machine
Dhcp message when doing ifdown eth0 && ifup eth0 inside container
Upvotes: 2
Views: 4363
Reputation: 353
This is an older question, but I decided to answer it, since I got stuck on the same topic and the solution isn't exactly obvious.
If you want your container to obtain its ip configuration from an external device (e.g. internet router, company dhcp server), you need to tell it so, at creation time. This is done via a configuration parameter pair user.network_mode=dhcp
Since this configuration is in "user" space, it is not normed, but works on ubuntu 16.04. For details see: https://github.com/lxc/lxd/blob/master/doc/configuration.md
Step 1: create bridge on the host in /etc/network/interfaces
auto br0
iface br0 inet dhcp
bridge_ports ens32
bridge_stp off
bridge_fd 0
Step 2: create you own lxd profile called mydhcp
lxd profile create mydhcp
or reconfigure your default lxd configuration by calling
sudo dpkg-reconfigure -p medium lxd
(You need to choose at the first prompt and add on the second prompt, then enter your bridge's name)
If you use your own profile, edit it
lxc profile edit mydhcp
paste the following
name: mydhcp
config:
user.network_mode: dhcp
description: Profile for creating dhcp containers
devices:
eth0:
name: eth0
nictype: bridged
parent: br0
type: nic
(Note the spaces - this is a YAML file, the spaces matter!)
Step 3: create a new container using you mydhcp profile
lxc launch ubuntu:16.04 mydhcpcontainer -p mydhcp -c user.network_mode=dhcp
if you changed the default lxd configuration in the previous step, just enter
lxc launch ubuntu:16.04 mydhcpcontainer -c user.network_mode=dhcp
Check your new container's ip address with
lxc exec mydhcpcontainer -- ifconfig
Upvotes: 3