An iptables rule should be sufficient. It would need to be at the top of your FORWARD
chain; something like:
iptables -A FORWARD -s 10.99.99.0/24 -d 192.168.x.0/24 -j DROP
It needs to be at the top of the chain because otherwise it becomes a no-op -- there are rules added by Docker that will explicitly ACCEPT
the traffic.
You could instead add the rule to the DOCKER-USER
chain; this is a chain that Docker arranges to be called before any Docker-managed rules. The FORWARD
chain on my local system looks like:
-P FORWARD ACCEPT
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
.
.
.
Alternately, you could add a policy routing rule so that traffic from your containers wouldn't have a route to the untagged network. Your default routing policy looks like this:
# ip rule show
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
Where the main
table is what you see when you run ip route
. You can add a rule that uses an alternate lookup for traffic originating from your containers:
ip rule add priority 1000 from 10.99.99.0/24 lookup 1000
That should result in:
# ip rule show
0: from all lookup local
1000: from 10.99.99.0/24 lookup 1000
32766: from all lookup main
32767: from all lookup default
And then add routing entries to table 1000:
ip route add table 1000 default via 10.x.x.1
Now connections from the containers will only have a default route, and would only be able to access the untagged network if the router at 10.x.x.1 provided an appropriate route.