Iptables를 티용한 포트포워딩.. ㅠ

A 서버의 2222번 포트로 들어오는 트래픽을 B 서버의 22번 포트로 포워딩하고 싶습니다 (SSH)

3시간의 구글링을 했지만 먹히는것이 하나도 없네요…ㅠ

modprobe ip_tables
modprobe iptable_nat
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -p tcp -s <A서버 IP> -d <A서버 IP> --dport 2222 -j DNAT --to <B서버 IP>:22
iptables -t nat -A POSTROUTING -j MASQUERADE

iptables 고수님들에게 부탁드립니다 ㅠ

[quote="angelfire":2ludckzs]iptables -t nat -A PREROUTING -p tcp -s <A서버 IP> -d <A서버 IP> --dport 2222 -j DNAT --to <B서버 IP>:22[/quote:2ludckzs]

A서버가 ufw(우분투 IPTABLE) 활성 상태에서 A 서버에서 (sudo ufw enable)
sudo iptables -A PREROUTING -t nat -p tcp -i eth0 --dport 2222 -j DNAT --to <B서버 IP> 하여
B서버로 보내는지 확인 바랍니다. 2222포트가 22번으로 아이피:22 하면 가는 지는 모르겠습니다.
위에 것이 된다면

sudo iptables -A PREROUTING -t nat -p tcp -i eth0 --dport 2222 -j DNAT --to <B서버 IP>:22 도 해보시기 바랍니다.

ufw 일반 방법 참고 링크 : https://help.ubuntu.com/community/Uncom … ction=show

문제 스스로 해결… ㅠ

iptables -t nat -F
iptables -t nat -X
iptables -t nat -Z
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 2222 -j DNAT --to x.x.x.x:22

eth0 : 주 네트워크 인터페이스
x.x.x.x : 외부 서버