/etc/hosts.allow 与 /etc/hosts.deny的关系

1.概述

  在centos中可以通过配置hosts.allow和hosts.deny这两个文件共同来控制外部对本机的访问权限

/etc/hosts.allow控制可以允许访问本机的IP地址,/etc/hosts.deny控制禁止访问本机的IP。如果两个文件的配置有冲突,以/etc/hosts.allow为准(实际情况可能有误,建议搭环境进行测试)

2.配置优先级

    linux 系统会先检查/etc/hosts.deny规则,再检查/etc/hosts.allow规则,如果有冲突按/etc/hosts.allow规则处理

    下图是我搭建的实验环境,左边部分是在虚拟机centos中配置的/etc/hosts.allow,/etc/hosts.deny ,右边是我用物理机远程链接虚拟机的实验结果。

3.例

1. 只允许 140.116.44.0/255.255.255.0  与 140.116.79.0/255.255.255.0 这两个网段,及 140.116.141.99 这个主机可以进入我们的 telnet 服务器; 此外,其它的 IP 全部都挡掉!

这样则首先可以设定 /etc/hosts.allow 这个档案成为:

[root @test root]# vi /etc/hosts.allow

telnetd: 140.116.44.0/255.255.255.0 : allow

telnetd: 140.116.79.0/255.255.255.0 : allow

telnetd: 140.116.141.99 : allow

再来,设定 /etc/hosts.deny 成为『全部都挡掉』的状态:

[root @test root]# vi /etc/hosts.deny

telnetd: ALL : deny

4.注意修改完后:

    service network restart(centos6)

    systemctl restart network(centos7)

    重启网络服务才能让刚才的更改生效


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容