昨晚一直覺得上網整個變得卡頓卡頓,查了一下一直有 CN 大量 IP 連入 3wa 爬資料
也不是說不讓看,只是大量網段一直連
把 40M 上傳打到剩 10M 上傳,上網也從 10ms 內的反應速度變成 30~50ms 有時還會爆高
針對 apache2 來訪 log 採最近 5min 紀錄,可以列出哪些 ip 連入,並用 whois 查詢該國家
同時也收集 user-agent
針對有些惡意掃站、偷抓環境檔、或注入攻擊的行為作收集
fail2ban 也一起使用
# apt install fail2ban
# systemctl enable fail2ban
# systemctl start fail2ban
# vim /etc/fail2ban/filter.d/apache-abuse.conf
[Definition]
# 這裡抓所有 HTTP 請求行為,主要用來計數 flood / scan
# <HOST> 會被 fail2ban 替換成 IP
failregex = ^<HOST> .* "(GET|POST|HEAD|PUT|DELETE|OPTIONS|TRACE)"
# 如果有想排除的 IP 或 pattern 可以寫在這
ignoreregex =
# vim /etc/fail2ban/jail.d/apache-abuse.conf
[apache-abuse]
enabled = true
port = http,https
filter = apache-abuse
logpath = /var/log/apache2/access.log
maxretry = 300
findtime = 60
bantime = 3600
action = iptables[name=apache-abuse, port="http,https", protocol=tcp]
ignoreip = 127.0.0.1/8 ::1 192.168.0.0/16 211.20.175.0/24
# 載入設定
# fail2ban-client reload
# 查看狀況
# fail2ban-client status apache-abuse
近期從 1/9 以後就有微量的流量攻擊,阻斷後再觀察看看

把一些網攻的來源 ban 掉後,上行又恢復到 40M 了,網路順暢

最後再加入 ipsum 大於 3 分的示警 IP,網路的延遲跟順暢度又回歸了
相當舒服