欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > linux >内容正文

linux

Linux下的TCP Wrapper机制

发布时间:2025/3/20 linux 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Linux下的TCP Wrapper机制 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
inetd程序在系统中是作为一个服务进程出现,它监听许多端口并且在得到客户请求时启动这个端口的服务程序。 早期系统中使用的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里的ALLALL表示,除非在/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 
  •       本文转自Vnimos51CTO博客,原文链接:http://blog.51cto.com/vnimos/1177594,如需转载请自行联系原作者



    总结

    以上是生活随笔为你收集整理的Linux下的TCP Wrapper机制的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。