一、概述

在 TCP Wrappers 中,allow 的优先级高于 deny。具体来说:

访问顺序:当一个连接请求到达时,TCP Wrappers 会首先检查 /etc/hosts.allow 文件。如果请求的来源 IP 地址或主机名在 hosts.allow 中被允许,连接就会被允许。

拒绝优先级:如果请求不在 hosts.allow 中,TCP Wrappers 接着检查 /etc/hosts.deny 文件。如果该请求的来源在 hosts.deny 中被拒绝,则连接会被拒绝。

二、TCP Wrappers配置白名单(黑名单同理)

2.1 常用服务名称

#常用服务名称
sshd: 192.168.1.200
ftpd: 192.168.1.200
telnetd: 192.168.1.200
nfsd: 192.168.1.200
httpd: 192.168.1.200
rpc.mountd: 192.168.1.200

#全部服务
ALL: 192.168.1.200

2.2 针对子网配置

sshd: 192.168.1.

2.3 针对主机名

ftpd: trusted-host

2.4 针对多个ip

httpd: 192.168.1.100, 192.168.1.101

2.5 使用通配符

telnetd: 192.168.1.*

2.6 允许本地访问

ALL: 127.0.0.1

2.7 拒绝所有

#所有地白名单配置都需要/etc/hosts.deny中配置默认拒绝
ALL: ALL

三、范例

3.1 nfs白名单

通过TCP Wrappers配置白名单,可以防止非授权用户通过showmount查看nfs共享信息。

#/etc/exports
/home/shared 192.168.1.100(rw,sync,no_subtree_check)
#nfs配置

#/etc/hosts.allow
nfsd: 192.168.1.100
#允许指定IP

#/etc/hosts.deny
nfsd: ALL
#拒绝全部

标签: none

添加新评论