一,firewalld的systemd管理命令

启动:systemctl start firewalld
关闭:systemctl stop firewalld
查看状态:systemctl status firewalld
开机禁用:systemctl disable firewalld
开机启用:systemctl enable firewalld

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,firewall-cmd的通用命令:

1,查看firewall-cmd版本:

[root@localhost liuhongdi]# firewall-cmd --version
0.7.0

2,查看firewall-cmd帮助

[root@localhost liuhongdi]# firewall-cmd --help

3,查看firewalld状态

[root@localhost liuhongdi]# firewall-cmd --state
running

4,更新防火墙的规则

[root@localhost liuhongdi]# firewall-cmd --reload
success

说明:--reload的作用:让“永久生效”的配置规则立即生效,并覆盖当前的配置规则

5,查看firewalld的所有规则:

[root@localhost zones]# firewall-cmd --list-all

三,zone相关命令:

1,得到默认的zone:

[root@localhost liuhongdi]# firewall-cmd --get-default-zone
public

2,得到当前正在使用的zone与网卡名称

[root@localhost liuhongdi]# firewall-cmd --get-active-zones
libvirt
interfaces: virbr0
public
interfaces: ens33

3,得到所有可用的zone

[root@localhost liuhongdi]# firewall-cmd --get-zones
block dmz drop external home internal libvirt public trusted work

4,设置默认的zone

[root@localhost liuhongdi]# firewall-cmd --set-default-zone=drop
success
[root@localhost liuhongdi]# firewall-cmd --get-active-zones
drop
interfaces: ens33
libvirt
interfaces: virbr0

四,services相关命令:

1,列出所有可用的services

[root@localhost liuhongdi]# firewall-cmd --get-services 

2,列出当前已放开的services

[root@localhost liuhongdi]# firewall-cmd --list-services

3,  放开一个服务

[root@localhost liuhongdi]# firewall-cmd --add-service=http

4,  关闭一个服务

[root@localhost liuhongdi]# firewall-cmd --remove-service=http --permanent
success

说明:关于permanent参数:    添加--permanent重启后则永久生效,如无--permanent仅临时生效

五,port相关命令:

1,查看所有打开的端口:

[root@localhost liuhongdi]# firewall-cmd --zone=public --list-ports
80/tcp 8080/tcp 22/tcp

2,放开一个端口:

[root@localhost liuhongdi]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success

3,关闭已放开的端口:

[root@localhost liuhongdi]# firewall-cmd --zone=public --remove-port=80/tcp --permanent
success

六,针对permanent参数的验证:

1,添加端口后,如果加了 permanent,不会马上起作用:reload之后会起作用

[root@localhost liuhongdi]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost liuhongdi]# firewall-cmd --zone=public --list-ports
8080/tcp 22/tcp
[root@localhost liuhongdi]# firewall-cmd --reload
success
[root@localhost liuhongdi]# firewall-cmd --zone=public --list-ports
8080/tcp 22/tcp 80/tcp

2,删除端口,如果加了 permanent,不会马上起作用,也需要reload

[root@localhost liuhongdi]# firewall-cmd --zone=public --remove-port=80/tcp --permanent
success
[root@localhost liuhongdi]# firewall-cmd --zone=public --list-ports
8080/tcp 22/tcp 80/tcp
[root@localhost liuhongdi]# firewall-cmd --reload
success
[root@localhost liuhongdi]# firewall-cmd --zone=public --list-ports
8080/tcp 22/tcp

3,如果不加permanent,能马上起作用:

[root@localhost liuhongdi]# firewall-cmd --zone=public --add-port=80/tcp
success
[root@localhost liuhongdi]# firewall-cmd --zone=public --list-ports
8080/tcp 22/tcp 80/tcp

七,针对ip地址的操作:

1,允许一个ip访问:

[root@localhost liuhongdi]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="43.229.53.61" accept'

2,禁止一个ip访问

[root@localhost liuhongdi]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="43.229.53.61" drop'

说明:drop也可用reject

两者的区别在于drop不会提示拒绝访问而是直接丢弃数据包

3,指定允许一个ip到指定端口的访问

[root@localhost liuhongdi]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="22" accept'
success

4,删除一条rich rule

[root@localhost liuhongdi]# firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="22" accept'
success

八,手动添加的防火墙规则位于哪里?

/etc/firewalld/zones/public.xml

说明:可以手动编辑这个保存规则的xml,

然后做reload

九,生产环境中要注意的地方:

如果已添加了http服务,仍然可以添加80 port,

导致要关闭http服务时,也需要关闭80 port,

所以,尽量使用 port,而不要把service和port混用

十,一个生产环境中防火墙的zone文件例子:

