当前位置: 首页 > news >正文

配置防火墙和SELinux(1)

systemctl命令速查

[root@client ~]# systemctl unmask firewalld

                                                                 //执行命令,即可实现取消服务的锁定
[root@client ~]# systemctl mask firewalld

                                                                 //下次需要锁定该服务时执行
[root@client ~]# systemctl start firewalld.service

                                                                 //启动防火墙
[root@client ~]# systemctl stop firewalld.service

                                                                 //禁用防火墙

[root@client ~]# systemctl reload firewalld.service      

                                                                 //重载配置(需要先开启防火墙)

[root@client ~]# systemctl restart firewalld.service

                                                                 //重启服务
[root@client ~]# systemctl status firewalld.service

                                                                 //显示服务的状态

[root@client ~]# systemctl enable firewalld.service

                                                                 //在开机时启用服务
[root@client ~]# systemctl disable firewalld.service
                                                                 //在开机时禁用服务
[root@client ~]# systemctl is-enabled firewalld.service
                                                                 //查看服务是否开机启动
[root@client ~]# systemctl list-unit-files  |  grep enabled

                                                                 //查看已启动的服务列表

[root@client ~]# systemctl --failed

                                                                 //查看启动失败的服务列表

1.启动防火墙之前要先关闭

2.服务的状态

firewall-cmd命令速查

[root@client ~]# firewall-cmd   --state
                                                                 //查看防火墙状态
[root@client ~]# firewall-cmd   --reload
                                                                 //更新防火墙规则
[root@client ~]# firewall-cmd   --state
                                                                 //查看防火墙状态
[root@client ~]# firewall-cmd   --reload
                                                                 //重载防火墙规则
[root@client ~]# firewall-cmd   --list-ports

                                                                 //查看所有打开的端口

[root@client ~]# firewall-cmd   --list-services
                                                                 //查看所有允许的服务
[root@client ~]# firewall-cmd   --get-services

                                                                 //获取所有支持的服务

区域相关命令速查

[root@client ~]# firewall-cmd  --list-all-zones

                                                                 //查看所有区域信息

[root@client ~]# firewall-cmd  --get-active-zones

                                                                 //查看活动区域信息

[root@client ~]# firewall-cmd  --set-default-zone=public
                                                                 //设置 public 为默认区域
[root@client ~]# firewall-cmd  --get-default-zone
                                                                 //查看默认区域信息
[root@client ~]# firewall-cmd  --zone=public  --add-interface=eth0

                                                                 //将接口 eth0 加入区域 publid

接口相关命令速查

[root@client ~]# firewall-cmd --zone=public --remove-interface=ens160

                                                                 //从区域public中删除接口ens160

[root@client ~]# firewall-cmd --zone=external  --change-interface=ens160

                                                                 //修改接口ens160 所属区域为 default

[root@client ~]# firewall-cmd  --get-zone-of-interface=ens160

                                                                 //查看接口 ens160 所属区域

端口控制命令速查

[root@client ~]# firewall-cmd  --add-port=80/tcp  --permanent
                                                               //永久开启 80 端口(全局)
[root@client ~]# firewall-cmd  --remove-port=80/tcp  --permanent
                                                               //永久关闭 80 端口(全局)
[root@client ~]# firewall-cmd  --add-port=65001-65010/tcp  --permanent
                                                               //永久开启 65001-65010端口(全局)
[root@client ~]# firewall-cmd --zone=public --add-port=80/tcp  --permanent                                                                                          //永久开启 80 端口(区域 public)
[root@client ~]#  firewall-cmd --zone=public --remove-port=80/tcp  --permanent
                                                                //永久关闭 80端口(区域 public)                                 
[root@client ~]#   firewall-cmd --zone=public --add-port=65001-65010/tcp  --permanent                                                                          //永久开启 65001-65010 端口(区域 public)
[root@client ~]# firewall-cmd  --query-port=8080/tcp
                                                               //查询端口是否开放
[root@client ~]# firewall-cmd  --permanent  --add-port=80/tcp
                                                               //开放 80 端口
[root@client ~]#
firewall-cmd  --permanent  --remove-port=8080/tcp
                                                               //移除端口
[root@client ~]#
firewall-cmd  --reload                                                                                                                                                     //重启防火墙(修改配置后要重启防火墙)

使用终端管理工具实例

1.查看firewalld服务当前状态和使用的区域

[root@client ~]# firewall-cmd  --state

                                                               //查看防火墙状态
[root@client ~]# systemctl  restart  firewalld
[root@client ~]# firewall-cmd  --get-default-zone

                                                               //查看默认区域

