port forwading

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Security_Guide/s1-firewall-ipt-fwd.html

http://serverfault.com/questions/342407/linux-how-to-port-forwarding-with-iptables-between-2-hosts-on-different-network


mysql server 실행

docker run --name chozo99 --rm -e MYSQL_ROOT_PASSWORD=**** mysql:5.5


docker inspect --format '{{ .NetworkSettings.IPAddress }}' chozo99


local 에서 mysql 접속...

mysql --host=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' chozo99` -uroot -p'****' mysql


외부에서 접속시 포트개방

$ echo 1 > /proc/sys/net/ipv4/ip_forward


$ iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 3306 -j DNAT \

      --to `docker inspect --format '{{ .NetworkSettings.IPAddress }}' chozo99`:3306

$ iptables -t nat  -A POSTROUTING -j MASQUERADE


reference

iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 3306 -j DNAT \

      --to `docker inspect --format '{{ .NetworkSettings.IPAddress }}' chozo99`:3306

$ iptables -t nat -D POSTROUTING -j MASQUERADE


iptables -t nat -L PREROUTING  -n --line-numbers

iptables -t nat -D PREROUTING 2






+ Recent posts