当前位置:网站首页>Linu性能调优:面对DDOS攻击,我们如何缓解局面?
Linu性能调优:面对DDOS攻击,我们如何缓解局面?
2022-07-27 05:22:00 【小小小糖果人】
1、看现象,例如访问连接超时
# --connect-timeout表示连接超时时间
# -w 设置完成后输出的格式
$ curl -w 'Http code: %{http_code}\nTotal time:%{time_total}s\n' -o /dev/null --connect-timeout 10 http://192.168.0.30
...
Http code: 000
Total time:10.001s
curl: (28) Connection timed out after 10000 milliseconds2、检查网络状况
# -n 网络统计
# DEV 网卡 1(代表第一个网卡)
$ sar -n DEV 1
08:55:49 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
08:55:50 docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
08:55:50 eth0 22274.00 629.00 1174.64 37.78 0.00 0.00 0.00 0.02
08:55:50 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.003、利用tcpdump抓包
# -i eth0 只抓取eth0网卡,-n不解析协议名和主机名
# tcp port 80表示只抓取tcp协议并且端口号为80的网络帧
$ tcpdump -i eth0 -n tcp port 80
09:15:48.287047 IP 192.168.0.2.27095 > 192.168.0.30: Flags [S], seq 1288268370, win 512, length 0
09:15:48.287050 IP 192.168.0.2.27131 > 192.168.0.30: Flags [S], seq 2084255254, win 512, length 0
09:15:48.287052 IP 192.168.0.2.27116 > 192.168.0.30: Flags [S], seq 677393791, win 512, length 0
09:15:48.287055 IP 192.168.0.2.27141 > 192.168.0.30: Flags [S], seq 1276451587, win 512, length 0
09:15:48.287068 IP 192.168.0.2.27154 > 192.168.0.30: Flags [S], seq 1851495339, win 512, length 0
...3、利用netstat查看TCP连接状态
# -n表示不解析名字,-p表示显示连接所属进程
$ netstat -n -p | grep SYN_REC
tcp 0 0 192.168.0.30:80 192.168.0.2:12503 SYN_RECV -
tcp 0 0 192.168.0.30:80 192.168.0.2:13502 SYN_RECV -
tcp 0 0 192.168.0.30:80 192.168.0.2:15256 SYN_RECV -
tcp 0 0 192.168.0.30:80 192.168.0.2:18117 SYN_RECV -
...4、统计TCP连接数量
$ netstat -n -p | grep SYN_REC | wc -l
1935、找到攻击源以后,使用防火墙策略,干掉它(缓解途径一)
$ iptables -I INPUT -s 192.168.0.2 -p tcp -j REJECT6、限制TCP发送SYN包的速率(缓解途径二)
# 限制syn并发数为每秒1次
$ iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT
# 限制单个IP在60秒新建立的连接数为10
$ iptables -I INPUT -p tcp --dport 80 --syn -m recent --name SYN_FLOOD --update --seconds 60 --hitcount 10 -j REJECT7、由于目标主机一直无法收到源主机的TCP确认包,导致超时,所以需要增大半开状态连接数量,放置终端无法连接主机,默认是256(缓解途径三)
$ sysctl -w net.ipv4.tcp_max_syn_backlog=1024
net.ipv4.tcp_max_syn_backlog = 10248、由于目标主机等不到源主机的ACK确认包,导致超时,但内核还会自动重试建立连接,默认的重试次数是5次,优化成1次。(缓解途径四)
$ sysctl -w net.ipv4.tcp_synack_retries=1
net.ipv4.tcp_synack_retries = 19、TCP SYN Cookies 也是一种专门防御 SYN Flood 攻击的方法,开启SYN Cookies后,就不需要维护半开连接状态了,进而也就没有了半连接数的限制。注意,开启TCP syncookies,内核 net.ipv4.tcp_max_syn-backlog也就无效了。(缓解途径五)
9.1 临时开启
$ sysctl -w net.ipv4.tcp_syncookies=1
net.ipv4.tcp_syncookies = 19.2 为了保证配置持久化,你还应该把这些配置,写入 /etc/sysctl.conf 文件中,执行 sysctl -p 命令后,才会动态生效。
$ cat /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_max_syn_backlog = 1024边栏推荐
- Dynamic planning for solving problems (6)
- 技术和理论知识学习的一点心得
- Remote sensing image recognition training strategy
- 数据库的约束以及设计
- Thesis writing (harvest)
- 文件内容的读写——数据流
- Brief introduction to unity window interface
- IP core summary
- 通信机制案例
- 5g's past and present life -- a brief introduction to the development of mobile communication
猜你喜欢

Reading and writing of file content - data flow

Remote sensing image recognition training strategy

Related knowledge of multithreading

Code implementation and introduction of all commonly used sorting

IP核之ROM

Remote sensing image recognition imaging synthesis

Unity hub login no response

Unity engine starts to migrate from mono to.Net coreclr

ROS分布式通信

Basic concepts of software testing
随机推荐
socket 长链接
PLL of IP core
允许或者禁止同时连接到一个non-domain和一个domain网络
Li Kou daily question leetcode 513. find the value in the lower left corner of the tree
wireshark数据包修改--添加或修改消息字段(二)
Remote sensing image recognition - making data sets
Dynamic programming for solving problems (7)
Remote sensing image recognition imaging synthesis
Header and source files in ROS
Unity hub login no response
Understand the pointer in a picture
Programming learning records - Lesson 3 [first knowledge of C language]
shell script if嵌套for循环脚本
自动化部署项目
Three ways to get RPM packages using yum
Force deduction problem solving monotonous stack
Random points in non overlapping rectangle (force deduction daily question)
多坐标变换
如何选择正确的服务器备份方法
Ulcl function --5gc