Sorry for the late response, I was not in my home these days.
Please check the example below, this confirm that although the container webdevops-ssh
is bound to vlan 192.168.10.0/24 its external traffic is in 192.168.0.0/24 I confirm that because I’m able to SSH from this container to other container on 192.168.0.0/24 network. This means that the traffic is not going through the main gateway and it is not filtered.
root@sofx1013dckr309.home.lan:~# docker ps | head -n2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc577bf6d83b webdevops/ssh "/entrypoint supervi…" 5 days ago Up 5 days 192.168.10.9:22->22/tcp webdevops-ssh
root@sofx1013dckr309.home.lan:~#
The Docker host is in 192.168.0.0/24 network, this is its main interface. The main IP of that Docker host is 192.168.0.9
root@sofx1013dckr309.home.lan:~# ip addr show | grep inet
inet 127.0.0.1/8 scope host lo
inet 192.168.10.9/24 brd 192.168.10.255 scope global enp0s5
inet 192.168.10.6/24 brd 192.168.10.255 scope global secondary enp0s5:1
inet 192.168.0.9/24 brd 192.168.0.255 scope global br30
inet 172.16.18.1/24 brd 172.16.18.255 scope global br-312d010c1a79
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
inet 10.31.93.1/24 scope global lxdbr0
root@sofx1013dckr309.home.lan:~#
In the main routing table I have:
auto lo
iface lo inet loopback
# br30
auto br30
iface br30 inet static
bridge_ports enp0s4
address 192.168.0.9
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1
# VLAN30
auto enp0s4
iface enp0s4 inet manual
for handling additional IP from different networks I have this:
root@sofx1013dckr309.home.lan:~# cat /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
# Added by KpuCko
100 vlan310
root@sofx1013dckr309.home.lan:~#
Back to interfaces file:
# VLAN310
auto enp0s5
iface enp0s5 inet static
address 192.168.10.9
netmask 255.255.255.0
post-up ip route add 192.168.10.0/24 dev enp0s5 src 192.168.10.14 table vlan310
post-up ip route add default via 192.168.10.254 dev enp0s5 table vlan310
post-up ip rule add from 192.168.10.14/32 table vlan310
post-up ip rule add to 192.168.10.14/32 table vlan310
auto enp0s5:1
iface enp0s5:1 inet static
address 192.168.10.6
netmask 255.255.255.0
So 192.168.10.9 is from vlan310, but the iptables show that the external traffic goes thought 192.168.0.0/24
root@sofx1013dckr309.home.lan:~# iptables -t nat -L -n
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DOCKER all -- 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
DOCKER all -- 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 172.17.0.0/16 0.0.0.0/0
MASQUERADE all -- 172.16.18.0/24 0.0.0.0/0
MASQUERADE tcp -- 172.16.18.2 172.16.18.2 tcp dpt:443
MASQUERADE tcp -- 172.16.18.2 172.16.18.2 tcp dpt:80
MASQUERADE tcp -- 172.16.18.4 172.16.18.4 tcp dpt:51414
MASQUERADE tcp -- 172.16.18.16 172.16.18.16 tcp dpt:22
Chain DOCKER (2 references)
target prot opt source destination
RETURN all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
DNAT tcp -- 0.0.0.0/0 192.168.10.6 tcp dpt:51414 to:172.16.18.4:51414
DNAT tcp -- 0.0.0.0/0 192.168.0.9 tcp dpt:443 to:172.16.18.2:443
DNAT tcp -- 0.0.0.0/0 192.168.0.9 tcp dpt:80 to:172.16.18.2:80
DNAT tcp -- 0.0.0.0/0 192.168.10.9 tcp dpt:22 to:172.16.18.16:22
root@sofx1013dckr309.home.lan:~#
And the tests confirmed that:
root@sofx1013dckr309.home.lan:~# docker exec -it webdevops-ssh bash
root@dc577bf6d83b:/# cd
root@dc577bf6d83b:~# ssh 192.168.0.7
root@192.168.0.7's password:
root@dc577bf6d83b:~#
In a normal scenario this traffic should be blocked by my main firewall.