I am using the following simple iptables rule that accepts related packets:
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
I am letting ICMP echo-requests pass with this other rule:
-A INPUT -p icmp --icmp-type echo-request -j ACCEPT
Should I explicitly add anything to receive "useful" ICMP messages like destination-unreachable
, time-exceeded
and parameter-problem
, or the RELATED
clause will already accept them?
http://www.linuxtopia.org/Linux_Firewall_iptables/x1571.html
The RELATED rule will take care of the associated ICMP messages by default. From iptables man page, in the section related to conntrack (http://linux.die.net/man/8/iptables):
Other states reported by conntrack are:
You can examine and manage the conntrack table using the
conntrack
package.In general is a very bad idea to filter or block icmp, usually the only "valid" bit of icmp to filter is echo-request to "appear" down in a naïve scan.
But if you want to explicit allow parts of it you are missing at least two very important bits, fragmentation needed & Source Quench:
Let me tell you again that filtering icmp is a bad idea that will mask problems and make it difficult to discover.
That was the problem with DF (don't fragment) and fragmentation-needed which is needed for automatic PTMU discovery and caused sites to be inaccessible because intermediate firewalls/routers dropped the icmp packets advertising the endpoint to lower the MTU.
I'll add my own answer to provide my final configuration, inspired by other answers and the following sources:
an expired draft by IETF with a useful table which shows which ICMP types allow, deny or rate limit;
another page with the minimum lines for iptables and Cisco IOS;
a third resource which uses
RELATED
:ICMP is a very important connection protocol. The "echo-request" is the only important useful message that helps communication. Rest of them including "destination-unreachable" is safe to block specially if the application you're running receives a large number of unknown hits.
You're better off with something like this,
This would not only accept "echo-request" but also block ping floods greater than 30 packets/s. Anything else you want to add has to explicitly be accepted because the RELATED clause will not receive them as long as the connection is established by letting it in.