From: Pascal Hambourg <pascal.mail@plouf.fr.eu.org>
To: netfilter@vger.kernel.org
Subject: Re: Port redirection
Date: Wed, 05 Aug 2009 16:04:11 +0200 [thread overview]
Message-ID: <4A79915B.7050407@plouf.fr.eu.org> (raw)
In-Reply-To: <7d7f2e8c0908042157y4e80136ct82efd1dd2446db2c@mail.gmail.com>
Hello,
Steve Fink a écrit :
> I am trying to redirect all traffic generated on box $SRC to a
> particular UDP port to a different host $SPY. I've done similar things
> with whole TCP connections using DNAT and SNAT, but this time I want
> UDP and I want to be able to start up the redirection after the
> "connection" has been established. (I never see these packets in the
> 'nat' table.)
You don't see these packets in the 'nat' table because the "connection"
already exists and has an an entry in the conntrack table. You can
delete a conntrack entry with the conntrack command from the
conntrack-tools package. You can also prevent the packets to create a
conntrack entry by using the NOTRACK target in the 'raw' table until
after you add the NAT rules. Make sure to match packets in both
directions. After you remove the NOTRACK rules, the next packet will
enter the 'nat' chains and hit the NAT rules.
> The only option that seemed viable, me not knowing much about
> networking, was to use the 'mangle' table to set a mark on the
> outgoing packets, then use 'ip' to route the packet to $SPY. I've used
> iptables a fair amount, but ip not at all.
>
> On $SRC, I ran:
> iptables -t mangle -A OUTPUT -p udp --dport 8765 -j MARK --set-mark 1
> ip rule add fwmark 1 table 50
> ip route add via $SPY table 50
> sysctl net.ipv4.ip_forward=1 # Dunno if this matters
It doesn't matter. Packets are locally generated, the box does not act
as a router.
> ip route flush cache
>
> On $SPY, I ran:
> sysctl net.ipv4.ip_forward=1 # Makes sense here
>
> $SRC, $SPY, and $ORIG_DEST (the original destination) can all reach each other.
>
> According to iptables, the mark is getting set on the packets I want
> redirected. But tcpdump shows packets still going to the original
> destination, not $SPY. I am testing by running this on $SRC
>
> nc -v -u $ORIG_DEST 8765
>
> And I trigger packets to be sent by hitting enter in that window. The
> packets are making it to my dummy server on $ORIG_DEST. They do not
> show up to tcpdump on $SPY.
>
> I don't know how to read the output of 'ip route show cache', but it includes
>
> $SPY from $SRC tos lowdelay dev tun0
> cache mtu 1412 advmss 1372 hoplimit 64
> local $SRC from $SPY tos lowdelay dev lo src $SRC
> cache <local,src-direct> iif tun0
>
> (I'm testing this over a VPN, hence the tun0 device. Both $ORIG_DEST
> and $SPY are accessible via the VPN.)
This matters a lot : for both $ORIG_DEST and $SPY, the actual next hop
is the VPN endpoint.
> The only thing I can think of is that $SPY needs to be reachable in a
> single hop
Indeed, otherwise the actual next hop will forward the packets based on
the destination address. Whether the packet is marked or not, the next
hop is the VPN endpoint anyway, and it forwards the packets to
$ORIG_DEST, not $SPY.
next prev parent reply other threads:[~2009-08-05 14:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-05 4:57 Port redirection Steve Fink
2009-08-05 14:04 ` Pascal Hambourg [this message]
2009-08-05 18:30 ` Steve Fink
-- strict thread matches above, loose matches on Subject: below --
2006-08-13 0:18 port redirection Brian Lewis
2006-08-13 6:18 ` Graham Murray
2006-08-13 7:54 ` Brian Lewis
[not found] <200505312248.j4VMmKcQ016084@rti02.co-lo.riverviewtech.net>
2005-05-31 23:37 ` Port redirection Taylor, Grant
2005-05-31 19:25 Chris NoSurname
2005-05-31 22:42 ` Anthony Sadler
2005-06-01 2:45 ` Jason Opperisano
2003-04-30 14:43 Port Redirection nassri abokhalaf
2003-04-30 14:38 ABOKHALAF, Nassri Abdellatif
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A79915B.7050407@plouf.fr.eu.org \
--to=pascal.mail@plouf.fr.eu.org \
--cc=netfilter@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox