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:

-A PREROUTING --destination -j NETMAP --to
-A POSTROUTING --source ! -d -j NETMAP --to

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:

-A PREROUTING --destination -j NETMAP --to
-A POSTROUTING --source ! -d ! -d -j NETMAP --to

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


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

-N NETMAP_src101020
-A NETMAP_src101020 -d -j RETURN
-A NETMAP_src101020 -d -j RETURN
-A NETMAP_src101020 -j NETMAP --to
-A PREROUTING --source -j NETMAP_src101020
-A PREROUTING --destination -j NETMAP --to

So any packets from is sent into the NETMAP_src101020 chain. If the packet is destined for then we RETURN from that chain; same if the packet is destined to 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.

| improve this answer | |
  • This makes a lot of sense. I will test it out tomorrow. – Andy Shinn Dec 18 '12 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 '12 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.