Hi All,
I have the following situation:
[HOST_A]:TCP to port6060 --> eth0-[HOST_B]-eth0 --> [HOST_C]
IP HOST_C = zz.zz.zz.zz (can be any host on the internet)
IP HOST_B = xx.xx.xx.xx
IP HOST_C = yy.yy.yy.yy
I need to redirect incoming traffic on HOST_B on eg. port 6060 to HOST_C port 80. This because on HOST_C only traffic on port 80 is allowed from configured IP Addresses.
So my goal is to have another host connecting to port 6060 on HOST_B, which in turn redirects that traffic to HOST_C so HOST_C thinks the traffic is coming from HOST_B.
The rules I found on the internet are:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 6060 -j DNAT --to yy.yy.yy.yy:80
iptables -t nat -A POSTROUTING -p tcp --dst yy.yy.yy.yy --dport 80 -j SNAT --to xx.xx.xx.xx
iptables -t nat -A OUTPUT --dst xx.xx.xx.xx -p tcp --dport 6060 -j DNAT --to yy.yy.yy.yy:80
But it doesn't work completely. If on HOST_B I telnet localhost 6060 my traffic is redirected to HOST_C, but from the outside, telnet xx.xx.xx.xx 6060 my traffic is not being redirected.
Someone any ideas? I enabled IPv4 forwarding
Hope that someone can point me into the right direction.
Thanks!
Onno.
[EDIT]
Ok, more strange things: When I run "tcpdump host zz.zz.zz.zz and host yy.yy.yy.yy" it suddenly works!! So tcpdump does 'something', because when I stop tcpdump, the whole thing stops working and my traffic stops being redirected. Below some output from tcpdump:
Code:
-bash-3.2# tcpdump host [HOST_A] or host [HOST_C]
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
19:31:05.463761 IP [HOST_A].54276 > [HOST_B].6060: S 1370221981:1370221981(0) win 16384 <mss 1460,nop,nop,sackOK>
19:31:05.464267 IP [HOST_B].54276 > [HOST_C].http: S 1370221981:1370221981(0) win 16384 <mss 1460,nop,nop,sackOK>
19:31:05.464338 IP [HOST_C].http > [HOST_B].54276: S 1940932723:1940932723(0) ack 1370221982 win 65535 <mss 1460,sackOK,eol>
19:31:05.464345 IP [HOST_B].6060 > [HOST_A].54276: S 1940932723:1940932723(0) ack 1370221982 win 65535 <mss 1460,sackOK,eol>
19:31:05.495415 IP [HOST_A].54276 > [HOST_B].6060: . ack 1 win 17520
19:31:05.495427 IP [HOST_B].54276 > [HOST_C].http: . ack 1 win 17520
19:31:13.571384 IP [HOST_A].54276 > [HOST_B].6060: P 1:2(1) ack 1 win 17520
19:31:13.571401 IP [HOST_B].54276 > [HOST_C].http: P 1:2(1) ack 1 win 17520
19:31:13.671615 IP [HOST_C].http > [HOST_B].54276: . ack 2 win 65535
19:31:13.671628 IP [HOST_B].6060 > [HOST_A].54276: . ack 2 win 65535
19:31:13.905020 IP [HOST_A].54276 > [HOST_B].6060: P 2:5(3) ack 1 win 17520
19:31:13.905033 IP [HOST_B].54276 > [HOST_C].http: P 2:5(3) ack 1 win 17520
19:31:14.004616 IP [HOST_C].http > [HOST_B].54276: . ack 5 win 65535
19:31:14.004627 IP [HOST_B].6060 > [HOST_A].54276: . ack 5 win 65535
19:31:14.935235 IP [HOST_A].54276 > [HOST_B].6060: P 5:7(2) ack 1 win 17520
19:31:14.935246 IP [HOST_B].54276 > [HOST_C].http: P 5:7(2) ack 1 win 17520
19:31:14.937750 IP [HOST_C].http > [HOST_B].54276: P 1:308(307) ack 7 win 65535
19:31:14.937762 IP [HOST_B].6060 > [HOST_A].54276: P 1:308(307) ack 7 win 65535
19:31:14.938051 IP [HOST_C].http > [HOST_B].54276: F 308:308(0) ack 7 win 65535
19:31:14.938061 IP [HOST_B].6060 > [HOST_A].54276: F 308:308(0) ack 7 win 65535
19:31:14.969568 IP [HOST_A].54276 > [HOST_B].6060: . ack 309 win 17213
19:31:14.969579 IP [HOST_B].54276 > [HOST_C].http: . ack 309 win 17213
19:31:14.971522 IP [HOST_A].54276 > [HOST_B].6060: F 7:7(0) ack 309 win 17213
19:31:14.971533 IP [HOST_B].54276 > [HOST_C].http: F 7:7(0) ack 309 win 17213
19:31:14.972041 IP [HOST_C].http > [HOST_B].54276: . ack 8 win 65534
19:31:14.972056 IP [HOST_B].6060 > [HOST_A].54276: . ack 8 win 65534