3 ms·
Start with the basics: iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT Allow loopback, icmp: iptables -A INPUT -i lo -m comment --commen
by 0xbadcafebee 5y ago
Start with the basics:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Allow loopback, icmp:
iptables -A INPUT -i lo -m comment --comment "Allow loopback connections" -j ACCEPT
iptables -A INPUT -p icmp -m comment --comment "Allow ICMP packets" -j ACCEPT
Limit ssh connections to 5 per minute, per source ipv4 host:
iptables -A INPUT -i eth0 -p tcp --syn --dport 22 -m connlimit --connlimit-above 5 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
Set maximum number of ssh connections to 100:
iptables -t filter -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 100 -j DROP
Limit to only 5 new connections per second (This is what you probably want, ala Fail2ban):
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --set
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 5 --name SSH --rsource -j DROP
Limit https connections to 150/second, after a burst of 300/second. Beware: once the limit is reached, I don't think it gets reset.
iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state RELATED,ESTABLISHED -m limit --limit 150/second --limit-burst 300 -j ACCEPT
Similar limit, but with hashlimit module:
iptables -A INPUT -i eth0 -p tcp --dport 443 -m hashlimit --hashlimit-name HTTPS --hashlimit-mode srcip --hashlimit 1/s --hashlimit-burst 300 -j ACCEPT
Don't forget to drop everything else:
iptables -A INPUT -i eth0 -j DROP
- tambourine_man 5y agoNice, thanks!