LXC : ping host with 2 containers and access internet


#1

Hello everybody,

I’m new to LXC so I’m not very strong. I want my 2 containers to be able to ping each other and ping the host, also have access to the internet. But after following this link > https://wiki.debian.org/LXC/SimpleBridge . My containers ping the host, but not each other, and the host don’t have access to the internet.

For now, I made these steps :
Host machine

brctl addbr br0
ip addr add 192.168.1.219/24 dev br0

vim /var/lib/lxc/container1/config

add

lxc.utsname = container1
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0

lxc.network.ipv4 = 192.168.1.239
lxc.network.ipv4.gateway = 192.168.1.219

(same for container2)

Can somebody help me please ?


#2

Hi!
I do not know much about LXC to be of any help. If you are OK to switch to LXD, then the default configuration would do exactly what you are asking.
See Comparing LXD vs. LXC to decide whether LXD would be useful for your case.


#3

The thing is that I want to do it with lxc :thinking:


#4

I wrote a tutorial to setup a bridge using lxc-net: https://angristan.xyz/setup-network-bridge-lxc-net/

It’s pretty straightforward and easy to setup, you should try it.


#5

I tried to follow your tutorial but it doesn’t work :frowning_face:


#6

Did you try from scratch? :stuck_out_tongue:


#9

It’s ok, with an other method, I can ping my containers and the containers can ping the host. But they don’t have access to the internet :roll_eyes:


#10

What’s the output of

iptables -t nat -L -v -n

?


#11

I tried to run iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE but nothing