阅读量:3
在Linux系统中,配置防火墙规则通常使用iptables或firewalld工具。以下是使用这两个工具配置防火墙规则的基本步骤:
使用 iptables
-
查看当前规则:
sudo iptables -L -n -v -
允许特定IP访问:
sudo iptables -A INPUT -s 192.168.1.100 -j ACCEPT -
拒绝特定IP访问:
sudo iptables -A INPUT -s 192.168.1.101 -j DROP -
允许特定端口访问:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT -
拒绝特定端口访问:
sudo iptables -A INPUT -p tcp --dport 22 -j DROP -
保存规则:
sudo iptables-save > /etc/iptables/rules.v4 -
恢复规则:
sudo iptables-restore < /etc/iptables/rules.v4
使用 firewalld
-
查看当前区域和规则:
sudo firewall-cmd --list-all -
允许特定IP访问:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" accept' -
拒绝特定IP访问:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.101" reject' -
允许特定端口访问:
sudo firewall-cmd --permanent --add-port=80/tcp -
拒绝特定端口访问:
sudo firewall-cmd --permanent --remove-port=22/tcp -
重新加载防火墙配置:
sudo firewall-cmd --reload
注意事项
- 备份规则:在修改防火墙规则之前,建议备份当前的规则集,以便在出现问题时可以恢复。
- 权限:配置防火墙规则通常需要超级用户权限,因此需要使用
sudo。 - 持久化:
iptables的规则在系统重启后会丢失,除非使用iptables-save和iptables-restore命令保存和恢复规则。firewalld的规则可以通过--permanent选项设置为持久化。
通过以上步骤,你可以根据需要配置Linux系统的防火墙规则,以保护你的系统免受不必要的网络访问。
以上就是关于“Linux Trigger:怎样配置防火墙规则”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm