FreePBX | Register | Issues | Wiki | Portal | Support

What is the correct setup for fail2ban?


Did you read the documention about that? it basically reads the fail2ban log itself, and would only ban after in your case ten times the bantime of the underlying jail causing a Ban then an Unban on any particular host .

gcc (the c++ compiler asterisk uses) will compile best effort against the processor it is running under, in a virtualized KVM environment their is no knowledge of the real hardware, just whatever QEMU or whatever you are using presents it, give it a plain old i386 and if it fails to compile, take that up with QEMU or XEN or whatever you are using, if it compiles but doesn’t run, a possibility I guess, then now you can start blaming your hardware, did you try any of that yet? I have and it works under everything I have thrown at it.


Hmm, virtual servers over a TimeWarner residential service? Hardly robust I would have thought :-), what is it like at 4:20 pm when the neighborhood kids all come home?


Yes, but after 50 times now still no one week ban peer the jail rule.

And running fail2ban-regex /var/log/fail2ban.log /etc/fail2ban/filter.d/asterisk.conf produces no matches.

Anyway the box I am discussing now is not a virtual machine. It’s a Pentium 4 and Asterisk 11 would not compile correctly on it. It would get that same error in the bug report I listed above.

(Andrew Nagy) #45

There lies your problem.


Well maybe a Pentium 4 is exceptiinal and won’t work but most will, even the original Pentium MMX :smile:

My install script in a VERY abbreviated form, with a few fail2ban specific debug routines added, which I use after booting machines real or virtual, with :-

cat /proc/cpuinfo;cat /proc/partitions;free
read -p "Here is what you have to work with  . . . . "
apt-get -y install multitail build-essential ncurses-dev libsqlite3-dev libssl-dev python-pyinotify
echo "check_mail:0" >> /etc/multitail.conf
cd /usr/src
tar -zxsvf asterisk-11-current.tar.gz 
cd asterisk-11.10.2/
./configure --disable-xmldoc
make install
make samples
make config
sed -i s'/^;dateformat=%F %T/dateformat=%F %T/' /etc/asterisk/logger.conf
echo  "security = security,notice" >> /etc/asterisk/logger.conf 
service asterisk start &
read -t 10 -p  "Now for fail2ban , press any key or wait a few. . . "
cd /usr/src
tar -zsxvf 0.9.0
cd fail2ban-0.9.0/
python install
sed -i s'/\[asterisk\]/\[asterisk\]\nenabled = true/' /etc/fail2ban/jail.conf 
sed -i s'|/var/log/asterisk/messages|/var/log/asterisk/security|' /etc/fail2ban/jail.conf 
fail2ban-client start;sleep 3
fail2ban-regex /var/log/asterisk/security /etc/fail2ban/filter.d/asterisk.conf 
read -p "Fail2ban should be working now . . . ."
multitail /var/log/asterisk/security /var/log/fail2ban.log /var/log/mail.log

Dollars to donuts it will also work for @GeekBoy also . . .


( for ubiquity :slight_smile: )


So you want me to install Debian on a Ubiquity router??


hehe :smile:

but linux is case sensitive and rather strict about spelling, so that probably wouldn’t work.


Well I tried compiling on CentOS 6.5 in KVM.

That was an EPIC FAIL.

It does not function - as usual in KVM per the bug reported at

First I get Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?)

Okay so I do a asterisk -&

Then asterisk -rvvvvv

sip show peers
No such command ‘sip show peers’ (type ‘core show help sip show’ for other possible commands)

Oh, and in case you are wondering…asterisk.conf

astetcdir => /etc/asterisk
astmoddir => /usr/lib64/asterisk/modules
astvarlibdir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk

(Andrew Nagy) #51

And yet you fail to show us what is actually IN /usr/lib64/asterisk/modules or in modules.conf


well sinc eyou inssit:



 Asterisk Module Loader configuration file

; Any modules that need to be loaded before the Asterisk core has been
; initialized (just after the logger has been initialized) can be loaded
; using 'preload'. This will frequently be needed if you wish to map all
; module configuration files into Realtime storage, since the Realtime
; driver will need to be loaded before the modules using those configuration
; files are initialized.
; An example of loading ODBC support would be:
;preload =>
;preload =>
; As FreePBX is using Local as the channel for queue members we need to make sure
; that and are preloaded. If not, queue members
; will be marked as invalid until app_queue is reloaded.
preload =>
preload =>
; Uncomment the following if you wish to use the Speech Recognition API
;preload =>
; If you want, load the GTK console right away.
; KDE console is obsolete and was removed from Asterisk 2008-01-10
noload =>
;load =>
noload =>
; Intercom application is obsoleted by
; chan_oss.  Don't load it.
noload =>
; DON'T load the, as they are obsolete in * 1.2

