Translation(s): English - Français


Alternatives to this network setup for containers can be found on the LXC main page.

In case of routed dhcp backed network provided by the host using libvirt, here is an example.

Dependencies

Installing libvirt

Debian Jessie and below:

apt-get install libvirt-bin

Debian Stretch/Sid:

apt-get install libvirt-clients libvirt-daemon-system

apt-get install ebtables dnsmasq

virsh net-info default

Using default network

(in jessie_di_alpha_1 it's /etc/libvirt/qemu/networks/default.xml)

root@debian:/# cat /var/lib/libvirt/network/default.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE 
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh net-edit default
or other application using the libvirt API.
-->

<network>
  <name>default</name>
  <uuid>999d40xx-22db-c999-f68x-42cfbeba99a3</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0' />
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.100' end='192.168.122.254' />
    </dhcp>
  </ip>
</network>

virsh net-start default
ifconfig -a

root@debian:/# cat /var/lib/lxc/a_container/config
[...]
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = virbr0
lxc.network.hwaddr = 00:FF:AA:00:00:01
lxc.network.ipv4 = 0.0.0.0/24
[...]

<dhcp>
  <range start="192.168.122.100" end="192.168.122.254" />
  <host mac="00:FF:AA:00:00:01" name="foo.example.com" ip="192.168.122.101" />
  <host mac="00:FF:AA:00:00:02" name="bar.example.com" ip="192.168.122.102" />
</dhcp>

virsh net-autostart default
virsh net-info default