LXD - new interface Ubuntu 18.04

Hi I have a problem with adding new interface to my container.

I have a computer from which I want to make a router. But the program I want to use works only in Ubuntu 14.04. So I´m creating a Ubuntu 14.04 container. And the program will work from container.

I do this -> apt install lxd
lxd init
lxc launch images:ubuntu/trusty/amd64 router1

This container use interface from PC (enp1s0) and in the container it like eth0 (I think). And then I add to the computer new external network interface (enx00…).

But I don´t know how add this external network interface to cantainer.


So, you have an extra physical interface and you want to have it used exclusively by a specific container (coincidentally running Ubuntu 14.04).

If the network interface on the host is enx00, then to make it available exclusively to the container router1, you need to run:

lxc config device add router1 enx00 nic nictype=physical parent=enx00 name=enx00

Here is the breakdown,

  1. lxc config device add, to add a device
  2. router1, to the container called router1
  3. enx00, this is the name that LXD will use for this device. Can change if you wish.
  4. nic, it’s a NIC (network interface)
  5. nictype=physical, this does the whole work. It’s a physical interface, and the whole interface goes into the container. Read the LXD documentation on NICs for more.
  6. parent=enx00, this is important to use the correct interface on the host.
  7. name=enx00, that is the name of the interface inside the container. You can obviously change it.

You can add a physical NIC to a container even if the container is already running. It will appear instantaneously.

In the container, you can view the new network interface with

ifconfig -a

The interface by default is down, and you need to bring it up yourself (i.e. sudo ifconfig enx00 up).

Thanks a lot. It works.
But now a have another problem with container. When I want do inside the container apt-get update or apt-get install it show me errors but in the local pc it works.

See this:
root@xorp1:~# apt-get update
Err http://archive.ubuntu.com trusty InRelease

Err http://archive.ubuntu.com trusty-updates InRelease

Err http://security.ubuntu.com trusty-security InRelease

Err http://archive.ubuntu.com trusty Release.gpg
Temporary failure resolving ‘archive.ubuntu.com
Err http://security.ubuntu.com trusty-security Release.gpg
Temporary failure resolving ‘security.ubuntu.com
Err http://archive.ubuntu.com trusty-updates Release.gpg
Temporary failure resolving ‘archive.ubuntu.com
Reading package lists… Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/InRelease

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Temporary failure resolving ‘archive.ubuntu.com

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg Temporary failure resolving ‘archive.ubuntu.com

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg Temporary failure resolving ‘security.ubuntu.com

W: Some index files failed to download. They have been ignored, or old ones used instead.

Your container now has two network interfaces. When your container wants to connect to the Internet, it needs to decide which network interface to use.
What you get is a network configuration issue. It should be solved as part of the conversion of the container to a router.