TCP_Wrappers简介

TCP_Wrappers是工作起来如同TCP守护进程的安全工具。它们能够为systat、finger、FTP、telnet、rlogin、rsh、exec、tftp、talk及其它网络服务监视和过滤进入的请求。

TCP_Wrappers工作原理

TCP_Wrappers有一个TCP的守护进程叫tcpd。以telnet为例,每当有telnet的连接请求时,tcpd即会截获请求,先读取系统管理员所设置的访问控制文件,合乎要求,则会把这次连接原封不动的转给真正的telnet进程,由telnet完成后续工作;如果这次连接发起的ip不符合访问控制文件中的设置,则会中断连接请求,拒绝提供telnet服务。

TCP_Wrappers配置

1、配置文件

TCP_Wrappers的主要配置文件为:/etc/hosts.allow和/etc/hosts.deny。

[root@ts3-142 ~]# cat /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.
#

/usr/sbin/tcpd进程首先检查此文件,如果请求访问的主机名或IP包含在此文件中,则允许访问。

[root@ts3-142 ~]# cat /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!

如果请求访问的主机名或IP不包含在/etc/hosts.allow中,那么tcpd进程就检查/etc/hosts.deny。看请求访问的主机名或IP有没有包含在hosts.deny文件中。如果包含,那么访问就被拒绝;如果既不包含在/etc/hosts.allow中,又不包含在/etc/hosts.deny中,那么此访问也被允许。

2、访问控制规则的格式

访问控制需要加在/etc/hosts.allow和/etc/hosts.deny里,规则格式如下:

<daemon list>:<client list>[:<option>:<option>:...]

daemon list     服务进程名列表,如telnet的服务进程名为in.telnetd
client list     访问控制的客户端列表,可以写域名、主机名或网段,如.trubolinux.com.cn或者192.168.1.
option          可选选项,这里可以是某些命令,也可以是指定的日志文件

3、配置示例

[root@ts3-142 ~]# cat /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.
#
in.telnetd:.turbolinux.com.cn
vsftpd:192.168.0.
sshd:192.168.0.0/255.255.255.0
[root@ts3-142 ~]# cat /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!
ALL:ALL

/etc/hosts.deny里的ALL:ALL表示,除非在/etc/hosts.allow里明确允许访问,否则一律拒绝。
/etc/hosts.allow里第一行in.telnetd:.turbolinux.com.cn表示,只有turbolinux.com.cn这个域里的主机允许访问TELNET服务,注意turbolinux.com.cn前面的那个点(.)。
/etc/hosts.allow里第二行表示,只有192.168.0这个网段的用户允许访问FTP服务,注意0后面的点(.)。
/etc/hosts.allow里第三行表示,只有192.168.0这个网段的用户允许访问SSH服务,注意这里不能写为192.168.0.0/24。虽然在CISCO路由器种这两中写法是等同的。
更多规则格式请参考TCP_Wrappers的MAN PAGE。

 
/www/httpd/html/turbo/wiki/data/pages/network/access_control.txt · 最后更改: 2009/04/23 15:39 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki