访问限制

Linux下的访问限制有很多, iptables, hosts.allow, hosts.deny 等等

介绍一下hosts.allow和hosts.deny

一: hosts.allow, hosts.deny

hosts.allow, hosts.deny 的使用需要确认openssh开启了--with-tcp-wrappers
经过测试, 一般centos7 默认的openssh7.4是支持的.
使用 ldd /usr/sbin/sshd | grep libwrap

编辑 /etc/hosts.allow

  1. 允许 192.168.128.1登录

sshd:192.168.128.1:allow
2) 允许 192.168.128.0/24 网段登录
sshd:192.168.128.:allow
3) 允许 192.168.128.0/24 和 192.168.64.0/24 多个网段登录
sshd:192.168.128.,192.168.64.:allow
4) 允许全部登录
sshd:ALL

编辑 /etc/hosts.deny
5) 禁止 192.168.128.1登录
sshd:192.168.128.1:deny

只允许某个/多个ip的访问
编辑 /etc/hosts.deny 添加 sshd:ALL
编辑 /etc/hosts.allow 添加允许访问的ip

二: sshd_config限制登录(hosts.allow, hosts.deny不可用的时候)

编辑: /etc/ssh/sshd_config

只允许 192.168.128.0/24这个网段访问
添加: AllowUsers root@192.168.128.0/24