Wednesday, August 17, 2011

iptables hashlimit

To limit number of incoming connection we can use hashlimit module of iptables. Initially it looks diffcult to implement but its very self explanatory. I here shared a simple example to implement hashlimit.
iptables limiting ssh connection to 1 connection (--hashlimit 2/sec -j Drop) on the basis of source ip (--hashlimit-mode srcip). Hashlimit keep track of connection in a table, that table will created inside /proc/net/ipt_hashlimit. Name of table in example is dropssh (--hashlimit-name dropssh).