suse系统配置/etc/hosts.allow、/etc/hosts.deny 测试未生效问题

在SUSE系统中配置/etc/hosts.allow/etc/hosts.deny不生效的问题可能由多种因素引起。首先,我们需要了解这两个文件是tcp_Wrappers防火墙的配置文件,用于控制特定服务的访问策略。tcp_Wrappers通过/etc/hosts.allow/etc/hosts.deny中的规则来允许或拒绝来自特定IP地址的访问请求。

以下是可能导致配置不生效的一些常见原因及解决方法:

  1. 服务未使用tcp_Wrappers:
    • 检查服务是否支持tcp_Wrappers。这通常可以通过查看服务是否链接了libwrapped库来确定。使用ldd命令可以查看服务是否链接了libwrap.so库。
    • 如果服务没有使用tcp_Wrappers,那么/etc/hosts.allow/etc/hosts.deny中的规则将不会对该服务生效。
  2. 配置文件格式错误:
    • 确保/etc/hosts.allow/etc/hosts.deny的格式正确。每个规则应该占一行,格式为服务名: 客户机地址
    • 注意,如果两个文件中都有针对同一服务的规则,那么/etc/hosts.allow中的规则会优先于/etc/hosts.deny中的规则

经过排查服务器未启用tcp_wrappers,配置文件 /etc/ssh/sshd_config 中 UseTCPWrappers yes

注释打开,重启sshd服务后,问题解决

在 SSH 服务(sshd)中,当 UseTCPWrappers 配置项设置为 yes 时,sshd 会使用 TCP Wrappers 来检查 /etc/hosts.allow 和 /etc/hosts.deny 文件中的规则,以决定是否允许来自特定主机的连接。

既然已经解开注释 UseTCPWrappers yes 并重启了 sshd 服务,现在 TCP Wrappers 应该已经启用,并且 sshd 会根据 /etc/hosts.allow 和 /etc/hosts.deny 中的规则来过滤连接。

posted @ 2024-03-07 10:58  太阳的阳ฅ  阅读(278)  评论(0编辑  收藏  举报