How to access LXC container from LAN?
In this part I will shortly show how we can access LXC container from our local network using Debian VM as host.
This post is continuation of the previous one. Check it here. I encourage you to read its contents first.
How to access LXC container from LAN?
Via sudo lxc list
we can see that our container from previous post is running and has IPV4 assigned. However it can't be reached outside our host. In order to make it able to connect from other hosts in LAN we need to configure bridge.
I'm running this setup on Debian host, so instructions included in this post will be Debian related. However it should be almost the same on Ubuntu host.
Firstly we need to find name of our physical interface.
In my case it's enp0s11. We can proceed then with creating network config file:
sudo vi /etc/network/interfaces.d/br0
Copy following config lines and paste it into br0
file.
auto br0
iface br0 inet dhcp
bridge_ports enp0s11
We are using DHCP here. Sample configuration files for bridge interfaces with static ip addr can be found on the internet.
Save the file and then restart networking service via systemctl.
sudo systemctl restart networking
We can see that our bridge is UP:
Now let's assign it to the container. It can be done via following command:
sudo lxc config device add container1 eth0 nic nictype=bridged parent=br0 name=eth0
We can see that our IPV4 changed.
Now our container is reachable from LAN and not only from host.
Hope this post helped you to configure your containers to be accessible from LAN :)