ICMP packets won't go through NAT table
I am using iptables on my NAT gateway but it refuses to apply NAT to any ICMP packets. NAT works correctly for other types of packets. The issue seems to be that ICMP packets don't pass through the 'nat' table at all. They enter and leave the box, without ever seeing the NAT rules.
To demonstrate the problem, I first flushed all my iptables rules, and made sure there was no other filtering running on the gateway. Then, I apply one or more of the following rules:
iptables --table nat --append PREROUTING --protocol icmp --jump LOG --log-prefix "ICMP packet: "
iptables --table nat --append POSTROUTING --protocol icmp --jump LOG --log-prefix "ICMP packet: "
iptables --table nat --append OUTPUT --protocol icmp --jump LOG --log-prefix "ICMP packet: "
I then generate some ICMP packets by pinging or tracerouting either a host accessed via the gateway, or the gateway itself. The packets get through, but they are not logged. And there are no other iptables rules active except the logging ones shown above.
If I apply the same rules to chains in the 'filter' table instead of the 'nat' table, I get packets logged. So if ICMP packets are passing through the filter table and not getting dropped, why isn't the nat table seeing any of these packets?
Again, the problem only seems to occur with ICMP packets, not TCP or UDP.
I am using iptables v1.3.1 on a 2.6.12 kernel.
My apologies if this has been addressed before, I did quite a few different Google searches and haven't come up with anything. Is there a bug, or any likely conflict/configuration option that I might be overlooking?
Thanks,
Glenn
Quoted 4 lines · Glenn Schmidt
I am using iptables on my NAT gateway but it refuses to apply NAT to any ICMP packets. NAT works correctly for other types of packets. The issue seems to be that ICMP packets don't pass through the 'nat' table at all. They enter and leave the box, without ever seeing the NAT rules.
<AFAIK>
There's two class of ICMP packets:
. ICMP requests/replies, such as ping
. ICMP errors
ICMP requests/replies works on a NEW/ESTABLISHED scheme, meaning the request have NEW state and reply ESTABLISHED state.
ICMP errors, if valid (i.e. corresponding to an existing contrack entry), have RELATED state.
Now for NAT table... NAT table only "sees" packets with state NEW. If matched and accepted by filtering rules, an according conntrack entry is created, and following packets are handled transparently by conntrack, meaning both ESTABLISHED and RELATED packets.
</AFAIK>
Now, to partially answer your question, and maybe to refine your observations:
. you won't see ICMP errors in NAT table, which means you won't
see ICMP packets generated by a tracerouting application
. you should see ICMP echo requests, but won't see ICMP echo
replies
I know it does not totally answer your question, but at least, I hope this provides some useful information to you.
Signature · 2 lines
http://sid.rstack.org/ PGP KeyID: 157E98EE FingerPrint: FA62226DA9E72FA8AECAA240008B480E157E98EE
Quoted 2 lines
Quoted 2 lines
Hi! I'm your friendly neighbourhood signature virus. Copy me to your signature file and help me spread!
logging for snat
Hi,
Is it possible to log traffic for a specific postrouting policy that will be snat to somewhere else from a particular interface?
ie. iptables -t nat -I nat POSTROUTING -i eth0 -s 192.168.1.0/255.255.255.0 -d 192.168.22.0/255.255.255.0 -p tcp -m tcp -j SNAT --to-source 192.168.22.215:1-65535
I would like to log the translating address of the above iptables rule. Please advice if that can be done and how.
Thanks,
Peggy