Skip to content

Instantly share code, notes, and snippets.

@menxit
Last active November 2, 2020 08:20
Show Gist options
  • Save menxit/335875704e022eec4f868c7d8c3f4978 to your computer and use it in GitHub Desktop.
Save menxit/335875704e022eec4f868c7d8c3f4978 to your computer and use it in GitHub Desktop.
Docker UFW and iptables
  1. Disable iptables
$ sudo vim /etc/docker/daemon.json
{
  "iptables": false
}
  1. You have to set Docker's bridge postrouting in ufw:
$ ifconfig docker0

It should returns something like this:

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255

So docker0's network is 172.17.0.1/16

sudo vim /etc/ufw/after.rules
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 172.17.0.1/16 -o eth0 -j MASQUERADE
COMMIT
  1. Finally you have to restart UFW and Docker
sudo ufw disable
sudo ufw enable
sudo systemctl restart docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment