freeswitch 安装 fail2ban 动态拦截IP攻击

一. 安装 fail2ban

centos: sudo yum install fail2ban

ubuntu: sudo apt install fail2ban

设置开机自启动  systemctl enable fail2ban

启动:  systemctl start fail2ban

二. 配置文件简单介绍

1. fail2ban.conf

fail2ban的基本配置;日志路径,日志级别等

2. jail.conf

jail官方提供的,一些常用服务器的配置默认都是没有enable的;建议不要直接改动, 里面也有个freeswitch的配置,可以参考。

可以在jail.d目录下,就单独的服务在重新配置

官方的文档写到:在配置时,我们应该避免修改由fail2ban安装创建的文件,我们应该去编写具有.local扩展名的新文件。在.local新文件里配置的内容会覆盖jail.conf内容里相同的值

3. filter.d 目录;有各个服务给出的默认过滤配置;其中也有freeswitch.conf 文件;过滤规则可参考

4. jail.d 目录

针对具体过滤的服务的配置。配置文件以.local后缀结尾

注意:centos系统,该目录下有个默认的配置文件,把它删除

三. 增加freeswitch的策略文件

在jail.d 目录下新建freeswitch.local 文件,添加下面内容;也可以根据实际情况进行配置,

这个配置文件是 3600秒(1个小时) 中有5次匹配到 failregex 中的内容,则进行 action  操作;禁止时间为 259200(3天)

[freeswitch]
enabled = true

maxretry  =   4    ; for a total of five failures
findtime  =  3600  ; based on empirical testing
bantime   =  259200  ; ban for 3day (which lets us pick up repeat offenders)

# We do not use 5061 and it is not open to the outside world, so act on 5060 only
port     = 7060


failregex = ^\.\d+ \[WARNING\] sofia_reg\.c:\d+ SIP auth (failure) \((REGISTER|INVITE)\) on sofia profile \'[^']+\' for \[.*\] from ip <HOST>$
            ^\.\d+ \[WARNING\] sofia_reg\.c:\d+ Can't find user \[\d+@\d+\.\d+\.\d+\.\d+\] from <HOST>$

# we do not want mail, so remove that action from standard jail.conf freeswitch config
action   = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
           %(banaction)s[name=%(__name__)s-udp, port="%(port)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]

# Add intrusion log, which contains special string for host (see freeswitch.local filter)
logpath = /usr/local/freeswitch/log/freeswitch.log


 

四. 重启 或者重新加载fail2ban的配置

五:freeswitch 对应的网关文件打开对应配置

我这里是默认的5060端口配置文件 internal.xml;打开

<param name="log-auth-failures" value="true"/>

fail2ban 常用命令:

1. fail2ban-client status freeswitch   #查看当前freeswitch 被禁止的服务器的状态

2. fail2ban-client reload    #重新加载fail2ban配置

3.   ail2ban-client set freeswitch unbanip 1.2.3.4      #设置freeswitch策略,解禁IP 1.2.3.4

发布了10 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/a01021111230/article/details/105645907
今日推荐