lxc
Table of Content
Commands
Command | Description |
---|---|
lxc-create -t download -- -l | Lists available dist’s with there revisions and so on |
lxc-ls -f | displays 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-top | a 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
- 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 - So lets remove the full
eno4
NIC configuration from your system (e.g. from/etc/network/interfaces
) - 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 ;)
- To do that create the a new file beneath
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
- 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 variablelxc.net.0.link
. By default you will have something like thatlxc.net.0.link = lxcbr0
inside of the config which you need to change tolxc.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.
- First you need to change inside of the config file (e.g.
# 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