0x0034's Blog.

CentOS 7/8 安装fail2ban+iptables预防爆破

字数统计: 162阅读时长: 1 min
2022/01/24

fail2ban

安装epel

  • CentOS7
1
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  • CentOS8
1
2
3
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

安装fail2ban

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
yum install -y fail2ban
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

cat <<EOF > /etc/fail2ban/jail.local
[ssh-iptables]
ignoreip = 127.0.0.1/8 192.168.1.0/24
enabled = true
filter = sshd
action = iptables[name=SSH, port=22, protocol=tcp]
logpath = /var/log/secure
maxretry = 3
findtime = 300
EOF


systemctl enable --now fail2ban

使用fail2ban

1
2
3
4
5
6
7
8
# 查看ssh-iptables状态
fail2ban-client status ssh-iptables

# 取消IP ban
fail2ban-client set ssh-iptables unbanip 23.34.45.56

# IP ban
fail2ban-client set ssh-iptables banip 23.34.45.56
CATALOG
  1. 1. fail2ban
    1. 1.1. 安装epel
    2. 1.2. 安装fail2ban
    3. 1.3. 使用fail2ban