Linux防火墙:Firewalld 常用命令

Linux防火墙:Firewalld 常用命令

CentOS 和 Fedora 中默认的防火墙是 Firewalld

  • 查看防火墙状态 firewall-cmd --state

  • 启动防火墙 systemctl start firewalld

  • 重启防火墙 systemctl restart firewalld

  • 暂时关闭防火墙 systemctl stop firewalld

  • 永久关闭防火墙 systemctl disable firewalld

  • 查看firewall服务状态(普通用户可执行) systemctl status firewalld

  • 查看防火墙服务是否开机启动 systemctl is-enabled firewalld

  • 设置开机时启用、禁用防火墙服务

  1. 启用服务 systemctl enable firewalld

  2. 禁用服务 systemctl disable firewalld

配置防火墙的命令

  • 查看防火墙的版本 firewall-cmd --version

  • 查看防火墙全部的信息 firewall-cmd --list-all

  • 查看防火墙已开通的端口 firewall-cmd --list-port

  • 查看防火墙已开通的服务 firewall-cmd --list-service

  • 查看全部的服务列表(普通用户可执行) firewall-cmd --get-services

  • 开放、移除某个端口

  1. 开放80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent

  2. 移除80端口 firewall-cmd --zone=public --remove-port=80/tcp --permanent

  • 开放、移去范围端口
  1. 开放5000-5500之间的端口 firewall-cmd --zone=public --add-port=5000-5500/tcp --permanent

  2. 移除5000-5500之间的端口 firewall-cmd --zone=public --remove-port=5000-5500/tcp --permanent

  • 开放、移去服务
  1. 开放ftp服务 firewall-cmd --zone=public --add-service=ftp --permanent

  2. 移去http服务 firewall-cmd --zone=public --remove-service=ftp --permanent

  • 重新加载防火墙配置(修改配置后要重新加载防火墙配置或重启防火墙服)firewall-cmd --reload

原文链接

Linux防火墙:Firewalld 常用命令

### 回答1: CentOS 系统防火墙有两种:iptables 和 firewalld。 1. iptables:是 Linux 内核的一部分,是一个防火墙管理工具。使用 iptables 命令管理防火墙规则。 2. firewalld:是一个防火墙管理工具,可以动态管理防火墙规则。使用 firewall-cmd 命令管理防火墙规则。 ### 回答2: CentOS 系统有两种防火墙:iptables 和 firewalld。这两种防火墙都可以用于保护系统免受网络攻击和恶意访问。 iptables 是一种传统的 Linux 防火墙工具,可以通过命令行来配置、管理和监控防火墙规则。以下是一些常用的 iptables 命令: 1. iptables -L:列出当前防火墙规则列表。 2. iptables -F:清空所有防火墙规则。 3. iptables -A INPUT -p tcp --dport 80 -j ACCEPT:允许所有进入端口 80 的 TCP 连接。 4. iptables -A INPUT -p tcp --dport 22 -j DROP:禁止所有进入端口 22 的 TCP 连接。 5. iptables-save > /etc/sysconfig/iptables:保存当前防火墙规则至文件。 firewalld 是 CentOS 7 及更新版本中引入的防火墙管理工具,相比于 iptables,它提供了更加灵活和方便的使用方式。以下是一些常用的 firewalld 命令: 1. systemctl start firewalld:启动 firewalld 服务。 2. firewall-cmd --state:检查 firewalld 是否处于运行状态。 3. firewall-cmd --list-all:显示当前防火墙规则和配置的详细信息。 4. firewall-cmd --zone=public --add-port=80/tcp --permanent:永久性开放 80 端口,使其对外可访问。 5. firewall-cmd --reload:重新加载防火墙规则。 总之,对于 CentOS 系统,在使用防火墙时可以根据具体需求选择合适的工具。如果对于命令行操作更为熟悉或需要更精细的控制,可以使用 iptables;而如果需要更简单的操作和集中管理,可以选择 firewalld
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

开源分享汇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值