LXC - Linux Containers - Add new network interface without restarting

lxc
Diamond picture Diamond · Apr 1, 2014 · Viewed 11.6k times · Source

Searching on google, there's only way to add new network interface is adding to config file. Is there any lxc command that we can add lively, (don't need to restart the container)?

The page mentioned how to add second network interface: http://box.matto.nl/lxctwonics.html

Thanks!

Answer

lanzz picture lanzz · Apr 21, 2014

It would very much depend on the configuration of the interface you're trying to add to the container.

If you have an existing interface on your host which you want to be visible inside the container:

# on the host:
pid=$(lxc-info -pHn foobar)
ip link set dev eth3 netns $pid name eth1

This will cause your host's eth3 interface to be moved to the container foobar, renamed to eth1. This is roughly equal to this configuration:

lxc.network.type=phys
lxc.network.link=eth3
lxc.network.name=eth1

Another useful scenario would be to create a new interface inside the container, bridged to an existing bridge on the host:

# on the host:
pid=$(lxc-info -pHn foobar)
ip link add name veth0 type veth peer name veth0_container
brctl addif br0 veth0
ip link set dev veth0_container netns $pid name veth0

This will create a pair of connected virtual-ethernet interfaces (veth0 and veth0_container), add one of them to the br0 bridge, and move the other into the container foobar. This is roughly equivalent to this configuration:

lxc.network.type=veth
lxc.network.link=br0
lxc.network.name=veth0