1、centos7系统默认是放行ssh22端口,需删除
/usr/lib/firewalld/services/ssh.xml文件
rm -rf /usr/lib/firewalld/services/ssh.xml
2、删除防火墙开放的22端口规则
firewall-cmd --zone=public --remove-port=22/tcp --permanent
3、添加相应访问22端口IP段
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.3.0/24 port protocol=tcp port=22 accept'(限制某一个IP访问使用此条规则:firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.3.101/32 port protocol=tcp port=22 accept')
重载规则
firewall-cmd –reload
4、验证
使用iptables -L命令查看默认规则,确保只有一条ssh防火墙规则。
找到IN_public_allow验证。
最终使用未开放的网段验证是否能登录和开放的网段能否登录。
精彩评论