2.查询防火墙生效ens160网卡在firewalld服务中的区域

[root@client ~]# firewall-cmd  --get-active-zones

                                                               //查看当前防火墙中生效的区域

[root@client ~]# firewall-cmd  --set-default-zone=trusted

                                                               //设定默认区域

3.把firewalld服务中ens160网卡默认区域修改为external,并在系统重启后生效。分别查看运行时模式与永久模式下的区域名称

[root@client ~]# firewall-cmd  --list-all  --zone=work

                                                               //查看指定区域的防火墙策略

[root@client ~]# firewall-cmd  --permanent  --zone=external  --change-interface=ens160
[root@client ~]# firewall-cmd  --get-zone-of-interface=ens160
[root@client ~]# firewall-cmd  --permanent  --get-zone-of-interface=ens160

4.把firewalld服务的当前默认区域设置为public

[root@client ~]# firewall-cmd --set-default-zone=public
[root@client ~]# firewall-cmd --get-default-zone

5.启动/关闭firewalld服务的应急状况模式,阻断一切网络连接

[root@client ~]# firewall-cmd  --panic-on

[root@client ~]# firewall-cmd  --panic-off

6.查询public区域是否允许请求SSH和HTTPS的流量

[root@client ~]# firewall-cmd  --zone=public  --query-service=ssh
[root@client ~]# firewall-cmd  --zone=public  --query-service=https

7.把firewalld服务中请求https的流量设置为永久允许,并立即生效

[root@client ~]# firewall-cmd  --get-services

                                                               //查看所有可以设定的服务

[root@client ~]# firewall-cmd --zone=public --add-service=https
[root@client ~]# firewall-cmd  --permanent  --zone=public  --add-service=https
[root@client ~]# firewall-cmd  --reload
[root@client ~]# firewall-cmd  --list-all

                                                               //查看生效的防火墙策略

8.把firewalld服务中请求https的流量设置为永久拒绝,并立即生效

[root@client ~]# firewall-cmd  --permanent  --zone=public  --remove-service=https
[root@client ~]# firewall-cmd  --reload
[root@client ~]# firewall-cmd  --list-all

                                                               //查看生效的防火墙策略

9.把在firewalld服务中访问8088和8089端口的流量策略设置为允许,但仅限当前生效

[root@client ~]# firewall-cmd  --zone=public  --add-port=8088-8089/tcp
[root@client ~]# firewall-cmd  --zone=public  --list-ports

图像化的配置

先配置yum仓库

[root@server ~]#cd /etc/yum.repos.d/

[root@server ~]#rm   -f    *

[root@server ~]#curl -o /etc/yum.repos.d/CentOS-Base.repo

https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

[root@server ~]#sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

[root@server ~]# mount /dev/cdrom /media/

[root@server ~]# dnf install  firewall-config  -y

设置SELinux的模式

使用配置文件设置SELinux的模式

[root@client ~]# cat  /etc/selinux/config   -n     

使用命令行命令设置SELinux的模式

[root@client ~]# getenforce

[root@client ~]# setenforce  permissive

[root@client ~]# setenforce  1

[root@client ~]# setenforce  0

[root@client ~]# sestatus

查看用户、文件和进程的安全上下文

Z都是大写!!!

[root@client ~]# id  -Z


[root@client ~]# ls  -Zl

[root@client ~]# ps  -Z


http://www.mrgr.cn/news/96691.html

相关文章:

  • 【Yolov8部署】 VS2019 + opencv + onnxruntime 环境下部署目标检测模型
  • mysql 八股
  • C语言常用的字符串函数
  • 06-02-自考数据结构(20331)- 查找技术-动态查找知识点
  • 蓝桥杯 刷题对应的题解
  • Java基础 3.31
  • 【Feign】⭐️使用 openFeign 时传递 MultipartFile 类型的参数参考
  • SpringBoot详细教程(持续更新中...)
  • HCIP(RSTP+MSTP)
  • 记忆学习用内容
  • Sentinel[超详细讲解]-4
  • Axure疑难杂症:完美解决文本框读取、赋值、计数(玩转文本框)
  • 安卓一些接口使用
  • python文件的基本操作和文件读写
  • 实现在Unity3D中仿真汽车,而且还能使用ros2控制
  • Docker部署sprintboot后端项目
  • 【Golang】泛型与类型约束
  • 【第十三届“泰迪杯”数据挖掘挑战赛】【2025泰迪杯】【思路篇】A题解题全流程(持续更新)
  • 浏览器 ➔ 服务器or服务器 ➔ 浏览器:
  • linux进程信号 ─── linux第27课