Internet access LXC-Container

networking

#1

Hello,

first of all: I’m not a network specialist. So I need to have some support here.
My goal: I want to have a setup which I can:
a) access all LXC-containers from LAN
AND
b) internet access for LXC-containers

Situation:
LAN 192.168.1.0 (Router)
Windows 10 - Oracle Virtual Box: LXC-host on Debian-9 (192.168.1.112)
On this LXC-host are different LXC-containers. For example another Debian-9 system.

I tried different network settings.

1st (internet accessible but no connection from LAN):

root@lxc-vm:~# cat /etc/network/interfaces
[...]
# The primary network interface
allow-hotplug enp0s3
iface enp0s3 inet dhcp

root@lxc-vm:~# cat /var/lib/lxc/debian-9/config
[...]
# Network configuration
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:b8:52:96

root@lxc-vm:~# lxc-ls --fancy
NAME          STATE   AUTOSTART GROUPS IPV4      IPV6
debian-9      RUNNING 0         -      10.0.3.67 -

Have set a route in my router:

I can ping this LXC-container from LXC-host but not from LAN.
But I have an internet connection.

2nd (accessible from LAN, but no internet):

root@lxc-vm:~# cat /etc/network/interfaces
[...]
# The primary network interface
allow-hotplug enp0s3
iface enp0s3 inet manual
# The br0 bridge
auto br0
iface br0 inet dhcp
    bridge-ifaces enp0s3
    bridge-ports enp0s3
    up ifconfig enp0s3 up

root@lxc-vm:~# cat /var/lib/lxc/debian-9/config
[...]
# Network configuration
lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:b8:52:96
lxc.network.ipv4.gateway = 192.168.1.1
lxc.network.ipv4 = 0.0.0.0/24

root@lxc-vm:~# lxc-ls --fancy
NAME          STATE   AUTOSTART GROUPS IPV4         IPV6
debian-9      RUNNING 0         -      192.168.1.20 -

I can ping this LXC-container from LAN but have no internet connection.

What do I have to do?

Thanks for help!


#2

I found a solution:

On LXC-host:

root@lxc-vm:~# cat /var/lib/lxc/debian-9/config
[...]
# Network configuration
lxc.network.0.type = veth
lxc.network.0.link = lxcbr0
lxc.network.0.flags = up
lxc.network.0.hwaddr = 00:16:3e:xx:xx:xx
lxc.network.1.type = veth
lxc.network.1.link = br0
lxc.network.1.flags = up
lxc.network.1.hwaddr = 00:17:3e:xx:xx:xx

On LXC-container:

root@debian-9:~# cat /etc/network/interfaces
[...]
auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet dhcp
up route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.3.1 dev eth0

root@debian-9:~# echo 1 > /proc/sys/net/ipv4/ip_forward