我在我的ubuntu10.04.04服务器上使用/etc/hosts.deny和ufw的组合。大多数时候,我看到.com.cn域中机器的ssh尝试失败,报告如下:
Failed logins from:
112.114.63.139 (139.63.114.112.broad.km.yn.dynamic.163data.com.cn): 1 time但是,在/etc/hosts.deny中,我有这样的规则:
ALL: .com.cn这难道不应该在连接命中ssh之前就阻止它吗?我已经通过阻塞我的主机来测试它,在我获得登录提示之前,它肯定会拒绝我一个连接(是的,我已经把ssh键移开了,所以这些键都不涉及)。
这是否如预期的那样?
编辑:促使我更仔细地查看日志,也许我知道为什么会发生这种情况。来自auth.log:
Nov 5 09:38:40 mymachine sshd[22864]: warning: /etc/hosts.deny, line 21: can't verify hostname: getaddrinfo(139.63.114.112.broad.km.yn.dynamic.163data.com.cn, AF_INET) failed
Nov 5 09:38:44 mymachine sshd[22864]: reverse mapping checking getaddrinfo for 139.63.114.112.broad.km.yn.dynamic.163data.com.cn [112.114.63.139] failed - POSSIBLE BREAK-IN ATTEMPT!
Nov 5 09:38:45 mymachine sshd[22864]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=112.114.63.139 user=root
Nov 5 09:38:47 mymachine sshd[22864]: Failed password for root from 112.114.63.139 port 37245 ssh2
Nov 5 09:38:47 mymachine sshd[22866]: Connection closed by 112.114.63.139这对我来说意味着,如果sshd不确定IP->名称查找,那么它就会犯错误,而且不会阻止该主机。是那么回事吗?
发布于 2012-11-01 17:29:15
这对于sshd来说是预期的,因为它直接链接到libwrap,所以sshd实际上是执行主机检查的。如果要在调用sshd之前阻止连接,则需要在其前面放置一些东西来处理连接尝试,然后再将其传递给sshd。有几个选择是:
only_from和no_access服务选项,这些选项提供与/etc/hosts.low和/etc/hosts.deny类似的功能。但是,sshd手册阻止了这些方法,尽管:
-i Specifies that sshd is being run from inetd(8). sshd is normally
not run from inetd because it needs to generate the server key
before it can respond to the client, and this may take tens of
seconds. Clients would have to wait too long if the key was
regenerated every time. However, with small key sizes (e.g. 512)
using sshd from inetd may be feasible.使用iptables或在服务器前面放置防火墙似乎是一个不错的选择,但大多数不执行任何名称解析,因此您仅限于通过IP地址控制访问。这不一定是一件坏事,但对你想要完成的事情没有帮助。
https://serverfault.com/questions/444431
复制相似问题