1.先安裝套件庫

   yum install epel-release

   參考:http://kirby86a.pixnet.net/blog/post/118589751-centos-linux-release-7.5.1804-%E5%AE%89%E8%A3%9D%E5%A5%97%E4%BB%B6%E5%BA%AB

2.安裝支援支援firewalld的fail2ban

   yum install fail2ban-firewalld fail2ban-systemd fail2ban-server fail2ban-sendmail

3.新增參數檔

  複製預設參數檔為jail.local ,避免更新後jail.conf和fail2ban.con被覆蓋

  cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

4.設定參數檔

   (1)vi /etc/fail2ban/jail.local

   (2)保護sshd機制預設不啟動,啟用sshd保護機制,找到 [sshd] 字樣,於下方加上enabled = true

      [sshd]

      enabled = true

    (3) 修改封鎖IP時間,單位是秒,預設為600秒,請修改為你喜歡的秒數,範例修改為86400 秒(24小時)

         bantime = 86400

    (4)修改檢測時間,在此時間內登入帳號失敗超過maxretry規定的次數會啟用Fail2ban封鎖IP,單位是秒 ,預設為600秒

        findtime = 60

    (5)修改嘗試次數,此參數搭配findtime,預設值為5

        maxretry = 3

5.設定開機啟動fail2ban

  sudo systemctl enable fail2ban

6.啟動fail2ban

  sudo systemctl start fail2ban

7.常用指令:

  (1)檢查fail2ban執行狀態

    fail2ban-client status

  (2)檢查fail2ban sshd防護執行狀態

   fail2ban-client status sshd

  (3)解除被封鎖IP

     fail2ban-client set sshd unbanip 被封鎖的ip

  (4)封鎖ip

      fail2ban-client set sshd banip 要封鎖的ip

   其他指令說明:http://www.fail2ban.org/wiki/index.php/Commands

 8.記錄檔:

  /var/log/fail2ban.log

9.其他功能設定

   (1)編輯v3/etc/fail2ban/jail.local

   (2)設定電子郵件MTA為postfix 預設為sendmail

     mta = postfix

參考資料:

Fail2ban

arrow
arrow
    文章標籤
    CENTOS 7 fail2ban sshd
    全站熱搜

    K 發表在 痞客邦 留言(0) 人氣()