如何在CentOS 8上使用firewalld设置防火墙

2023-11-02

介绍 (Introduction)

firewalld is firewall management software available for many Linux distributions, which acts as a frontend for Linux’s in-kernel nftables or iptables packet filtering systems.

firewalld是可用于许多Linux发行版的防火墙管理软件,它充当Linux内核内可移植对象iptables数据包过滤系统的前端。

In this guide, we will show you how to set up a firewalld firewall for your CentOS 8 server, and cover the basics of managing the firewall with the firewall-cmd administrative tool.

在本指南中,我们将向您展示如何为CentOS 8服务器设置防火墙防火墙,并介绍使用firewall-cmd管理工具管理防火墙的基础知识。

先决条件 (Prerequisites)

To complete this tutorial, you will need a server running CentOS 8. We will assume you are logged into this server as a non-root, sudo-enabled user. To set this up, see our Initial Server Setup for CentOS 8 guide.

要完成本教程,您将需要一台运行CentOS 8的服务器。我们假定您以非root用户 ,启用了sudo用户身份登录到该服务器。 要进行设置,请参阅我们的CentOS 8初始服务器设置指南。

Firewalld中的基本概念 (Basic Concepts in firewalld)

Before we begin talking about how to actually use the firewall-cmd utility to manage your firewall configuration, we should get familiar with a few concepts that the tool introduces.

在开始讨论如何实际使用firewall-cmd实用程序来管理防火墙配置之前,我们应该熟悉该工具引入的一些概念。

区域 (Zones)

The firewalld daemon manages groups of rules using entities called zones. Zones are sets of rules that dictate what traffic should be allowed depending on the level of trust you have in the network. Network interfaces are assigned to a zone to dictate the behavior that the firewall should allow.

firewalld守护程序使用称为zone的实体管理规则组。 区域是一组规则,这些规则根据您在网络中的信任级别来决定应允许的流量。 将网络接口分配给区域,以指示防火墙应允许的行为。

For computers that might move between networks frequently (like laptops), this kind of flexibility provides a good method of changing your rules depending on your environment. You may have strict rules in place prohibiting most traffic when operating on a public WiFi network, while allowing more relaxed restrictions when connected to your home network. For a server, these zones are often not as important because the network environment rarely, if ever, changes.

对于可能经常在网络之间移动的计算机(例如笔记本电脑),这种灵活性提供了一种根据环境更改规则的好方法。 在公共WiFi网络上运行时,您可能有严格的规则禁止大多数流量,而在连接到家庭网络时允许放宽限制。 对于服务器,这些区域通常并不那么重要,因为网络环境很少(如果有的话)发生变化。

Regardless of how dynamic your network environment may be, it is still useful to be familiar with the general idea behind each of the predefined zones for firewalld. The predefined zones within firewalld are, in order from least trusted to most trusted:

无论您的网络环境有多动态,熟悉firewalld d的每个预定义区域背后的一般思想仍然很有用。 按最低信任最受信任的顺序, firewalld中的预定义区域是:

  • drop: The lowest level of trust. All incoming connections are dropped without reply and only outgoing connections are possible.

    drop :最低信任级别。 所有传入的连接都将被丢弃而不会回复,并且只能进行传出连接。

  • block: Similar to the above, but instead of simply dropping connections, incoming requests are rejected with an icmp-host-prohibited or icmp6-adm-prohibited message.

    block :与上述类似,但不是简单地丢弃连接,而是使用icmp-host-prohibitedicmp6-adm-prohibited消息拒绝传入的请求。

  • public: Represents public, untrusted networks. You don’t trust other computers but may allow selected incoming connections on a case-by-case basis.

    public :代表公共的,不受信任的网络。 您不信任其他计算机,但可能会视情况允许选择的传入连接。

  • external: External networks in the event that you are using the firewall as your gateway. It is configured for NAT masquerading so that your internal network remains private but reachable.

    external :如果您使用防火墙作为网关,则为外部网络。 将其配置为伪装NAT,以便您的内部网络保持私有但可访问。

  • internal: The other side of the external zone, used for the internal portion of a gateway. The computers are fairly trustworthy and some additional services are available.

    内部 :外部区域的另一侧,用于网关的内部。 这些计算机相当值得信赖,并且可以使用一些其他服务。

  • dmz: Used for computers located in a DMZ (isolated computers that will not have access to the rest of your network). Only certain incoming connections are allowed.

    dmz :用于DMZ中的计算机(将无法访问网络其余部分的隔离计算机)。 仅允许某些传入连接。

  • work: Used for work machines. Trust most of the computers in the network. A few more services might be allowed.

    工作 :用于工作机。 信任网络中的大多数计算机。 可能还允许其他一些服务。

  • home: A home environment. It generally implies that you trust most of the other computers and that a few more services will be accepted.

    home :家庭环境。 通常,这意味着您信任其他大多数计算机,并且将接受其他一些服务。

  • trusted: Trust all of the machines in the network. The most open of the available options and should be used sparingly.

    Trusted :信任网络中的所有计算机。 可用选项中最开放的,应谨慎使用。

