Skip to content

Instantly share code, notes, and snippets.

@adonis0147
Last active September 28, 2018 15:26
Show Gist options
  • Select an option

  • Save adonis0147/f7f089bfa90662b6417b56e926a979f2 to your computer and use it in GitHub Desktop.

Select an option

Save adonis0147/f7f089bfa90662b6417b56e926a979f2 to your computer and use it in GitHub Desktop.
iptables forwarding between two interfaces (connect docker containers in virtual machine with host)
#!/bin/bash
# reference: https://serverfault.com/questions/431593/iptables-forwarding-between-two-interface
# MacOS host
# sudo route -n add 172.17.0.0/16 192.168.1.9
# virutal machine which runs docker containers
# echo 1 > /proc/sys/net/ipv4/ip_forward
sudo iptables -A FORWARD -i ens33 -o docker0 -j ACCEPT
sudo iptables -A FORWARD -i docker0 -o ens33 -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o docker0 -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment