TCP wrappers 是主机存取控制列表系统, 作用是限制 IP, hostname 存取 TCP 网络。TCP wrappers 透过以下两个设定档设定过滤的 IP:
/etc/hosts.allow
/etc/hosts.deny
当客户端尝试从远端连线时, 以从上面两个档案读取规则, 决定客户端的连线是允许还是禁止。设定 /etc/hosts.allow 及 /etc/hosts.deny 的格式是这样:
上面三个字段的意思是:
daemon_list: 设定的 daemons, 用逗号 (,) 分隔每个 daemons, 用 ALL 代表全部 daemons.
client_list: 客户端的 IP, 同样用逗号 (,) 分隔, ALL 代表全部 IP.
command: 当客户端符合以上规则存取网络时, 需要执行的指令, 可选择是否填写.
将要允许存取网络的 IP 或 hostname 加入 /etc/hosts.allow, 而禁止存取网络的 IP 或 hostname 加入 /etc/hosts.deny.
首先 /etc/hosts.allow 会由上面下逐行被读取, 当有 IP 符合规则, 便可以存取, 当没有匹配的 IP, 则会开始逐行读取 /etc/hosts.deny 的内容, 如果有匹配的内容, 便会禁止存取。当 /etc/hosts.deny 没有匹配, 或者 /etc/hosts.deny 档案不存在, 便可以存取.
由于 /etc/hosts.allow 会先被读取, 所以 /etc/hosts.allow 的设定会优先于 /etc/hosts.deny. 所以如果同一 IP 同时加入到 /etc/hosts.allow 及 /etc/hosts.deny, 这个 IP 同样可以存取服务.
以下是 /etc/hosts.allow 及 /etc/hosts.deny 的常用例子:
/etc/hosts.allow
允许 192.168.1.100 存取 SSH:
允许 192.168.1.* 存取 FTP, 以下假设 daemon 是 vsftpd:
/etc/hosts.deny
禁止所有 IP 存取 FTP: