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!

有帮助吗?

解决方案

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

其他提示

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

Like @Leahkim I also had to UP the device, but furthermore assign a static IP from within the container:

ifconfig veth0 add 192.168.18.2 netmask 255.255.255.0 up

You could probably use a dhcp client at this point as well, but this wasnt available for me.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top