Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Vigneswaran R <vignesh@atc.tcs.com>
To: "krzf83@gmail.com" <krzf83@gmail.com>
Cc: netfilter@vger.kernel.org
Subject: Re: OUTPUT: nat after filter (2nd nat). Please help :(
Date: Tue, 14 May 2013 11:00:04 +0530	[thread overview]
Message-ID: <5191CBDC.6020603@atc.tcs.com> (raw)
In-Reply-To: <CAJ1PRSnsV_cN0R6JK+8PYb=9u=Fnp_tbo9ufB1j0vUJPoP0cFQ@mail.gmail.com>

On 05/14/2013 10:05 AM, krzf83@gmail.com wrote:
> According to graph at wikipedia
> (http://imageshack.us/scaled/thumb/29/iptablesb.png) in OUTPUT nat
> table is processed before AND after filter (2 times). I want to
> utilize this second time:
>
> iptables -t filter -A OUTPUT -d 1.2.3.4 -j DROP
> iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner abc -j DNAT --to
> 127.0.0.1:121
>
> Does not work because nat is executed befure filter.
>
> iptables -t filter -A OUTPUT -d 1.2.3.4 -J DROP
> iptables -t filter -A OUTPUT -m owner --uid-owner abc -j CONNMARK
> --set-mark 0x1234
> iptables -t nat -A OUTPUT -p tcp -m connmark --mark 0x1234 -j DNAT
> --to 127.0.0.1:121
>
> I think that should work. It does not. What am I missing? Please help :(

It seems, the two nat tables you are talking about are from different 
chains (OUTPUT, POSTROUTING). The order of packet flow between these 
tables will be like the following,

     OUTPUT nat --> OUTPUT filter --> POSTROUTING nat

So, if you want to filter the packets before nat you can do the following,

iptables -t filter -A OUTPUT -d 1.2.3.4 -J DROP
iptables -t nat -A POSTROUTING -p tcp -m owner --uid-owner abc -j DNAT --to
127.0.0.1:121

I found the following simplified iptables diagram useful for beginners.
<http://pritambaral.com/wp-content/uploads/2012/05/iptables.png>


Regards,
Vignesh

  reply	other threads:[~2013-05-14  5:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-14  4:35 OUTPUT: nat after filter (2nd nat). Please help :( krzf83@gmail.com 
2013-05-14  5:30 ` Vigneswaran R [this message]
     [not found]   ` <CAJ1PRSnzBFnjd5hQbzVs0u2CSBH5ZfwmtUN05+DhvjrDmxWbqA@mail.gmail.com>
2013-05-14  6:07     ` Vigneswaran R

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=5191CBDC.6020603@atc.tcs.com \
    --to=vignesh@atc.tcs.com \
    --cc=krzf83@gmail.com \
    --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