<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are acc
epted.</description>
<port port="80" protocol="tcp"/>
<rule family="ipv4">
<source address="10.0.10.1"/>
<accept/>
</rule>
<rule family="ipv4">
<source address="43.229.53.61"/>
<drop/>
</rule>
</zone>

说明: 1,生产环境中防火墙一定要做基于ip地址的限制,不能允许从公网随便访问

2,需要放开的端口越少越好,最好只放开一个有运行中业务的端口

centos8用firewalld搭建防火墙的更多相关文章

  1. centos7 && centos6.5部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发

    centos7 && centos6.5 部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发 一.准备工作: 1: 检查kvm ...

  2. CentOS 使用firewalld打开防火墙与端口

    CentOS 使用firewalld打开防火墙与端口 LinuxCentOS 基本使用 启动 : systemctl start firewalld 关闭 : systemctl stop firew ...

  3. CentOS8.1中搭建Gitlab服务器

    依旧是写在前面的话♠:很多IT人从业N年也许都还没有亲自搭过一次Gitlab服务器,是不是?有木有?!通常都是背着自己的笔记电脑到一家公司入职,或入职后领到公司分配的电脑,然后分配了Git账号,拿了将 ...

  4. firewalld管理防火墙常用命令

    1.查看防火墙的状态 [root@localhost HMK]# firewall-cmd --state 查看防火墙的运行状态 not running [root@localhost HMK]# s ...

  5. Centos7管理selinux及使用firewalld管理防火墙

    CentOS 7.0默认使用的是firewall作为防火墙 1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status ...

  6. firewalld的防火墙

    firewalld的介绍与简单应用 CentOS7的默认防火墙是firewalld,在之前使用iptables时,关闭了firewalld服务,现在反过来关闭iptables服务,打开firewall ...

  7. Linux学习笔记之CentOS 7系统使用firewalld管理防火墙端口

    0x00 firewalld的基本使用 # 启动: systemctl start firewalld # 查看状态: systemctl status firewalld # 停止: systemc ...

  8. CentOS7使用firewalld管理防火墙与端口

    firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status fir ...

  9. 第二十三章 Firewalld的防火墙

    一.防火墙基本概述 在CentOS7系统中集成了多款防火墙管理工具,默认启用的是firewalld(动态防火墙管理器)防火墙管理工具,Firewalld支持CLI(命令行)以及GUI(图形)的两种管理 ...

随机推荐

  1. 内存管理初始化源码3:bootmem

    start_kernel ——> setup_arch ——> arch_mem_init ——> bootmem_init ——> init_bootmem_node: 此时 ...

  2. json出现引用 "$ref": "$.conpolice[2]"

    1. 出现这个问题一般是因为代码循环引用出现的问题,可以改变逻辑,也可以直接加上下面加粗的代码 JSONObject jsonObject = new JSONObject(); jsonObject ...

  3. web网站——apache和nginx对比02

    nginx介绍 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为“engine X”,是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理 ...

  4. hystrix(5) 使用

    这一节我们开始了解hystrix执行的主流程,在讲解主流程之前,我们先来看一下怎么使用hystrix. 引入jar <dependency> <groupId>com.netf ...

  5. Java Web学习(二)数据加密

    一.Tomcat 体系 首先通过一幅图来了解下tomcat的运行体系: Tomcat服务器的启动是基于一个server.xml文件的. 启动流程: 首先启动一个Server,Server里面就会启动S ...

  6. php基础复习

    基础捡漏: 1.短标记<??> 通过修改ini文件的short_open_tag或编译时 --enable-short-tags 可用 不推荐使用. 2.?>默认有隐藏分号结束,而文 ...

  7. [Abp vNext 源码分析] - 21. 界面与文字的本地化

    一.简介 ABP vNext 提供了全套的本地化字符串支持,具体用法可以参考官方使用文档.vNext 本身是对 Microsoft 提供的本地化组件进行了实现,通过 JSON 文件提供本地化源,这一点 ...

  8. 国产化之路-统信UOS操作系统安装

    专题目录 国产化之路-统信UOS操作系统安装 国产化之路-国产操作系统安装.net core 3.1 sdk 国产化之路-安装WEB服务器 国产化之路-安装达梦DM8数据库 国产化之路-统信UOS + ...

  9. Elasticsearch(2):索引详谈

      在上一篇博客中,介绍了ES中的一些核心概念和ES.Kibana安装方法.本节开始,我们从索引开始来学习ES的操作方法.   1 创建索引¶   创建一个索引的方法很简单,在Kibana中运行下行请 ...

  10. pytest封神之路第六步 断言技巧

    pytest的断言把Python语言简洁的优点发挥的淋漓尽致,因为它用的就是Python的标准断言assert. assert基础 assert用法 assert_stmt ::= "ass ...