测试环境:linux centos6.5
1、hosts.allow文件配置:
修改/etc/hosts.allow文件
## hosts.allow This file describes the names of the hosts which are# allowed to use the local INET services, as decided# by the ‘/usr/sbin/tcpd’ server.#sshd:210.13.218.*:allowsshd:222.77.15.*:allow以上写法表示允许210和222两个ip段连接sshd服务(这必然需要和hosts.deny这个文件配合使用),当然“:allow” 完全可以省略的。当然如果管理员集中在一个IP那么这样写是比较省事的all:218.24.129.110//他表示接受110这个ip的所有请求!
2、hosts.deny文件配置
/etc/hosts.deny文件,此文件是拒绝服务列表,文件内容如下:## hosts.deny This file describes the names of the hosts which are# *not* allowed to use the local INET services, as decided# by the ‘/usr/sbin/tcpd’ server.## The portmap line is redundant, but it is left to remind you that# the new secure portmap uses hosts.deny and hosts.allow. In particular# you should know that NFS uses portmap!sshd:all:deny注意看:sshd:all:deny表示拒绝了所有sshd远程连接。:deny可以省略。所以:当hosts.allow和 host.deny相冲突时,以hosts.allow设置为准。修改完成后立刻生效。
3、扩展:
1.禁止所有ip访问linux 的ssh功能可以在/etc/hosts.deny添加一行 sshd:all:deny2.禁止某一个ip(192.168.11.112)访问ssh功能
可以在/etc/hosts.deny添加一行sshd:192.168.11.1123.如果在/etc/hosts.deny和/etc/hosts.allow同时 有sshd:192.168.11.112 规则,则192.168.11.112可以访问主机的ssh服务
总结:通过这种方法可以控制部分非授权访问,但不是一劳永逸的方法!我们在看服务日志的时候或许会看到很多扫描记录,不是还是直接针对root用户的,这时控制你的访问列表就非常有作用了!