Fail2ban

From 탱이의 잡동사니
Jump to navigation Jump to search

Overview

Linux 접근 탐지 툴 Fail2ban 사용법 소개.

Installation

$ sudo apt-get install fail2ban

Configuration

단지 fail2ban을 설치만 해도, 대부분의 brute force 공격을 막을 수 있다. 하지만 보다 더 강력한 보안을 원한다면 설정을 변경할 수 있다.

기본 설정파일은 /etc/fail2ban/jail.conf 파일이다.

ignoreip

여기에 설정된 아이피에 대해서는 접근제어를 하지 않는다. 서브넷을 지정하여 네트워크 단위로도 설정이 가능하다.

# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1/8

bantime

특정 호스트가 차단이 될 때, 차단이 되는 시간을 설정한다. 단위(초)

# "bantime" is the number of seconds that a host is banned.
bantime  = 600

findtime, maxretry

최대 시도 횟수 및 시간 범위를 지정한다.

# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime = 600
maxretry = 3

Services

jail.conf 파일에는 즉시 이용할 수 있는 여러가지 서비스 항목들이 설정되어 있다. 기본값은 사용안함으로 설정되어 있지만, enabled 항목을 true 로 변경해주고, fail2ban 을 재시작하기만하면 바로 적용이 된다.

아래는 asterisk 관련 기본설정과 enabled=true 로 설정한 예제이다.

# Multiple jails, 1 per protocol, are necessary ATM:
# see https://github.com/fail2ban/fail2ban/issues/37
[asterisk-tcp]
#enabled  = false
enabled  = true
filter   = asterisk
port     = 5060,5061
protocol = tcp
logpath  = /var/log/asterisk/messages

[asterisk-udp]
#enabled  = false
enabled  = true
filter   = asterisk
port     = 5060,5061
protocol = udp
logpath  = /var/log/asterisk/messages

See also

References

<references />