如何查看被阻止的主机列表
执行以下cat命令:
$ sudo cat /etc/hosts.deny
另一种方法是使用iptables命令查看被阻止的IP地址:
$ sudo iptables -L INPUT -n -v $ sudo iptables -L INPUT -n -v | more $ sudo iptables -L INPUT -n -v | grep DROP
配置denyhosts
默认的运行模式是守护程序模式,配置文件是/etc/denyhosts.conf
:
$ sudo vi /etc/denyhosts.conf
确保将SECURE_LOG设置如下:
SECURE_LOG = /var/log/auth.log
HOSTS_DENY设置如下:
HOSTS_DENY = /etc/hosts.deny
只阻止sshd:
BLOCK_SERVICE = sshd
设置登录尝试的拒绝阈值:
DENY_THRESHOLD_INVALID = 5 DENY_THRESHOLD_VALID = 10 DENY_THRESHOLD_ROOT = 1 DENY_THRESHOLD_RESTRICTED = 1
要使用Linux防火墙IPTABLES阻止传入连接,则设置如下:
IPTABLES = /sbin/iptables
重启denyhosts服务
在Ubuntu Linux 16.04 LTS或更高版本上执行以下命令:
$ sudo systemctl restart denyhosts.service
对于较旧的Ubuntu/Debian Linux系统,则执行:
$ sudo /etc/init.d/denyhosts restart
设置denyhosts服务开机自启动
执行以下命令:
$ sudo systemctl enable denyhosts.service
如何启动denyhosts服务?
在Ubuntu Linux 16.04 LTS+上:
$ sudo systemctl start denyhosts.service
在较旧的Ubuntu/Debian Linux系统上:
$ sudo /etc/init.d/denyhosts start
如何停止denyhosts服务?
在Ubuntu Linux 16.04 LTS+上:
$ sudo systemctl stop denyhosts.service
在较旧的Ubuntu/Debian Linux系统上:
$ sudo /etc/init.d/denyhosts stop
安装denyhosts
在Ubuntu Linux上执行以下apt-get命令或apt命令,安装denyhosts:
$ sudo apt-get install denyhosts
或者
$ sudo apt install denyhosts
将管理者自己的IP地址列入白名单
编辑/etc/hosts.allow
文件,并添加您的客户端IP地址。
$ sudo vi /etc/hosts.allow
语法如下:
sshd: whitelist-ip1, whitelist-ip2, ...., whitelist-ipN
监控denyhosts日志文件
日志文件是我们之前设定的/var/log/denyhosts
$ sudo tail -f /var/log/denyhosts
DenyHosts是一个python写的入侵防护安全工具。其旨在通过在/etc/hosts.deny文件中添加条目或者使用iptables来阻止系统被ssh暴力破解。
日期:2020-03-23 08:03:54 来源:oir作者:oir