noload =>
noload =>
noload =>
noload =>

; Trunkisavail is a broken module supplied by Trixbox
noload =>

; Ensure that format_* modules are loaded before res_musiconhold
;load =>
load =>
load =>

; is removed from Asterisk 1.4 and later, remove ; to enable
;load =>

; This isn't part of 'Asterisk' iteslf, it's part of asterisk-addons. If this isn't
; installed, asterisk will fail to start. But it does need to go here for native MOH
; to work using mp3's.
;       Note that on a system with a high number of calls, using a compressed audio format for
;       musiconhold takes CPU resources. Converting these files to ulaw/alaw makes the job
;       much easier for your CPU.
load =>
load =>
; Load either OSS or ALSA, not both
; By default, load no console driver
noload =>
noload =>
noload =>
noload =>

(Andrew Nagy) #53

and what happens when you try to load manually?


As I indicated in a previous post,You will need libssl-dev or the redhat equivalent as a prerequisite for a bare minimum install to compile chan_sip


It does work if I manually local it. First time I have seen this. SIP is the core module of Asterisk and having to manually load it? I still need to test it I guess.



Fail2ban is , well, failing again. It just started to failing after working so well.
I wonder if it is iptables related issue or what.

I am seeing this in the fail2ban.log:

2014-07-07 05:48:21,235 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp -j fail2ban-PBX-GUI iptables -F fail2ban-PBX-GUI iptables -X fail2ban-PBX-GUI returned 100
2014-07-07 05:48:21,240 fail2ban.jail : INFO Jail 'apache-tcpwrapper’
2014-07-07 05:48:22,186 fail2ban.actions.action: ERROR iptables -D INPUT -p all -j fail2ban-recidive iptables -F fail2ban-recidive iptables -X fail2ban-recidive returned 100
2014-07-07 05:48:22,190 fail2ban.jail : INFO Jail ‘recidive’ stopped
2014-07-07 05:48:23,195 fail2ban.actions.action: ERROR iptables -D INPUT -p all -j fail2ban-PBX-GUI iptables -F fail2ban-PBX-GUI iptables -X fail2ban-PBX-GUI returned 100
2014-07-07 05:48:23,202 fail2ban.jail : INFO Jail ‘pbx-gui’ stopped
2014-07-07 05:48:24,164 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp -m multiport --dports http,https -j fail2ban-BadBots iptables -F fail2ban-BadBots iptables -X fail2ban-BadBots returned 100
2014-07-07 05:48:24,168 fail2ban.jail : INFO Jail 'apache-badbots’
2014-07-07 05:48:24,224 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp --dport ssh -j fail2ban-SSH iptables -F fail2ban-SSH iptables -X fail2ban-SSH returned 100
2014-07-07 05:48:24,301 fail2ban.jail : INFO Jail ‘ssh-iptables’ stopped
2014-07-07 05:48:25,300 fail2ban.actions.action: ERROR iptables -D INPUT -p all -j fail2ban-SIP iptables -F fail2ban-SIP iptables -X fail2ban-SIP returned 100
2014-07-07 05:48:25,304 fail2ban.jail : INFO Jail 'asterisk-iptables’
2014-07-07 05:48:25,363 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp --dport ftp -j fail2ban-FTP iptables -F fail2ban-FTP iptables -X fail2ban-FTP returned 100
2014-07-07 05:48:26,285 fail2ban.jail : INFO Jail 'vsftpd-iptables’
2014-07-07 05:48:26,286 fail2ban.server : INFO Exiting Fail2ban


Did anybody came to the idea to check for a jail.local file?
I had a simular problem and it turned out the freepbx distribution comes with an /etc/jail2ban/jail.local file that overrides everything defined in jail.conf.
Putting the right configuration in the jail.local file solved my problem.


#1 You did not read the entire thread. The problem was running an old Asterisk 1.8.x with an updated fail2ban client. It needed the “security” log option to read it properly, which was not available in Asterisk 1.8.x.

#2 Thread is a bit necro and moot at this point

(Andrew Nagy) #60