早期系统中使用的inetd被称做超级服务器,其实现控制对主机网络链接。当一个请求到达由inetd管理的服务端口,inetd将该请求转发给名为 tcpd的程序。tcpd根据配置文件host.{allow,deny}来判断是否容许服务该请求,若是请求被容许刚相应的服务器程序(如:ftpd、 telnet)将被启动。这个机制也被称为
TCP_Wrapper。
xinetd(eXended Internet services Daemon)提供相似于inetd+tcp_wrapper的功能,可是更增强大和安全。已经逐渐取代了inetd,而且提供了访问控制、增强的日志和资源管理功能,成了Linux系统的Internet标准超级守护进程。不少系统服务都用到了xinetd如:FTP、IMAP、POP和telnet等。/etc/services中全部的服务经过他们的端口来访问服务器的时候,先由xinetd来处理,在唤起服务请求以前,xinetd先检验请求者是否知足配置文件中指定的访问控制规则,当前的访问是否超过了指定的同时访问数目,还有配置文件中指定的其余规则等,检查经过,xinetd将这个请求交付到相应的服务去处理,本身就进入sleep状态,等待下一个请求的处理。
以telnet为例,每当有telnet的链接请求时,tcpd即会截获请求,先读取系统管理员所设置的访问控制文件,合乎要求,则会把此次链接原封不动的转给真正的telnet进程,由telnet完成后续工做;若是此次链接发起的ip不符合访问控制文件中的设置,则会中断链接请求,拒绝提供telnet服务。
#
ldd $(which Command) | grep wrap
"查看是否支持TCP Wrapper的服务"
[root@rhel6 ~]# ldd `which vsftpd` | grep wrap
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f58c2cdd000) "有返回值则表示支持TCP_Wrapper"
[root@rhel6 ~]# ldd `which sshd` | grep wrap
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007fdbbc848000)
·
配置文件
TCP_Wrappers
的主要配置文件为:
/etc/hosts.allow
和
/etc/hosts.deny
。
/usr/sbin/tcpd进程首先检查/etc/hosts.allow,若是请求访问的主机名或IP包含在此文件中,则容许访问。
若是请求访问的主机名或IP不包含在/etc/hosts.allow中,那么tcpd进程就检查/etc/hosts.deny。若是请求访问的主机名或IP包含在hosts.deny文件中,则访问就被拒绝;
若是都没有,默认许可
·
访问控制规则的格式
访问控制须要加在
/etc/hosts.allow
和
/etc/hosts.deny
里,规则格式以下:
<
daemon list
>:<
client list
>[:<option>:<option>:...]
daemon list
服务进程名列表,如
telnet
的服务进程名为
in.telnetd
client list
访问控制的客户端列表,能够写域名、主机名或网段,如
.example.com
或者
192.168.1.
option
可选选项,这里能够是某些命令,也能够是指定的日志文件
- [root@rhel6 ~]# cat /etc/hosts.allow
- #
- # hosts.allow This file contains access rules which are used to
- # allow or deny connections to network services that
- # either use the tcp_wrappers library or that have been
- # started through a tcp_wrappers-enabled xinetd.
- #
- # See 'man 5 hosts_options' and 'man 5 hosts_access'
- # for information on rule syntax.
- # See 'man tcpd' for information on tcp_wrappers
- in.telnetd:.xfcy.org
- vsftpd:192.168.0.
- sshd:192.168.0.0/255.255.255.0
-
- [root@rhel6 ~]# cat /etc/hosts.deny
- #
- # hosts.deny This file contains access rules which are used to
- # deny connections to network services that either use
- # the tcp_wrappers library or that have been
- # started through a tcp_wrappers-enabled xinetd.
- #
- # The rules in this file can also be set up in
- # /etc/hosts.allow with a 'deny' option instead.
- #
- # See 'man 5 hosts_options' and 'man 5 hosts_access'
- # for information on rule syntax.
- # See 'man tcpd' for information on tcp_wrappers
- #
- ALL:ALL
-
- /etc/hosts.deny里的ALL:ALL表示,除非在/etc/hosts.allow里明确容许访问,不然一概拒绝
- /etc/hosts.allow里第一行in.telnetd:.xfcy.org表示,只有xfcy.org这个域里的主机容许访问telnet服务,注意xfcy.org前面的那个点(.)
- /etc/hosts.allow里第二行表示,只有192.168.0这个网段的用户容许访问FTP服务,注意0后面的点(.)
- /etc/hosts.allow里第三行表示,只有192.168.0这个网段的用户容许访问SSH服务,注意这里不能写为192.168.0.0/24