LXC container with bridged IP

LXC (Linux Containers) is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel and a great alternative to Docker.

Within Ubuntu 16.04 there is on top container manager, called LXD. It’s basically an alternative to LXC’s tools and distribution template system with the added features that come from being controllable over the network.

The default network setup for a new LXC container within Ubuntu is a bridged one, based on the parent interface lxdbr0. Your container will receive an internal IP address from the LXD own managed DHCP server.

But if you want an IP address from your local LANs DHCP server you have to follow these guide.

  1. Convert your primary network interface to a bridged one. Edit your /etc/network/interfaces on the host with your prefered editor under root right and add the following lines
    auto br0
    iface br0 inet static (or dhcp)
    bridge_ports yourphysicalnetworkinterface
    further static IP details

    The following could be a sample interfaces file

    # 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
    # The primary network interface
    auto br0
    iface br0 inet static
    bridge_ports eth0
  2. Create a LXC network profile
    lxc profile create bridged
  3. Edit the new LXC network profile
    lxc profile edit bridged
  4. Edit the new LXC network profile
    config: {}
    description: bridged
        name: eth0
        nictype: bridged
        parent: br0
        type: nic
    name: bridged
    used_by: []
  5. Reboot your server
  6. Stop your existing LXC container
    lxc stop containername
  7. Apply your new created network settings to the container
    lxc profile apply containername bridged
  8. Start your container
    lxc start containername

And now, even everything is fine, your LXC container will receive an IP address from your local LANs DHCP server and could look like this

user@system:/home/user# lxc list
|    NAME    | STATUS  |         IPV4         | IPV6 |    TYP     |    SNAPSHOTS    |
| CONTAINER1 | RUNNING | (eth0) |      | PERSISTENT | 0               |
| CONTAINER2 | RUNNING | (eth0)|      | PERSISTENT | 0               |
| CONTAINER3 | RUNNING | (eth0) |      | PERSISTENT | 0               |
| CONTAINER4 | STOPPED |                      |      | PERSISTENT | 0               |

Schreibe einen Kommentar