TCP_Wrappers

TCP_Wrappers配置

这里主要涉及到两个配置文件/etc/hosts.allow和/etc/hosts.deny。/usr/sbin/tcpd进程会根据这两个文件判断是否对访问请求提供服务。
/usr/sbin/tcpd进程先检查文件/etc/hosts.allow,如果请求访问的主机名或IP包含在此文件中,则允许访问。
如果请求访问的主机名或IP不包含在/etc/hosts.allow中,那么tcpd进程就检查/etc/hosts.deny。看请求访问的主机名或IP有没有包含在hosts.deny文件中。如果包含,那么访问就被拒绝;如果既不包含在/etc/hosts.allow中,又不包含在/etc/hosts.deny中,那么此访问也被允许。

例1:
# cat /etc/hosts.allow
sshd:192.168.100.0

# cat/etc/hosts.deny
sshd:ALL

只允许192.168.100.0/24这个网段访问

例2:
# cat /etc/hosts.allow
sshd:192.168.100.0/255.255.255.0 except 192.168.100.3
# cat/etc/hosts.deny
sshd:ALL

192.168.100.0/24这个网段内除了192.168.100.3这个主机无法连接过来,其它主机都可以通过ssh协议连接进来。

例3:
# cat /etc/hosts.allow
sshd:ALL except 192.168.100.2

# cat/etc/hosts.deny

除了192.168.100.2外,允许所有主机连接。


检查某种服务是否可以通过tcp_wrappers来进行限制:
[root@rhel1 ~]# which vsftpd
/usr/sbin/vsftpd
[root@rhel1 ~]# ldd /usr/sbin/vsftpd | grep libwrap
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f6d52faf000)

比如httpd就不能通过tcp_wrappers来进行控制:

posted on 2017-09-22 16:09  遠離塵世の方舟  阅读(388)  评论(0编辑  收藏  举报

导航