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!
On such an Ubuntu system, installing LXC is as simple as: Your system will then have all the LXC commands available, all its templates as well as the python3 binding should you want to script LXC. Unprivileged containers are the safest containers.
LXC containers are often considered as something in the middle between a chroot and a full fledged virtual machine. The goal of LXC is to create an environment as close as possible to a standard Linux installation but without the need for a separate kernel. LXC is currently made of a few separate components:
There are multiple network modes that can be used in setting up LXC. By default, the lxc-oracle template script sets up networking by setting up a veth bridge. In this mode, a container obtains its IP address from the dnsmasq server that libvirtd runs on the private virtual bridge network (virbr0) between the container and the host.
Another useful scenario would be to create a new interface inside the container, bridged to an existing bridge on the host: 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With