Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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