CentOS 8 에 fail2ban 설치하기 및 트러블슈팅(troubleshooting) > 개발

본문 바로가기
사이트 내 전체검색

개발

CentOS 8 에 fail2ban 설치하기 및 트러블슈팅(troubleshooting)

페이지 정보

profile_image
작성자 관리자 (61.♡.26.87)
댓글 0건 조회 3,000회 작성일 19-12-17 21:49

본문

* 참고
https://www.cyberciti.biz/faq/how-to-protect-ssh-with-fail2ban-on-centos-8/


How to install Fail2Ban on CentOS 8
The procedure to set up and configure Fail2ban to secure your server is as follows:

1. Log in to your CentOS 8 server using ssh
2. Enable and install the EPEL repository on CentOS 8, run: # sudo yum install epel-release
3. Install Fail2Ban, run: # sudo yum install fail2ban
4. Configure Fail2ban
5. Enable and start Fail2ban service: # sudo systemctl enable fail2ban && sudo systemctl start fail2ban



ㅁ ipset .. cannot be created .. same name already exists 문제

로그를 보면, 이미 ban 된 ip 가 Found 로 나오는 경우가 있다.
이 현상은, fail2ban 에서는 ban 시켰다고 설정했는데 실제 iptables 에서는 차단되지 않은 경우다.
이유는 여러가지가 있을 수 있으나,
fail2ban 을 실행시에 ipset 관련해서 same name already exists 라는 로그가 남는 경우 해결책이다.

다음 명령어로 ipset 의 모든 SETNAME 을 destroy 시켜 버린다.
# ipset help
# ipset list
# ipset destroy [SETNAME]


위 ipset 및 iptables 관련 문제가 SELinux 때문인줄 알았는데.
SELinux 와 관련 없는 문제로 정리 되면서 아래 내용은 필요 없어졌지만,
나중에 또 삽질을 할 경우를 대비해서 남겨 둔다.



ㅁ fail2ban 재시작

서비스를 재시작 하는 방법은 여러가지가 있을 수 가 있지만,
기본적으로 systemctl 을 이용하는 방법은 서버 부하도 엄청 많이 먹고 재시작 속도도 엄청 느리다.
재시작 로그를 보면, 모든 jail 의 ip 값들을 하나씩 unban 시키고 서비스 재시작 후 다시 하나씩 ban 시킨다.
# systemctl restart fail2ban

ㅇ 설정파일만 다시 읽어 오는 재시작 방법으로 가볍게 reload 할 수 있다.
로그를 보면, 기존 ipset 값들을 unban 시키지 않고 conf 설정 파일만 다시 불러 오는 것을 알수 있다.
# fail2ban-client reload



ㅁ journalmatch 문제

ㅇ fail2ban 을 재시작해보면, 아래와 같은 로그가 남는다.
NOTICE Jail started without ‘journalmatch’ set. Jail regexs will be checked against all journal entries, which is not advised for performance reasons.

ㅇ 해결방법

/etc/fail2ban/jail.d/00-systemd.conf  설정에서
backend 값을 auto 로 변경

* 출처
https://www.digitalwhores.net/2018/11/07/notice-jail-started-without-journalmatch-set-jail-regexs-will-be-checked-against-all-journal-entries/



ㅁ ipset v7.1: Syntax error: '2419200' is out of range 0-2147483

설정에서 bantime 을 높게 설정을 하였더니, 오류가 난다.
말 그대로 범위에 제한이 있는 듯 하다.



ㅁ fail2ban-client 사용법

ㅇ 현재의 JailName 들을 확인
# fail2ban-client status

ㅇ JailName 에 차단된 IP 내역들 확인
# fail2ban-client status sshd




ㅁ 차단된 모든 IP 를 차단 해제 하기

* https://www.basvanbeek.nl/linux/how-to-unban-all-ips-that-fail2ban-blocked/

차단을 해제한다기 보다는, bantime 설정을 짧게 해서 등록된 ip 들을 unban 시켜 버리는 방법이다.

How to unban all IP’s that Fail2Ban blocked
Home » Linux » How to unban all IP’s that Fail2Ban blocked

To unban all IP’s just write this rule it will ban them for 1 second and then unban.

# fail2ban-client set JailName bantime 1
i.e.:
# fail2ban-client set dovecot bantime 1




ㅁ firewalld 관련 오류

fail2ban 은 firewalld 를 이용하여 접근 차단을 제어한다.
그래서, 방화벽 서비스로 firewalld 가 실행되고 있어야 한다.
CentOS 8 기본세팅으로 firewalld 가 사용되지 않는 듯 한데, 서비스로 등록해 주어야 한다.



ㅁ SELinux 관련

http://webs.co.kr/index.php?mid=linux_1&document_srl=3311868

추천0

댓글목록

등록된 댓글이 없습니다.

Total 386건 8 페이지
  • RSS

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.