iptables 포트포워딩을 통하여 (외부IP주소:포트)로 (내부IP주소:포트)에 접근하려고 합니다.
안녕하세요.
iptables을 이용한 포트포워딩이 잘 안돼서 조언을 구합니다.
1) 라즈비안OS에 도커 컨테이너를 띄우고 nginx로 웹서버를 구축하였습니다.
2) IP주소에 포트 설정까지 하였습니다. (내부 IP주소: 222.22.2.2:8888)
3) 공유기를 통한 내부망뿐만 아니라 외부망 어디서든지 접속가능하게 하려는 목적으로 포트포워딩을 하였습니다
4) KT통신사가 제공하는 공유기 설정페이지에서 포트포워딩을 설정하고,
외부 IP주소로 접속해보고, 내부 IP주소로도 접속해보니 잘 됩니다.
예) 111.111.11.111:8888 (외부 IP주소) -> 222.22.2.2:8888 (내부 IP주소)
5) 다음으로 iptables를 이용하여 포트포워딩을 시도해보았습니다.
검색을 통한 여러가지 방법을 다 적용해봤지만 모두 되지 않았습니다.
방법이 잘못된건지 통신사에게 막아놓은 것인지 아니면 원래 안되는 것인지 알지 못하여 글을 올리게 되었습니다
** 제가 적용해 보았던 소스들도 첨부하니 참조 부탁드립니다.
iptables -t nat -A PREROUTING -i wlan0 -p tcp -m tcp --dport 8888 -j DNAT --to-destination 222.22.2.2:8888
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp --dport 8888 -j DNAT --to-destination 222.22.2.2:8888
iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
iptables -A FORWARD -p tcp --dport 8888 -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp -i wlan0 --dport 8888 -j DNAT --to 222.22.2.2:8888
ptables -A PREROUTING -t nat -p tcp -d 111.111.11.111 --dport 8888 -j DNAT --to 222.22.2.2:8888
iptables -A FORWARD -p tcp --dport 8888 -d 222.22.2.2 -j ACCEPT
iptables -I INPUT 1 -p tcp --dport 8888 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --dport 8888 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 8888 -j REDIRECT --to-port 8888
invoke-rc.d netfilter-persistent save
invoke-rc.d netfilter-persistent reload
이해를 돕기 위해 파일을 첨부하였습니다
이해를 돕기 위해 파일을 첨부하였습니다
댓글 달기