1

I have a static 1:1 NAT setup in iptables which excludes a the larger subnet (so that NETMAP hosts can still get to other local hosts which are not static NAT) like so:

*nat
-A PREROUTING --destination 128.128.196.32/27 -j NETMAP --to 10.10.20.32/27
-A POSTROUTING --source 10.10.20.32/27 ! -d 10.0.0.0/8 -j NETMAP --to 128.128.196.32/27

I would also like to exclude public facing IP addresses so that static NAT hosts can still reach the public IP address of another static NAT host on the machine. But multiple negated destinations do not seem to be supported. This throws an error:

*nat
-A PREROUTING --destination 128.128.196.32/27 -j NETMAP --to 10.10.20.32/27
-A POSTROUTING --source 10.10.20.32/27 ! -d 10.0.0.0/8 ! -d 128.128.196.0/24 -j NETMAP --to 128.128.196.32/27

How can I setup iptables to allow static NAT NETMAPed hosts to reach other public addresses on the iptables machine?

1 Answer 1

4

You'll need to use an additional chain, and RETURN before the NETMAP rules.

*nat
-N NETMAP_src101020
-A NETMAP_src101020 -d 10.0.0.0/8 -j RETURN
-A NETMAP_src101020 -d 128.128.196.0/24 -j RETURN
-A NETMAP_src101020 -j NETMAP --to 128.128.196.32/27
-A PREROUTING --source 10.10.20.32/27 -j NETMAP_src101020
-A PREROUTING --destination 128.128.196.32/27 -j NETMAP --to 10.10.20.32/27

So any packets from 10.10.20.32/27 is sent into the NETMAP_src101020 chain. If the packet is destined for 10.0.0.0/8 then we RETURN from that chain; same if the packet is destined to 128.128.196.0/24. Only then does it get to the actual NETMAP rule.

Hope this makes enough sense; I think it's easier to explain by showing you than some long-winded explanation.

2
  • This makes a lot of sense. I will test it out tomorrow.
    – Andy Shinn
    Dec 18, 2012 at 3:12
  • Thanks, this ultimately does do what I asked and answers the question. However, it ultimately didn't fix my underlying problem that I thought was because of this. I will open a new question for my larger problem related to this.
    – Andy Shinn
    Dec 19, 2012 at 18:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .