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
First rule does not work because nat it processed before filter. Any way to bypass it?
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
First rule does not work because nat it processed before filter. Any way to bypass it?
You are not required to filter anything before DNAT. You ask the wrong question.
You should have a look at man iptables-extensions especially the module conntrack
with its options --ctstate DNAT
, --ctorigdst
, and --ctorigdstport
.
iptables -t nat -A OUTPUT -d 1.2.3.4 -j ACCEPT
iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner abc -j DNAT --to 127.0.0.1:121