Last active
September 28, 2018 15:26
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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