CentOS8.5 访问限制
CentOS7.x 使用的是hosts.allow和hosts.deny文件进行限制,到CentOS8.x已弃用hosts.allow和hosts.deny文件,可使用sshd_config文件和firewalld防火墙规则限制。
一、使用sshd_config进行限制
# 在/etc/ssh/sshd_config文件中添加限制
AllowUsers root@192.168.10.0/24
DenyUsers root@192.168.10.2
allow/deny按照一定顺序生效:
DenyUsers-->AllowUsers-->DenyGroups-->AllowGroups
二、使用firewalld防火墙规则进行限制
1、限制IP地址访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.10.0/24" port protocol="tcp" port="80" reject"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.10.0/24" port protocol="tcp" port="80" accept"
firewall-cmd --reload
firewall-cmd --zone=public --list-rich-rules
2、解除限制IP地址访问
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.10.0/24" port protocol="tcp" port="80" reject"
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.10.0/24" port protocol="tcp" port="80" accept"
firewall-cmd --reload
firewall-cmd --zone=public --list-rich-rules
3、限制端口访问
firewall-cmd --permanent --zone=public --add-port=100-500/tcp
firewall-cmd --permanent --zone=public --add-port=22/tcp
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
4、接触限制端口访问
firewall-cmd --permanent --zone=public --remove-port=100-500/tcp
firewall-cmd --permanent --zone=public --remove-port=22/tcp
firewall-cmd --reload
firewall-cmd --zone=public --list-ports