1. 简介

TCP Wrapper是Linux系统中一个通用的标准安全框架。其作用类似于IPTABLES, 用于控制从inetd启动的基于TCP的应用程序的访问。其守护进程是tcpd, 通过读取如下两个文件中的相关策略配置,决定允许还是拒绝到达的TCP连接。使用它来限制服务器允许执行的ip登陆,比防火墙方便很多。

/etc/hosts.allow

/etc/hosts.deny

linux系统会先检查/etc/hosts.deny规则,再检查/etc/hosts.allow规则。如果有冲突 ,按/etc/hosts.allow规则处理。即如果在/etc/hosts.deny和/etc/hosts.allow中,同时有sshd:192.168.11.112规则,则192.168.11.112可以访问主机的ssh服务。


2. 配置规则

  • 设置白名单

一般的用法是在hosts.allow中配置信任主机规则,然后到hosts.deny中拒绝所有其他主机。

# more /etc/hosts.allow 


# 设置IP网段
sshd:150.223.254.0/255.255.255.0:allow
sshd:182.42.255.0/255.255.255.0:allow
# 设置具体某个IP地址
sshd:36.111.140.26 allow
sshd:36.111.140.142 allow
sshd:106.39.160.37 allow


# more /etc/hosts.deny 

sshd: all
  • 设置黑名单

还有一种方法,在/etc/hosts.allow中接受其他所有主机,然后在/etc/hosts.deny中设置引用文件,在引用文件中禁用特定IP。

# more  /etc/hosts.allow 

sshd: all


# more /etc/hosts.deny

sshd:192.168.11.112
sshd:36.111.140.26

修改后,名单即时生效。


3. 参考文章

https://baike.baidu.com/item/TCP%20Wrapper/17661285?spm=a2c4g.11186623.0.0.23df3fbbCV7FuO

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