사용자 도구

사이트 도구


freebsd:py-fail2ban

py-fail2ban 0.11 설치

cd /usr/ports/security/py-fail2ban
make config
make all install clean

설치한 다음에 나오는 중요한 정보

아래 설정은 https://phrye.com/tools/fail2ban-on-freebsd/를 보고 따라한 것이다.

먼저 /usr/local/etc/ipfw.rules 를 다음 내용으로 만들어 준다.

# Initial setting
/bin/sh /etc/rc.firewall open

# fail2ban IPs
if ! ipfw table 1 info > /dev/null 2>&1; then
  ipfw table 1 create
  ipfw table 1 flush
fi
ipfw add 1 deny ip from "table(1)" to me

그런 다음 /usr/local/etc/fail2ban/jail.local 를 만든다.

cd /usr/local/etc/fail2ban
cp -Rp jail.conf jail.local

jai.local 에 다음 내용을 확인한다.

[sshd]
enabled = true
mode = aggressive
action = ipfw-table[name=SSH,port=ssh,protocol=tcp]
logpath = %(sshd_log)s
backend = %(sshd_backend)s
maxretry = 3
findtime = 600
bantime = 3600

이제 /usr/local/etc/fail2ban/action.d/ipfw-table.local 을 다음과 같은 내용으로 만든다.

[Definition]
actionstart =
actionstop =
actioncheck =
actionban = ipfw table 1 add <ip>
actionunban = ipfw table 1 delete <ip>

마지막으로 /etc/rc.conf 에 아래 명령어로 fail2ban과 방화벽에 관한 내용을 더한다.

sysrc fail2ban_enable="YES"
sysrc firewall_enable="YES"
sysrc firewall_type="OPEN"
sysrc firewall_script="/usr/local/etc/ipfw.rules"

이제 이 설정을 실행한다. 실행 전에, 방화벽 설정을 경험상 현재 접속한 계정에서 튕겨져 나가져 접속을 다시 못할 수도 있으니 설정에 주의에 주의를 요한다.

service ipfw start
service fail2ban start

마지막으로 제대로 설치되어 주어진 일을 하는지는 다음 명령어로 실행해서 알아볼 수 있다.

fail2ban-client status sshd
Status for the jail: sshd
|- Filter
|  |- Currently failed: 9
|  |- Total failed:     9
|  `- File list:        /var/log/auth.log
`- Actions
   |- Currently banned: 3
   |- Total banned:     3
   `- Banned IP list:   207.119.191.239 71.221.84.13 75.170.123.224

그리고 ipfw show 에서 다음 줄이 보이연 제대로 작동하는 거다.

00001      0         0 deny ip from table(1) to me
freebsd/py-fail2ban.txt · 마지막으로 수정됨: 2021/01/10 09:07 저자 127.0.0.1