限制NFS访问,设置hosts.allow和hostsdeny

 配置优先级说明:

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

1、添加允许访问信息(该配置优先生效)

vim /etc/hosts.allow

#配置/etc/hosts.allow文件允许192.168.2.23访问nfs
portmap:192.168.2.23
lockd:192.168.2.23
rquotad:192.168.2.23
mountd:192.168.2.23
statd:192.168.2.23

sshd:192.168.2.* #允许192.168.2.*网段通过ssh访问Linux

in.telnetd:192.168.2.24 #允许192.168.2.24通过telnet访问Linux

2、添加禁止访问信息

vim /etc/hosts.deny

#配置/etc/hosts.deny禁止所有用户访nfs的守护进程
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL

showmount:ALL #拒绝所有IP通过showmount访问Linux

sshd:ALL #拒绝所有IP通过ssh访问Linux
sshd:192.168.11.12 #拒绝192.168.11.12地址通过ssh访问Linux的

in.telnetd:ALL #拒绝所有IP通过telnet访问Linux

#ALL:deny #拒绝所有访问,一般情况下不要配置,会造成服务器无法访问

3、hosts.allow和hostsdeny配置后立即生效,不生效需要重启对应服务

#showmount配置不生效,则重启rpcbind、nfs服务
service rpcbind restart
service nfs restart

#sshd配置不生效,则尝试重启sshd、network服务
service sshd restart
#service network restart

#telnet配置不生效,则重启xinetd服务
service xinetd restart

说明:

1.一个IP请求连入,linux的检查策略是先看/etc/hosts.allow中是否允许,如果允许直接放行;如果没有,则再看/etc/hosts.deny中是否禁止,如果禁止那么就禁止连入。

2.实验发现对/etc/hosts.allow和/etc/hosts.deny的配置不用重启就立即生效,但不管重启不重启当前已有会话都不会受影响;也就是说对之前已经连入的,即便IP已配置为禁止登录会话仍不会强制断开。不过不知是否所有Linux都一样,由此第3步标为可选。

3.网上发现有些教程写成不是sshd而是in.sshd不是in.telnetd而是telnetd的,个人觉得应该是独立启的不用加in.托管于xinetd的需要加in。

编辑于 2022-03-30 11:08
 
转载于:https://zhuanlan.zhihu.com/p/478391264
 
posted @ 2022-08-23 21:29  李朋_Wechat  阅读(621)  评论(0编辑  收藏  举报