IPTables - SMTP rate limit

All things firewall related..

IPTables - SMTP rate limit

Postby NomadCF on Fri Mar 13, 2009 4:02 pm

3 connections PER incoming address excluding your Network.

Code: Select all
#!/bin/bash
IPTABLES=/sbin/iptables
MyNetWork=10.0.0.0/255.0.0.0

$IPTABLES -N SMTP_Remote_Limit_Block
$IPTABLES -F SMTP_Remote_Limit_Block
$IPTABLES -A SMTP_Remote_Limit_Block -j LOG --log-ip-options --log-prefix "IPT:SMTP:Remote:Block "
$IPTABLES -A SMTP_Remote_Limit_Block -j DROP

$IPTABLES -N SMTP_Remote_Limit
$IPTABLES -F SMTP_Remote_Limit
$IPTABLES -A SMTP_Remote_Limit -m state --state ! NEW,INVALID -j ACCEPT
$IPTABLES -A SMTP_Remote_Limit -m state --state NEW -j LOG --log-ip-options --log-prefix "IPT:SMTP:Remote:New "
$IPTABLES -A SMTP_Remote_Limit -m state --state NEW -m recent --set --name SMTP_Remote_Limit
$IPTABLES -A SMTP_Remote_Limit -m recent --update --name SMTP_Remote_Limit --seconds 60 --hitcount 3 -j SMTP_Remote_Limit_Block
$IPTABLES -A SMTP_Remote_Limit -j LOG --log-ip-options --log-prefix "IPT:SMTP:Remote:Allow "
$IPTABLES -A SMTP_Remote_Limit -j ACCEPT
$IPTABLES -A INPUT -p tcp -s ! $MyNetWork \--dport 25 -j SMTP_Remote_Limit
$IPTABLES -A INPUT -p tcp --dport 25 -j ACCEPT
NomadCF
Site Admin
 
Posts: 33
Joined: Sat Mar 22, 2008 11:21 am

Return to firewalls

Who is online

Users browsing this forum: No registered users and 1 guest

cron