기술노트

기술노트

게시물 상세
​fail2ban 으로 일정횟수 이상의 접속 실패 IP 차단
작성자 : 관리자(jieun@ehostidc.co.kr)  작성일 : 2018-11-08   조회수 : 4635

fail2ban 으로 일정횟수 이상의 접속 실패 IP 차단

 

CentOS 7 환경

 

1. 저정소 추가 

# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2. 패키지 설치

# yum --enablerepo epel install fail2ban

# systemctl enable fail2ban
# systemctl restart fail2ban  

 

3. 환경 설정

# vi /etc/fail2ban/jail.conf 

# 접속 차단 예외 IP
ignoreip = 127.0.0.1/8 192.168.10.0/24

 

# 접속 차단 시간 default 600초
bantime  = 600

 

# findtime(초) 내에 maxretty 횟수만큼 인증 실패시 차단
findtime  = 60
maxretry = 5

  

4. 별도 설정 파일 ( 별도 파일 생성을 통한 관리)

 # vi /etc/fail2ban/jail.local
[DEFAULT]
bantime = 3600
[sshd]
enabled = true

 

 5. 서비스 확인

    a. iptables 룰셋 확인

 

   b. 전체 상태

# fail2ban-client status 

   c. 서비스별 상태

# fail2ban-client status sshd

   d. ipset 설정(차단) 확인

# ipset --list

   e. fail2ban 로그 확인

awk '($(NF-1) = /Ban/){print $NF}' /var/log/fail2ban.log | sort | uniq -c | sort -n

이전글 CentOS 6 IPTABLES 정리
다음글 [Linux] 서버간 시간 동기화 chrony