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(图形)的两种管理 ...
随机推荐
- AD16
第三集 制作光敏小夜灯的原理图 1.点击G切换栅格的精度 2.元器件放置好之后要先布局在布线 3.布线完成后要检查电路的合理性.对应查一下电阻的个数,位置是不是符合.在原理上大概的估计是否可以. ...
- Django总结(Django十一)
总结一下自己在完成毕设时写的Django博客: Django的初步启动 pycharm+Django启动我的第一个页面 Django+bootstrap启动登录模板页面 Django中 < a ...
- CentOS7下mysql忘记root密码的处理方法
1. vi /etc/my.cnf,在[mysqld]中添加 skip-grant-tables 例如: [mysqld] skip-grant-tables datadir=/var/lib/my ...
- Docker添加TLS认证修复2375端口暴露引发的漏洞
#### 1.环境准备 ```bash# 查看Docker服务器主机名hostnamectl``` :Object类中声明 ...
- hystrix源码之概述
概述 hystrix核心原理是通过代理执行用户命令,记录命令执行的metrics信息,通过这些metrics信息进行降级和熔断. 源码结构包括一下几个部分: 熔断器 熔断器就是hystrix用来判断调 ...
- 容器云平台No.7~kubernetes监控系统prometheus-operator
简介 prometheus-operator Prometheus:一个非常优秀的监控工具或者说是监控方案.它提供了数据搜集.存储.处理.可视化和告警一套完整的解决方案.作为kubernetes官方推 ...
- Github 个人首页的 README,这样玩儿~
本文首发于 Ficow Shen's Blog,原文地址: Github 个人首页的 README,这样玩儿~. 内容概览 前言 创建仓库 修改 README 的内容 总结 前言 大家最近有没有发现这 ...
- 八皇后问题(n-皇后问题)
JAVA 作为一道经典的题目,那必然要用经典的dfs来做 dfs:深度优先搜索----纵向搜索符合条件的内容,走到底时回到上一个路口再走到底再回去,套娃至结束. 条件:在一个n*n的国际棋盘上摆放n个 ...
- 【读书】Into The Air:进入空气稀薄地带
珠穆朗玛峰,世界第一高峰,北部在中国境内,南部在尼泊尔境内.喜欢户外运动的人,曾经在20多岁的时候曾经"大言不惭"说这一辈子一定要去一次珠峰.<Into the Air> ...