LXC - Linux Containers - Add new network interface without restarting

Thread very helpful, but I had to set the created link up to make container access to the network:

Before:(ip link)

11: veth0@if10: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master vmbr0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 42:f1:f9:5a:5c:ae brd ff:ff:ff:ff:ff:ff link-netnsid 1

Set the link up:

ip link set dev veth0 up

After:(ip link)

11: veth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0 state UP mode DEFAULT group default qlen 1000
    link/ether 42:f1:f9:5a:5c:ae brd ff:ff:ff:ff:ff:ff link-netnsid 1

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

Tags:

Lxc