Port forwarding
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · KUCKAERTZ Régis - NVISION
Halo,
I've set up rules so that packets sent to $MASK_IP:$MASK_PORT are forwarded to $REAL_IP:$REAL_PORT with the source address being replaced by $MASK_IP:
# 1. Changing destination address
$IPTABLES -t nat -A PREROUTING -p tcp --dest $MASK_IP --dport $MASK_PORT -j DNAT --to-destination $REAL_IP:$REAL_PORT# 2. Accepting forwarded packets
$IPTABLES -A FORWARD -p tcp --dest $REAL_IP --dport $REAL_PORT -j ACCEPT
if that's your only FORWARD rule, and the POLICY of FORWARD is set to DROP--you're not allowing reply packets back through the machine (SYN's will get through, but SYN-ACK's will be blocked).
iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
would help in this situation.
Quoted 8 lines
# 3. IP masquerading after filtering
$IPTABLES -t nat -A POSTROUTING --dest $REAL_IP --dport $REAL_PORT -j SNAT --to-source $MASK_IPWhen I telnet on $MASK_IP:$MASK_PORT, it's hanging... I tried sniffing with tcpdump (although I must honestly confess that I don't know if the following request is good), and here is what I got:
um--where are you telnet-ing from, and where are you tcdump-ing at?
Quoted 2 lines
$TCPDUMP \(dst host $MASK_IP and dst port $MASK_PORT\) or \(src host $MASK_IP and src port $MASK_PORT\)
that filter is overly complicated:
$TCPDUMP host $MASK_IP and port $MASK_PORT
is equivalent to what you're trying to capture.
Quoted 10 lines
tcpdump: listening on eth0
14:32:28.568875 x.x.x.x.46569 > $REAL_IP.$REAL_PORT: S 2813621631:2813621631(0) win 5840 <mss 1460,sackOK,timestamp 46292274 0,nop,wscale 0> (DF) [tos0x10]
14:32:31.568875 x.x.x.x.46569 > $REAL_IP.$REAL_PORT: S 2813621631:2813621631(0) win 5840 <mss 1460,sackOK,timestamp 46292574 0,nop,wscale 0> (DF) [tos0x10]
14:32:37.568875 x.x.x.x.46569 > $REAL_IP.$REAL_PORT: S 2813621631:2813621631(0) win 5840 <mss 1460,sackOK,timestamp 46293174 0,nop,wscale 0> (DF) [tos0x10]
if your BPF specifies $MASK_IP and $MASK_PORT why is your capture showing $REAL_IP and $REAL_PORT? those packets shouldn't even match the filter...
Quoted 1 line
Nothing seems to get back... any idea?
it *never* hurts to provide us with:
iptables -vnxL -t nat; iptables -vnxL -t mangle; iptables -vnxL
-j
Signature · 1 line
Jason Opperisano <[email protected]>
Quoted 8 lines
if that's your only FORWARD rule, and the POLICY of FORWARD is set to DROP--you're not allowing reply packets back through the machine (SYN's will get through, but SYN-ACK's will be blocked).
iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPTwould help in this situation.
Did it, but nothing changed
Quoted 1 line
um--where are you telnet-ing from, and where are you tcdump-ing at?
I'm telnet'ing on a different host (otherwise I would have set the appropriate rule in the OUTPUT chain), but I do the dump on the "gateway"
Quoted 3 lines
$TCPDUMP host $MASK_IP and port $MASK_PORT
is equivalent to what you're trying to capture.
Thanks!!
Quoted 3 lines
if your BPF specifies $MASK_IP and $MASK_PORT why is your capture showing $REAL_IP and $REAL_PORT? those packets shouldn't even match the filter...
Maybe that's because I do the dump on the same machine that does the DNAT?
I hope what follows will help you spot my mistake!
Régis
$ iptables -vnxL -t nat; iptables -vnxL -t mangle; iptables -vnxL
# nat table
Chain PREROUTING (policy ACCEPT 2439 packets, 148991 bytes)
pkts bytes target prot opt in out source
destination
17 1020 DNAT tcp -- * * 0.0.0.0/0
$MASK_IP tcp dpt:$MASK_PORT to:$REAL_IP:$REAL_PORT Chain POSTROUTING (policy ACCEPT 741 packets, 45651 bytes)
pkts bytes target prot opt in out source
destination
0 0 SNAT tcp -- * * 0.0.0.0/0
$REAL_IP tcp dpt:$REAL_PORT to:$MASK_IP
Chain OUTPUT (policy ACCEPT 741 packets, 45651 bytes)
pkts bytes target prot opt in out source
destination
# mangle table
Chain PREROUTING (policy ACCEPT 1567265 packets, 1105330580 bytes)
pkts bytes target prot opt in out source
destination Chain OUTPUT (policy ACCEPT 1181535 packets, 615648770 bytes)
pkts bytes target prot opt in out source
destination
# filter table
Chain INPUT (policy ACCEPT 44233 packets, 9251612 bytes)
pkts bytes target prot opt in out source
destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source
destination
0 0 ACCEPT all -- * * 0.0.0.0/0
0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT tcp -- * * 0.0.0.0/0$REAL_IP tcp dpt:$REAL_PORT
Chain OUTPUT (policy ACCEPT 41927 packets, 30331854 bytes)
pkts bytes target prot opt in out source
destination