To use the firewall, we can create rules and alter the properties of our zones and then assign our network interfaces to whichever zones are most appropriate.

要使用防火墙,我们可以创建规则并更改区域的属性,然后将网络接口分配给最合适的区域。

规则永久性 (Rule Permanence)

In firewalld, rules can be applied to the current runtime ruleset, or be made permanent. When a rule is added or modified, by default, only the currently running firewall is modified. After the next reboot – or reload of the firewalld service – only the permanent rules will remain.

在firewalld中,规则可以应用于当前的运行时规则集,也可以成为永久规则。 添加或修改规则时, 默认情况下,仅修改当前运行的防火墙 。 下次重新启动后-或重新加载firewalld服务-仅保留永久性规则。

Most firewall-cmd operations can take a --permanent flag to indicate that the changes should be applied to the permenent configuration. Additionally, the currently running firewall can be saved to the permanent configuration with the firewall-cmd --runtime-to-permanent command.

大多数firewall-cmd操作都可以带有--permanent标志,以指示应将更改应用于永久配置。 另外,可以使用firewall-cmd --runtime-to-permanent命令将当前正在运行的防火墙保存到永久配置。

This separation of runtime vs permanent configuration means that you can safely test rules in your active firewall, then reload to start over if there are problems.

运行时间与永久配置的这种分离意味着您可以在活动防火墙中安全地测试规则,然后在出现问题时重新加载以重新开始。

安装和启用防火墙 (Installing and Enabling firewalld)

firewalld is installed by default on some Linux distributions, including many images of CentOS 8. However, it may be necessary for you to install firewalld yourself:

默认情况下, firewalld是在某些Linux发行版上安装的,包括许多CentOS 8映像。但是,您可能需要自己安装firewalld:

  • sudo dnf install firewalld

    须藤dnf安装firewalld

After you install firewalld, you can enable the service and reboot your server. Keep in mind that enabling firewalld will cause the service to start up at boot. It is best practice to create your firewall rules and take the opportunity to test them before configuring this behavior in order to avoid potential issues.

安装firewalld ,您可以启用该服务并重新启动服务器。 请记住,启用firewalld将导致该服务在启动时启动。 最好的做法是在配置此行为之前创建防火墙规则并借此机会对其进行测试,以避免潜在的问题。

  • sudo systemctl enable firewalld

    sudo systemctl启用防火墙
  • sudo systemctl start firewalld

    须藤systemctl启动firewalld

When the server restarts, your firewall should be brought up, your network interfaces should be put into the zones you configured (or fall back to the configured default zone), and any rules associated with the zone(s) will be applied to the associated interfaces.

服务器重新启动时,应启动防火墙,将网络接口放入配置的区域(或退回到配置的默认区域),并且与该区域关联的所有规则都将应用于关联的区域。接口。

We can verify that the service is running and reachable by typing:

我们可以通过输入以下内容来验证该服务正在运行并且

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在CentOS 8上使用firewalld设置防火墙 的相关文章

