禁止IP或IP段访问SSH:hosts.allow 和 hosts.deny

编辑于:2023年05月23日

禁止IP或IP段访问SSH:hosts.allow 和 hosts.deny

Linux 系统/etc/目录下的文件hosts.allowhosts.deny,可以允许或拒绝某个IP、IP段访问系统中使用了libwrap库的服务,如telnetdftpdsshd等。

hosts.allow 和 hosts.deny

当远程请求到达本机时,会先检查/etc/hosts.allow如果有匹配就默认允许访问,并跳过/etc/hosts.deny文件,否则将接着去匹配/etc/hosts.deny,有匹配则拒绝访问。

SSH 访问权限设置

允许单个IP访问

#/etc/hosts.allow 文件
sshd:192.168.0.0 
#/etc/hosts.deny 文件
sshd:ALL

允许多个IP访问

#/etc/hosts.allow 文件
sshd:192.168.0.0 , 192.168.0.1 #IP段
#/etc/hosts.deny 文件
sshd:ALL

允许单个IP段访问

#/etc/hosts.allow 文件
sshd:192.168.0.
#/etc/hosts.deny 文件
sshd:ALL

允许多个IP段访问

#/etc/hosts.allow 文件
sshd:192.168.0. , 192.168.1.
#/etc/hosts.deny 文件
sshd:ALL

允许多个服务多个IP段

#/etc/hosts.allow 文件
telnetd,sshd:192.168.1. , 192.168.2.
#/etc/hosts.deny 文件
sshd:ALL

禁止所有服务与所有IP

#/etc/hosts.deny 文件
all:all:deny

相关推荐

暂无评论