lxc

Table of Content

Commands

CommandDescription
lxc-create -t download -- -lLists available dist’s with there revisions and so on
lxc-ls -fdisplays existing containser as a table with details
lxc-attach -n <name>attaches your current session into the container
lxc-destroy -n <name>removes the container from your devices (removes full container dir)
lxc-start -n <name>starts container
lxc-stop -n <name>stops container
lxc-topa top like view showing installed containers with there current resource usage (CPU,MEM,IO)

Error Failed to load config for

$ lxc-ls Failed to load config for <container_name>... $ lxc-update-config -c /var/lib/lxc/<container_name>/config

Assign dedecated physical NIC to container

As you can not directly put the physical NIC into a container, you can use a bridge instead of it, which looks than in the end like a physical NIC in the container

  1. Have a look which interfaces you have attached and which one can be used (e.g. with ip a) and lets assume the interfaces which we use for bridging is eno4
  2. So lets remove the full eno4 NIC configuration from your system (e.g. from /etc/network/interfaces)
  3. Create now a bridge between your external NIC and the internal LXC NICk
    • To do that create the a new file beneath /etc/network/interfaces.d something like the interface name e.g. eno4br0 with the following content (adopted of course to your needs ;)
auto eno4br0 iface eno4br0 inet static address 10.42.37.189 # the bridge IP broadcast 10.42.37.255 # your vlan brodcast address netmask 255.255.255.0 # your vlan netmask gateway 10.42.37.1 # gateway address in the vlan dns-servesr 10.42.37.1 # your dns server (not needed but helpful) bridge_ports eno4 # NIC where bridge points to bridge_stp off # disable Spanning Tree Protocol bridge_waitport 0 # no delay before a port becomes available bridge_fd 0 # no forwarding delay
- After you have successfully created the new brdige you can just restart the networking service `systemctl restart networking.service` to get it online and fully applied in the system - If you run now `brctl show` you will see something similar to this
$ brctl show bridge name bridge id STP enabled interfaces eno4br0 8000.5e0709e627d1 no eno4
  • Or with ip a
5: eno4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master eno4br0 state UP group default qlen 1000 link/ether aa:aa:aa:aa:aa:aa brd ff:ff:ff:ff:ff:ff altname enp2s0f3 6: eno4br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether aa:aa:aa:aa:aa:bb brd ff:ff:ff:ff:ff:ff inet 10.42.37.189/24 brd 10.42.37.255 scope global eno4br0
  1. So good so far, the host is configured, now you just need to configure your container and your are good to go
    • First you need to change inside of the config file (e.g. /var/lib/lxc/mycontainer/config) the value for the variable lxc.net.0.link. By default you will have something like that lxc.net.0.link = lxcbr0 inside of the config which you need to change to lxc.net.0.link = eno4br0 (or to any othername you have given to your new bridge)
    • Before you restart the container, you can already config the new/changed interface for it again in the (/var/lib/lxc/mycontainer/rootfs)/etc/network/interfaces by adding the new entriy or modifing the current one.
# e.g. add a new eth0 with dhcp auto eth0 iface eth0 inet dhcp # e.g. add a new static eth0 iface eth0 inet static address 10.42.37.188 netmask 255.255.255.0 gateway 10.42.37.1 dns-servers 10.42.37.1
- If you again restart the networking service, you will have your new shiny physical pass through NIC in your container
$ ip a 52: eth0@if53: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether aa:aa:aa:aa:aa:cc brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.42.37.188/24 brd 10.42.37.255 scope global dynamic eth0