Saturday, February 11, 2012

Install Fail2ban in CentOS 5 (fail2ban)

1. Download and Install

wget http://sourceforge.net/projects/fail2ban/files/fail2ban-stable/fail2ban-0.8.4/fail2ban-0.8.4.tar.bz2
tar -xjvf fail2ban-0.8.4.tar.bz2
cd fail2ban-0.8.4
python setup.py install

2. Edit jail.conf

vi /etc/fail2ban/jail.conf

----------//---------

[DEFAULT]

# "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 192.168.1.0/24 <--------- ์—ฌ๊ธฐ์— ์ง€์ •๋œ ์ฃผ์†Œ๋Š” fail2ban์˜ํ•ด ๋ฐด๋‹นํ•˜์ง€ ์•Š๋Š”๋‹ค

# "bantime" is the number of seconds that a host is banned.
bantime  = 84600 <-------- 24์‹œ๊ฐ„์œผ๋กœ ๋ณ€๊ฒฝ. ํ•ด๋‹น ํ˜ธ์ŠคํŠธ๊ฐ€ ๋ฐด๋˜๋Š” ์‹œ๊ฐ„ (๊ธฐ๋ณธ 600)

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

# "maxretry" is the number of failures before a host get banned.
maxretry = 3  <------- ์œ„์˜ faindtime ์‹œ๊ฐ„์•ˆ์— maxretry ํšŸ์ˆ˜๋งŒํผ ๋กœ๊ทธ์ธ ์‹คํŒจ์‹œ ๋ฐด (๊ธฐ๋ณธ 3)

......

[ssh-iptables]

enabled  = true <-------- sshd์— ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด true๋กœ ๋ณ€๊ฒฝ
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
           sendmail-whois[name=SSH, dest=you@mail.com, sender=fail2ban@mail.com]
logpath  = /var/log/secure <------------ sshd.log์—์„œ secure๋กœ ๋ณ€๊ฒฝ
maxretry = 5   <-------- ๋ณ€๊ฒฝ์‹œ ์—ฌ๊ธฐ์— ์žˆ๋Š” ๊ฐ’์ด ์œ„์˜ default 'maxretry' ๊ฐ’๋ณด๋‹ค ์šฐ์„ ์‹œ ๋œ๋‹ค 

----------//---------

3. Copy start script and start service

cp files/redhat-initd /etc/init.d/fail2ban
chkconfig --add fail2ban
chkconfig fail2ban on
service fail2ban start
Engineering Studio — free local tools

SKP Engineering Labs

Local browser utilities. No input is sent to a server.