站长资源操作系统

CentOS下iptables封IP的命令讲解

整理:jimmy2025/1/11浏览2
简介查看当天登陆未成功的IP一条命令把这些IP全部封掉:for i in `grep "$(date +"%b %d")" /var/log/secure | grep "Failed password" | awk '{print $(NF-3)}' | sort | uniq -c | sort

查看当天登陆未成功的IP

CentOS下iptables封IP的命令讲解

一条命令把这些IP全部封掉:

for i in `grep "$(date +"%b %d")" /var/log/secure | grep "Failed password" | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr| awk '{print $2}'` ;do iptables -A INPUT -s $i -j DROP; done

效果:

CentOS下iptables封IP的命令讲解