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(图形)的两种管理 ...
随机推荐
- Web开发初探(系统理解Web知识点)
一.Web开发介绍 我们看到的网页通过代码来实现的 ,这些代码由浏览器解释并渲染成你看到的丰富多彩的页面效果. 这个浏览器就相当于Python的解释器,专门负责解释和执行(渲染)网页代码. 写网页的代 ...
- Physics Experiment(POJ 3684)
原题如下: Physics Experiment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3583 Accepte ...
- 内存管理初始化源码2:setup_arch
PFN相关宏说明: /* kernel/include/linux/pfn.h */ PFN : Page Frame Number(物理页帧) /* * PFN_ALIGN:返回地址x所在那一页帧的 ...
- springboot之启动端口指定
https://www.cnblogs.com/yaomajor/p/8616929.html
- URL及日期等特殊数据格式处理-JSON框架Jackson精解第2篇
Jackson是Spring Boot默认的JSON数据处理框架,但是其并不依赖于任何的Spring 库.有的小伙伴以为Jackson只能在Spring框架内使用,其实不是的,没有这种限制.它提供了很 ...
- 【JAVA】JAVA相关知识点收集
下面这些链接都是我这段时间(7月-9月)看过的.感觉自己现在处于一个疯狂吸收知识的阶段,如果是文字的方式一点一点搬运到自己的博客既重复又费时间,只有等自己积累到一定程度后才能进行原创性高质量的产出吧. ...
- jfinal3连接sqlserver2012 使用generator生成model 将smallint默认为string
修改MetaBuilder的buildColumnMetas方法增加对smallint的判断
- xss小游戏通关
xss url:http://test.ctf8.com/level1.php?name=test 小游戏payload: <script>alert("'test'" ...
- macOS提示“将对您的电脑造成伤害……“进阶版
> 很多小伙伴在更新完系统后运行应用会闪退以及提示"xxxx 将对您的电脑造成伤害. 您应该将它移到废纸篓",本文将针对此问题提供解决方法.如图:![-w456](https ...
- Linux NSF网络共享盘
服务器安装: yum -y install nfs-utils rpcbind 服务器配置 :vi /etc/exports 例: /root/docs 192.168.1.*(rw,sync,no ...