centos8用firewalld搭建防火墙
一,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搭建防火墙的更多相关文章
- centos7 && centos6.5部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发
centos7 && centos6.5 部KVM使用NAT联网并为虚拟机配置firewalld && iptables防火墙端口转发 一.准备工作: 1: 检查kvm ...
- CentOS 使用firewalld打开防火墙与端口
CentOS 使用firewalld打开防火墙与端口 LinuxCentOS 基本使用 启动 : systemctl start firewalld 关闭 : systemctl stop firew ...
- CentOS8.1中搭建Gitlab服务器
依旧是写在前面的话♠:很多IT人从业N年也许都还没有亲自搭过一次Gitlab服务器,是不是?有木有?!通常都是背着自己的笔记电脑到一家公司入职,或入职后领到公司分配的电脑,然后分配了Git账号,拿了将 ...
- firewalld管理防火墙常用命令
1.查看防火墙的状态 [root@localhost HMK]# firewall-cmd --state 查看防火墙的运行状态 not running [root@localhost HMK]# s ...
- Centos7管理selinux及使用firewalld管理防火墙
CentOS 7.0默认使用的是firewall作为防火墙 1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status ...
- firewalld的防火墙
firewalld的介绍与简单应用 CentOS7的默认防火墙是firewalld,在之前使用iptables时,关闭了firewalld服务,现在反过来关闭iptables服务,打开firewall ...
- Linux学习笔记之CentOS 7系统使用firewalld管理防火墙端口
0x00 firewalld的基本使用 # 启动: systemctl start firewalld # 查看状态: systemctl status firewalld # 停止: systemc ...
- CentOS7使用firewalld管理防火墙与端口
firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status fir ...
- 第二十三章 Firewalld的防火墙
一.防火墙基本概述 在CentOS7系统中集成了多款防火墙管理工具,默认启用的是firewalld(动态防火墙管理器)防火墙管理工具,Firewalld支持CLI(命令行)以及GUI(图形)的两种管理 ...
随机推荐
- SpringBoot+Shiro+JPA+LayUI的后台管理系统
一.系统说明 资源下载路径:https://download.csdn.net/download/qq_37171817/12056804 本系统是一个用SpringBoot做后台开发框架,Shiro ...
- [HDU2577]How to Type(DP)
题目链接 题意 给一个大小写字符串,求最少敲击字符串次数,最开始和最后要求shift都是down的.如日常,大小写转换可以ctrl+z或者shift保持 up/down. 题解 两个dp数组,一个表示 ...
- python获取倒数第k个结点
思路:定义快慢两个指针,快指针走k步后慢指针开始走,当快指针走到链表尾时快慢指针距离相隔k,倒数第K个结点就是慢指针所指的结点 # -*- coding:utf-8 -*- # class ListN ...
- C#开发PACS医学影像处理系统(十八):Dicom使用LUT色彩增强和反色
在医生阅片确诊的过程中,当发线疑似病灶时在灰度显示下有时并不清晰,这时候就需要色彩增强效果来使灰度图像变为彩色图像. LUT可以简单的理解为0-255的颜色映射值,例如:彩虹编码,将其打包成LUT格式 ...
- Redis详细使用及结合SpringBoot
今天咱来聊一下Redis五种数据类型的详细用法以及在代码中如何使用.废话不多说,开始! Redis五种数据类型: string:字符串对象 list:列表对象 hash:散列 set:集合 zset: ...
- ribbon源码(6) Server
Server 代表一个服务器信息. 内部有服务器地址(host).服务器端口(port).服务器dc(zone).是否存活标志(isAliveFlag).请求协议(scheme).是否可以提供服务(r ...
- hystrix文档翻译之Dashboard
Dashboard Hystrix Dashboard可以让你实时监控hystrix的metrics信息. 当netflix开始使用dashboard后,运维效率得到了极大的提升,并且极大降低了大多数 ...
- 安装Windows10操作系统 - 初学者系列 - 学习者系列文章
今天无事,就将安装操作系统的几种方式进行了总结( https://www.cnblogs.com/lzhdim/p/13719725.html ).这篇博文主要是对安装windows10操作系统的过程 ...
- Java11新特性
局部变量类型推断增强 Java11中可以在lambda表达式的形参中使用var,好处是可以在形参上加注解 使用示例 (@Deprecated var x, @Nullable var y)->x ...
- svn的使用学习
一:安装 1.svn安装包,语言包下载 地址:https://pan.baidu.com/s/1PFM7ya_hNJM-v979KgCpgA 提取码:mpxq 2.运行下载的TortoiseSVN程序 ...