$ sudo sysctl -a | grep ipv4 | grep syn
输出类似下面:
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_syn_retries = 5
把如下加入到/etc/sysctl.conf即可,之后执行“sysctl -p”!
net.ipv4.tcp_synCOOKIEs = 1
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
提高TCP连接能力
net.ipv4.tcp_rmem = 32768
net.ipv4.tcp_wmem = 32768
net.ipv4.sack=0
命令:
# netstat -an | grep ":80" | grep ESTABLISHED
来查看哪些IP可疑~比如:221.238.196.83这个ip连接较多,并很可疑,并不希望它再次与221.238.196.81有连接。可使用命令:
iptables -A INPUT -s 221.238.196.81 -p tcp -d 221.238.196.83 --dport 25 --syn -j ACCEPT
将其deny。
防止同步包洪水(Sync Flood)
# iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
也有人写作
# iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT
--limit 1/s 限制syn并发数每秒1次,可以根据自己的需要修改防止各种端口扫描
# iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
Ping洪水攻击(Ping of Death)
# iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
运行:
sysctl net.inet.tcp.msl=7500
为了重启有效,可以将下面折行加入 /etc/sysctl.conf:
net.inet.tcp.msl=7500