검색결과 리스트
글
리눅스(CentOS 5.8)에 Fail2Ban 설치 및 설정하기
Fail2Ban 설치 및 설정
1. http://www.fail2ban.org/wiki/index.php/Downloads 에 들어가서 stable 버전을 다운로드 받아준다.
(2015.01.05 기준으로 stable 다운로드 주소는 https://github.com/fail2ban/fail2ban/archive/0.8.14.tar.gz이다.)
2. 압축을 푼 후 설치한다.
[root@localhost ~] tar
-xvf fail2ban-0.8.14.tar.gz [root@localhost ~] cd fail2ban-0.8.14 [root@localhost ~] python setup.py install [root@localhost ~] cp files/redhat-initd /etc/init.d/fail2ban [root@localhost ~] chkconfig --add fail2ban [root@localhost ~] chkconfig fail2ban on |
3. /etc/fail2ban/jail.conf 설정파일을 수정한다(설정파일에 대한 내용은 구글링을 요함).
단, 96번째 줄에서,
[ssh-iptables] enabled = true # default : false logpath = /var/log/secure #ssh 로그파일 위치를 넣어주면 된다. centos의 경우 /var/log/secure 이다. |
위 사항은 필수적으로 변경해야 한다.
4. fail2ban 서비스를 실행한다.
[root@localhost ~] service fail2ban start Starting fail2ban (via systemctl): [ OK ] |
이렇게 하면 브루트포스 공격에서 벗어날 수 있다. ^ㅇ^
ps. fail2ban 에서 차단당한 아이피를 해제하려면 다음과 같은 명령어를 사용하면 된다.
iptables -D fail2ban-ProFTPD -s xxx.xxx.xxx.xxx -j DROP
iptables -D fail2ban-SSH -s xxx.xxx.xxx.xxx -j DROP
세부 설정 부분…
1> 저장소 추가후 설치
[root@cloud231 ~]# rpm -Uvh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm [root@cloud231 ~]# yum install fail2ban |
2> 설정
[root@cloud231 ~]# cd /etc/fail2ban/ [root@cloud231 ~]# vi jail.conf # 환경 설정을 수정한다.
|
설치하면 기본적으로
[ssh-iptables] enabled= true 이다.
별다른 설정 없이 바로 시작해도 된다.
다른녀석도 시작하고 싶다면.. enabled=true로 만들면 된다.
ignoreip : 체크대상에서 제외할 IP로 관리자 IP를 입력한다. 2개 이상일때는
, 로 구분
CIDR 표기법으로 대역 설정도 가능하다. 192.168.0.1/24
bantime : ban 조건에 걸렸을때 ban 할 시간... 길게 잡어두면 오래 못들어온다.
finditem : 실패횟수를 카운트할 시간범위
maxretry : 맥스 실패 횟수로 ban할 조건.
SSH 모니터링
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
sendmail-whois[name=SSH, dest=알림을받을이메일주소,sender=fail2ban@example.com, sendername="Fail2Ban"]
logpath = /var/log/secure
maxretry = 5
3> 서비스 시작
[root@cloud231 ~]# service fail2ban start
[root@cloud231 ~]# chkconfig | grep fail2ban fail2ban 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@cloud231 ~]# service fail2ban status fail2ban-server (pid 10397) is running... Status |- Number of jail: 1 `- Jail list: ssh-iptables |
# Fail2Ban의 필터에 걸리면 메일을 전송 하도록 설정
필터 내용( 노란색 부분이 메일 전송 설정 부분)
[asterisk-iptables]
enabled = true
filter = asterisk
action = iptables-allports[name=ASTERISK, protocol=all]
sendmail-whois[name=ASTERISK, dest=수신자@mail.com, sender= 발신자@mail.com]
logpath = /var/log/asterisk/messages
maxretry = 5
bantime = 259200