关于linux:Linux系统防火墙限制ssh连接

2次阅读

共计 1009 个字符,预计需要花费 3 分钟才能阅读完成。

我的环境应用 3A 云服务器搭建的 centos7

本文应用自带的防火墙服务 firewalld.service 来对拜访进行管制,次要讲限度 ssh 连贯拜访

1、先查看防火墙有没有运行,绿色代表已启动了
systemctl status firewalld

如果是灰色,先启动防火墙
systemctl start firewalld

2. 查看目前防火墙失效的策略,如果有对于 ssh 的就删除

firewall-cmd --zone=public --list-rich-rules

空洞无物
删除拜访限度的 ssh 服务

firewall-cmd –permanent –remove-service=ssh

3. 配置容许拜访 ssh 服务的控制策略
执行上面的命令,容许 ip 或 ip 段拜访 22 端口的 ssh 服务,例如上面命令执行后,将容许 192.168.5.0/24 这个 ip 段容许拜访 ssh 服务,留神端口要正确

firewall-cmd --permanent --add-rich-rule='rule family="ipv4"source address="192.168.5.0/24"port protocol="tcp"port="22"accept'

4. 重载防火墙配置,使其失效
firewall-cmd --reload

再查看目前防火墙失效的策略,

firewall-cmd --zone=public --list-rich-rules

能够看到他曾经失效了

拓展命令:
手动放行指定端口

firewall-cmd --permanent --add-port=3306/tcp

删除放行的端口

firewall-cmd --permanent --remove-port=3306/tcp

放行指定服务(零碎内)

firewall-cmd --permanent --add-service=http

删除服务

firewall-cmd --permanent --remove-service=http

屏蔽指定 ip 地址

firewall-cmd --permanent --add-rich-rule="rule family='ipv4'source address='192.168.1.100'reject"

屏蔽指定 ip 地址段

firewall-cmd --permanent --add-rich-rule="rule family='ipv4'source address='192.168.1.0/24'reject"
正文完
 0