经过查看dmesg日志信息,当存在大量以下 的信息,服务器开始响应缓慢并丢失正常的计数数据。这是典型的SYN Flood攻击(或开放半链接攻击)。服务器
[91767.569140] TCP: drop open request from 192.168.50.35/65039 [91767.569145] TCP: drop open request from 192.168.50.35/65040 [91767.569461] TCP: drop open request from 192.168.50.35/65041 [91767.569465] TCP: drop open request from 192.168.50.35/65042 [91767.570107] TCP: drop open request from 192.168.50.35/65043 [91767.589008] TCP: drop open request from 192.168.50.35/65053 [91768.045813] TCP: drop open request from 192.168.50.35/65196
TCP洪水攻击(SYN Flood)dmesg log [260916.826952] TCP: request_sock_TCP: Possible SYN flooding on port 80. Sending cookies. Check SNMP counters.
简单解决办法以下:cookie
一、缩短SYN Timeout时间,因为SYN Flood攻击的效果取决于服务器上保持的SYN半链接数,这个值等于SYN攻击的频度 x SYN
Timeout,因此经过缩短从接收到SYN报文到肯定这个报文无效并丢弃改链接的时间,例如设置为20秒如下(太低的SYN
Timeout设置可能会影响客户的正常访问),能够成倍的下降服务器的负荷。负载均衡
二、设置SYN Cookie,就是给每个请求链接的IP地址分配一个Cookie,若是短期内连续受到某个IP的重复SYN报文,就认定是tcp
受到了攻击,之后从这个IP地址来的包会被丢弃。但有一些参数须要协调配置,才会取到做用,不然会致使另外的问题。spa
建议统一使用下面这些参数:(部分参数根据实际网口修改,本例使用eth0)日志
sysctl -w net.ipv4.conf.eth0.accept_source_route=0 sysctl -w net.ipv4.conf.lo.accept_source_route=0 sysctl -w net.ipv4.conf.default.accept_source_route=0 sysctl -w net.ipv4.conf.all.accept_source_route=0 sysctl -w net.ipv4.tcp_syncookies=1 sysctl -w net.ipv4.conf.eth0.secure_redirects=1 sysctl -w net.ipv4.conf.lo.secure_redirects=1 sysctl -w net.ipv4.conf.default.secure_redirects=1 sysctl -w net.ipv4.conf.all.secure_redirects=1 sysctl -w net.ipv4.conf.eth0.accept_redirects=0 sysctl -w net.ipv4.conf.lo.accept_redirects=0 sysctl -w net.ipv4.conf.default.accept_redirects=0 sysctl -w net.ipv4.conf.all.accept_redirects=0 sysctl -w net.ipv4.conf.eth0.send_redirects=0 sysctl -w net.ipv4.conf.lo.send_redirects=0 sysctl -w net.ipv4.conf.default.send_redirects=0 sysctl -w net.ipv4.conf.all.send_redirects=0 sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1 sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1 sysctl -w net.ipv4.tcp_tw_reuse=1 sysctl -w net.ipv4.tcp_tw_recycle=1 sysctl -w net.ipv4.tcp_fin_timeout=20 #sysctl -w net.ipv4.tcp_fin_timeout=30 sysctl -w net.ipv4.tcp_keepalive_time=1800 sysctl -w net.ipv4.tcp_syn_retries1=1 sysctl -w net.ipv4.tcp_synack_retries=1 sysctl -w net.core.wmem_max=8388608 sysctl -w net.core.rmem_max=8388608 sysctl -w net.ipv4.tcp_rmem="4096 873814 8738140" sysctl -w net.ipv4.tcp_wmem="4096 873814 8738140" sysctl -w net.ipv4.tcp_max_syn_backlog=4096 ifconfig eth0 txqueuelen 1000
但上述的方法只能对付比较原始的SYN Flood攻击,缩短SYN
Timeout时间仅在对方攻击频度不高的状况下生效,SYN
Cookie更依赖于对方使用真实的IP地址,若是攻击者以数万/秒的速度发送SYN报文,同时利用SOCK_RAW随机改写IP报文中的源地址,以上的方法可能用处不大。要防护大规模,高密度的SYN攻击,一个有效的办法使用F5/Alteon等负载均衡设备,采用超过3台服务器的集群来对抗,即:
VIP(F5/Alteon等)--REAL
IP1,REAL IP2,REAL IP3....
一方面,负载均衡设备的高效链接管理能够应对一些SYN
Flood攻击,同时多台服务器的包处理能力大大加强,结合每台服务器改善的SYN Flood处理能力,彻底能够应对这种大规模、高密度的SYN Flood攻击。code