LXC container share host network
Goal
You want to share the host network with all your lxc containers.
Check network settings of your containers by typing:
lxc network list
If it displays something like that:
+---------+----------+---------+-------------+---------+
| NAME | TYPE | MANAGED | DESCRIPTION | USED BY |
+---------+----------+---------+-------------+---------+
| docker0 | bridge | NO | | 0 |
+---------+----------+---------+-------------+---------+
| eth0 | physical | NO | | 0 |
+---------+----------+---------+-------------+---------+
Solution
Set up your container with the default settings of LXD, creating a network for all containers attached to the newly created lxdbr0 adapter on the host system with
lxd init
and accept the defaults:
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=lxdbr0]:
and have your containers already connected to the lxdbr0 bridge on your host. You might now see something like this.
+---------+----------+---------+-------------+---------+
| NAME | TYPE | MANAGED | DESCRIPTION | USED BY |
+---------+----------+---------+-------------+---------+
| docker0 | bridge | NO | | 0 |
+---------+----------+---------+-------------+---------+
| eth0 | physical | NO | | 0 |
+---------+----------+---------+-------------+---------+
| lxdbr0 | bridge | YES | | 5 |
+---------+----------+---------+-------------+---------+
Now try it
lxc exec [mycontainer] /bin/bash
curl https://techoverflow.net