随机推荐

  • 【python随笔】之【将doc、docx文件保存为txt文件】

    import win32com client def change word to txt word path save path print 读取中 word win32com client Dispatch Word Applicati
  • vector 操作

    C 内置的数组支持容器的机制 但是它不支持容器抽象的语义 要解决此问题我们自己实现这样的类 在标准C 中 用容器向量 vector 实现 容器向量也是一个类模板 标准库vector类型使用需要的头文件 include
  • 汇编语言笔记-keil5软件仿真及调试

    目录 keil5调试功能 软件仿真设置 硬件调试设置 调试方法 调试选项及介绍 调试窗口 Command Disassembly Symbols Registers Call Stack Locals Watch Memory Serial
  • 赶快进来!!!手把手教你贪吃蛇

    一 大体框架 这里和前面写过的游戏一样 大体框架都是这样 有个简要的目录 我们主要是对play 函数进行封装 由于我们引用了自己的头文件 game h 所以我们可以把所要引用的库函数的预处理指令都放在 game h 的头文件中 如果你细心的
  • Vue3中vuex的基本使用

    一 基本结构 src store index js中 代码如下 vue3中创建store实例对象的方法createStore 按需引入 import createStore from vuex export default createSt
  • pywt 安装学习

    安装 conda install c conda forge pywavelets github地址 里面有demo https github com PyWavelets pywt 这个是学习笔记 https blog csdn net
  • UPC--扑克牌

    题目描述 从一副含有n n 10000 张的扑克牌 显然每张扑克牌都不相同 中 分给m m 100 个人 第i个人得到ai 0 ai 100 张牌 求一共有几种分法 这个数可能非常大 请输出此数模10007后的结果 输入 第一行两个整数 为
  • HDU1874 单源最短路经 dijkstra或者floyd

    include
  • 3、域渗透详解

    在渗透测试过程中 我们经常会遇到以下场景 某处于域中的服务器通过路由做端口映射 对外提供web服务 我们通过web脚本漏洞获得了该主机的system权限 如果甲方有进一步的内网渗透测试需求 以证明企业所面临的巨大风险 这个时候就需要做内网的
  • 模拟IC应届生都这么牛,我想到了崩溃

    再过两个月就到学弟学妹找工作的高峰期了 做为一个2007年的毕业生 能为学弟学妹做的 就是把我去年到今年找工作的经历和经验与他们分享 希望大家都能找到合适的工作 因为本人是模拟ic设计方向的 所以只能介绍些模拟ic设计方面的找工作经验 其实
  • SVM如何避免过拟合

    过拟合 Overfitting 表现为在训练数据上模型的预测很准 在未知数据上预测很差 过拟合主要是因为训练数据中的异常点 这些点严重偏离正常位置 我们知道 决定SVM最优分类超平面的恰恰是那些占少数的支持向量 如果支持向量中碰巧存在异常点
  • pyside6中QcommandLinkButton 控件qss有哪些用法和案例

    QCommandLinkButton 是 Qt GUI 框架中的一个功能按钮类 而 Qt Style Sheets QSS 提供了一种强大的方式来自定义 Qt 控件的外观 以下是 QCommandLinkButton 常用的 QSS 用法
  • 比亚迪半导体IPO再生波折:又被中止审核 红杉小米是股东

    雷递网 雷建平 4月1日报道 2022年1月底刚刚过会的比亚迪半导体上市再生波折 于2022年3月31日的审核再度被中止 这不是比亚迪半导体IPO审核第一次被深交所中止 2021年8月8日 因律师北京市天元律师事务所被中国证监会立案调查 比
  • [从零开始学DeepFaceLab-16]: 使用-命令行八大操作步骤-第6步:模型的选择与训练 - 进阶 - SAEHD模型训练参数详解与优化

    目录 前言 第1章 SAEHD模型训练参数详解 1 1 SAEHD参数汇总 默认 1 2 参数详解
  • 手把手教你:解决python UnicodeDecodeError: 'gb2312' codec can't decode问题

    问题 UnicodeDecodeError gb2312 codec can t decode bytes in position 2 3 illegal multibyte sequence 原因 python在做将普通字符串转换为uni
  • 【Github Action】使用ssh-deploy上传文件的小坑

    可以使用这个Github Action上传文件到服务器 https github com easingthemes ssh deploy README中描述了使用方法 name Deploy to Staging server uses e
  • FastAPI从入门到实战(13)——常见配置项

    这一部分的内容主要是一些常见的配置 包括路由 静态文件等 还包括一些路径和文档的修饰器 包括简介 标签参数等内容 配置静态文件 from fastapi import FastAPI from fastapi staticfiles imp
  • jvisualvm ssl远程连接JVM

    jvisualvm 远程ssl连接 文章目录 一 没认证的 JMX连接 不安全 二 SSL证书认证的JMX连接 安全 1 进入生成证书的目录 并执行脚本 2 一键生成密钥脚本 3 服务器端运行jar包时 开启ssl连接 4 客户端远程SSL
  • AR小项目的制作过程(一)

    前段时间一直想着初一个教程 怎么用unity去做一个AR小demo 在做之前先科普一下什么是AR AR技术也被称作是 增强现实 主要是一种将虚拟信息与真实世界巧妙融合的技术 现在光返的运用在很多方面 例如多媒体 3D建模 实时跟踪及注册 智
  • 如何在CentOS 8上使用firewalld设置防火墙

    介绍 Introduction firewalld is firewall management software available for many Linux distributions which acts as a fronten