Linux防火墙与SElinux
文章目录
- 一、防火墙介绍
- 二、iptables和firewalld的区别
- 操作方式:
- 配置层面:
- 性能和管理:
- 三、iptables与firewalld的优缺点
- iptables
- firewalld
- 四、iptables的工作流程
- 五、firewalld的工作流程
- 六、iptables安装与使用
- 6.1、关闭firewalld服务
- 6.2、安装iptables防火墙
- 6.3、启动iptables
- 6.4、显示当前规则(iptables -L)
- 6.5、添加一条规则(iptables -A)
- 6.5、删除一条规则(iptables -D)
- 6.6、保存规则(iptables-save)
- 6.7、加载规则(iptables-restore)
- 6.8、清除规则
- 6.9、配置网络地址转换(iptables -t nat -A)
- 6.10、端口转换
- 七、firewalld的使用
- 7.1、关闭iptables,启动firewalld
- 7.2、开放端口
- 7.3、关闭端口
- 7.4、开放服务
- 7.5、关闭服务
- 7.6、配置策略
- 八、SElinux
- 8.1、SElinux的工作流程
- 8.2、SElinux配置
一、防火墙介绍
Linux防火墙是一种网络安全系统,用于控制进出计算机网络的数据包,以保护内部网络不受外部威胁。
Linux中主要有两种防火墙工具:iptables和firewalld。
iptables:
是一种更接近数据原始操作的防火墙工具,提供了较高的精确度。
它是基于命令行的防火墙管理工具,用户可以通过一系列规则来定义如何处理进入或离开网络接口的数据包。
firewalld:
是CentOS 7及之后版本默认的防火墙管理工具,它取代了之前的iptables防火墙。
firewalld提供了基于区域和服务的防火墙管理方式,使得操作更加容易。
它支持动态防火墙管理,可以根据网络连接的安全等级来自动调整防火墙规则。
二、iptables和firewalld的区别
操作方式:
- iptables是一个较为底层的工具,它允许用户直接操作Linux内核的防火墙规则,提供了很高的灵活性和控制精度。
- firewalld则是一个更高级的工具,它通过命令行或图形界面提供了一个更易用的配置方式,使得非专业用户也能较容易地进行防火墙管理。
配置层面:
- iptables的规则是静态的,一旦设置完成,除非手动修改,否则不会随网络环境的变化而自动调整。
- firewalld支持动态防火墙管理,可以根据网络连接的安全等级来自动调整防火墙规则,这使得它能够更好地适应不断变化的网络环境。
性能和管理:
- 由于iptables直接与内核交互,它在处理大量规则时可能会有性能上的优势。
- firewalld通过提供基于区域和服务的配置,简化了规则的管理,使得维护更加简单直观。
三、iptables与firewalld的优缺点
iptables
优点:
- 灵活性和控制性:iptables提供了非常细致和低层次的控制,允许管理员精确地定义各种复杂的网络流量规则。
- 性能:由于iptables直接与内核交互,处理规则时可能会有更小的性能开销。
- 即时生效:iptables的规则一旦配置,立即生效,无需重启服务。
缺点:
- 复杂性:对于非专业用户来说,iptables的规则可能难以理解和管理,需要一定的专业知识。
- 静态配置:iptables不会根据网络环境的变化自动调整规则,这可能导致维护上的不便。
firewalld
优点:
- 易用性:firewalld提供了基于命令行和图形界面的配置方式,使得规则的设置更加直观和容易。
- 动态管理:支持基于区域和服务的配置,能够根据网络连接的安全等级自动调整防火墙规则。
- 工作层次:firewalld工作在网络层,提供包过滤功能,并且支持IPv4和IPv6。
缺点:
- 相对较新:相比iptables,firewalld是较新的工具,可能在一些老旧的文档和教程中不太常见。
- 潜在的性能影响:虽然firewalld易用,但其高层次的操作可能会引入一些性能开销。
四、iptables的工作流程
iptables的工作流程涉及多个组件,包括表(tables)、链(chains)和规则(rules),它们共同协作来处理网络数据包。
数据包进入:当数据包到达Linux系统时,首先经过的是PREROUTING链。这个链属于NAT表,通常用于做DNAT(目的地网络地址转换)。
路由判断:内核根据数据包的目标地址进行路由判断,确定数据包是发送给本机还是其他主机。如果是发送给本机的,数据包会被送到INPUT链;如果需要转发,则会被送到FORWARD链。
本地处理:对于发送给本机的数据包,会通过INPUT链进行处理。在INPUT链中,可以根据规则定义允许或拒绝特定的数据包进入本机。
转发处理:对于需要转发的数据包,会通过FORWARD链进行处理。在FORWARD链中,可以根据规则定义允许或拒绝特定的数据包通过本机转发。
本地发出:对于本机发出的数据包,会通过OUTPUT链进行处理。在OUTPUT链中,可以根据规则定义允许或拒绝特定的数据包从本机发出。
地址转换:在数据包被发送出去之前,还会经过POSTROUTING链。这个链也属于NAT表,通常用于做SNAT(源网络地址转换)。
规则匹配:在整个流程中,数据包会根据定义好的规则进行匹配。如果匹配成功,就会执行相应的操作,如允许、拒绝或者修改数据包。
默认策略:如果在所有的规则中都没有找到匹配项,那么会根据链的默认策略来处理数据包。默认策略可能是接受(ACCEPT)或丢弃(DROP)。
命令使用:iptables的命令格式为iptables [-t table] COMMAND [chain] CRETIRIA -j ACTION,其中-t指定表名,COMMAND定义对规则的管理操作,CRETIRIA是匹配参数,ACTION是触发动作。
规则管理:可以使用各种命令来添加、删除、插入、清空或列出防火墙规则。例如,-A用于添加规则,-D用于删除规则,-I用于插入规则,-F用于清空规则,-L用于列出规则。
五、firewalld的工作流程
firewalld的工作流程主要涉及定义网络区域、设置安全等级和服务规则,以及与内核的netfilter子系统交互来实现包过滤功能。
网络区域和安全等级:
- firewalld基于网络区域来设置规则,而不是像iptables那样基于接口。网络区域定义了一组规则,这些规则决定了数据包是否可以进入或离开该区域。
- 每个网络区域都有一个安全等级,这个等级决定了该区域的信任程度。例如,公共区域的安全等级较低,而内部区域的安全等级较高。
服务和应用程序规则:
- firewalld支持预定义的服务,这些服务有一组固定的端口号,可以快速地允许或拒绝相关流量。
- 应用程序也可以直接添加防火墙规则,这样用户可以轻松地为特定的服务或应用程序配置防火墙。
两种配置模式:
- 运行时配置是临时的,重启后会丢失。
- 永久配置会保存在系统中,即使重启也不会丢失。
IPv4和IPv6支持:
- firewalld同时支持IPv4和IPv6防火墙设置,以及以太网桥接。
数据包处理:
- 当数据包进入或离开系统时,它们会经过firewalld定义的规则。这些规则基于数据包的来源、目的地、协议类型等因素来决定是否允许数据包通过。
- 如果数据包与任何规则匹配,将执行相应的操作,如允许、拒绝或重定向。
命令行和图形界面:
- firewalld提供了命令行工具和图形界面来管理防火墙规则。这使得非专业用户也能较容易地进行配置。
六、iptables安装与使用
6.1、关闭firewalld服务
想要在默认使用firewalld的linux系统中使用iptables,首先需要关闭firewalld服务,然后安装并配置iptables服务。
# 关闭防火墙
[root@centos ~]# systemctl stop firewalld
# 防火墙开机不自启
[root@centos ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
# 查看防火墙状态
[root@centos ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)Active: failed (Result: exit-code) since Sat 2024-04-27 15:29:35 CST; 2 days agoDocs: man:firewalld(1)Main PID: 26914 (code=exited, status=1/FAILURE)Apr 18 15:20:39 centos systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 18 15:20:40 centos systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 18 15:20:40 centos firewalld[26914]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release...ling it now.
Apr 27 15:29:35 centos systemd[1]: firewalld.service: main process exited, code=exited, status=1/FAILURE
Apr 27 15:29:35 centos systemd[1]: Unit firewalld.service entered failed state.
Apr 27 15:29:35 centos systemd[1]: firewalld.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
6.2、安装iptables防火墙
# 安装iptables
[root@centos ~]# yum install -y iptables iptables-services
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package iptables-1.4.21-35.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package iptables-services.x86_64 0:1.4.21-35.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved==========================================================================================================================================================================================Package Arch Version Repository Size
==========================================================================================================================================================================================
Installing:iptables-services x86_64 1.4.21-35.el7 base 52 kTransaction Summary
==========================================================================================================================================================================================
Install 1 PackageTotal download size: 52 k
Installed size: 23 k
Downloading packages:
iptables-services-1.4.21-35.el7.x86_64.rpm | 52 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : iptables-services-1.4.21-35.el7.x86_64 1/1 Verifying : iptables-services-1.4.21-35.el7.x86_64 1/1 Installed:iptables-services.x86_64 0:1.4.21-35.el7 Complete!
# 查看状态,目前是未启动状态
[root@centos ~]# systemctl status iptables
● iptables.service - IPv4 firewall with iptablesLoaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)Active: inactive (dead)
6.3、启动iptables
# 启动iptables
[root@centos ~]# systemctl start iptables
# 设置开机自启
[root@centos ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
6.4、显示当前规则(iptables -L)
[root@centos ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited# INPUT链:
# 策略(policy):ACCEPT,表示默认情况下允许所有数据包进入。
# 规则:
# ACCEPT all:允许与已建立连接或相关联的数据包通过。
# ACCEPT icmp:允许ICMP协议的数据包通过。
# ACCEPT all:允许所有其他数据包通过。
# ACCEPT tcp dpt:ssh:允许目标端口为SSH(22)的TCP数据包通过。
# REJECT all:拒绝所有其他数据包,并返回ICMP主机禁止响应。Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited# FORWARD链:
# 策略(policy):ACCEPT,表示默认情况下允许所有数据包转发。
# 规则:
# REJECT all:拒绝所有数据包,并返回ICMP主机禁止响应。Chain OUTPUT (policy ACCEPT)
target prot opt source destination # OUTPUT链:
# 策略(policy):ACCEPT,表示默认情况下允许所有数据包输出。
# 规则:无特定规则,表示允许所有数据包输出。
6.5、添加一条规则(iptables -A)
- 指定规则链:需要确定要向哪个规则链添加规则,常见的规则链有 INPUT、OUTPUT 和 FORWARD。
- 指定规则选项:可以通过 -s 指定源地址,-p 指定协议类型(如 tcp、udp),–dport 指定目标端口,-m state --state 指定连接状态等。
- 指定动作:最后,通过 -j 指定匹配到规则后的动作,如 ACCEPT(接受)、DROP(丢弃)等。
# 添加一条 iptables 规则,用于允许来自 IP 地址为 192.168.10.233 的主机通过端口 22 进行新的 TCP 连接.[root@centos ~]# iptables -A INPUT -s 192.168.10.233 -p tcp -m state --state NEW --dport 22 -j ACCEPT# iptables: 这是 iptables 命令的名称,用于配置 Linux 内核防火墙。
# -A INPUT: -A 表示添加一条新规则到指定的规则链中,这里指定了 INPUT 链。INPUT 链用于处理进入本机的数据包。
# -s 192.168.10.233: -s 表示源地址,这里指定了源地址为 192.168.10.233。
# -p tcp: -p 表示协议类型,这里指定了协议为 TCP。
# -m state --state NEW: -m 表示使用扩展模块,这里使用了 state 模块来匹配数据包的状态。--state NEW 表示只匹配状态为 NEW(新建)的数据包。
# --dport 22: --dport 表示目标端口,这里指定了目标端口为 22。
# -j ACCEPT: -j 表示动作,这里指定了动作为 ACCEPT,即接受该数据包。
[root@centos ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- 192.168.10.233 anywhere state NEW tcp dpt:sshChain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)
target prot opt source destination # ACCEPT:表示允许数据包通过。
# tcp:表示协议类型为TCP。
# --:表示没有指定源地址和目标地址。
# 192.168.10.233:表示源IP地址为192.168.10.233。
# anywhere:表示目标地址可以是任意地址。
# state NEW:表示只匹配状态为新建(NEW)的TCP连接。
# tcp dpt:ssh:表示目标端口为SSH(22)。
6.5、删除一条规则(iptables -D)
- 指定规则链:需要确定要从哪个规则链中删除规则,常见的规则链有 INPUT、OUTPUT 和 FORWARD。
- 指定规则选项:通过 -s 指定源地址,-p 指定协议类型(如 tcp、udp),–dport 指定目标端口等。
- 指定动作:最后,通过 -j 指定动作,如 ACCEPT(接受)、DROP(丢弃)等。
# 删除源地址为192.168.10.224的这条规则
[root@centos ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- 192.168.10.233 anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- 192.168.10.234 anywhere state NEW tcp dpt:http
ACCEPT tcp -- 192.168.10.234 anywhere state NEW tcp dpt:81
ACCEPT tcp -- 192.168.10.224 anywhere state NEW tcp dpt:telnetChain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@centos ~]# iptables -D INPUT -s 192.168.10.224 -p tcp -m state --state NEW --dport 23 -j ACCEPT
[root@centos ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- 192.168.10.233 anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- 192.168.10.234 anywhere state NEW tcp dpt:http
ACCEPT tcp -- 192.168.10.234 anywhere state NEW tcp dpt:81Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)
target prot opt source destination
6.6、保存规则(iptables-save)
# 将现有规则保存到iptables.txt文件中
[root@centos /]# iptables-save > iptables.txt
[root@centos /]# ls
bin boot dev etc git-2.31.1 git-2.31.1.tar.gz home iptables.txt lib lib64 lost+found media mnt opt proc root run sbin srv sys test tmp top.txt usr var
[root@centos /]# cat iptables.txt
# Generated by iptables-save v1.4.21 on Mon Apr 29 18:19:41 2024
*nat
:PREROUTING ACCEPT [66997:2941494]
:INPUT ACCEPT [62419:2738538]
:OUTPUT ACCEPT [56263:4129762]
:POSTROUTING ACCEPT [56263:4129762]
:OUTPUT_direct - [0:0]
:POSTROUTING_ZONES - [0:0]
:POSTROUTING_ZONES_SOURCE - [0:0]
:POSTROUTING_direct - [0:0]
:POST_public - [0:0]
6.7、加载规则(iptables-restore)
# 从规则文件夹中加载规则
[root@centos /]# iptables-restore iptables.txt
6.8、清除规则
# 删除INPUT链下的所有规则
[root@centos /]# iptables -F INPUT
[root@centos /]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)
target prot opt source destination
6.9、配置网络地址转换(iptables -t nat -A)
- 指定链:需要确定要添加规则的链,常见的链有 PREROUTING、POSTROUTING 和 OUTPUT。
- 指定选项:可以通过 -s 指定源地址,-d 指定目标地址,–source-port 指定源端口,–destination-port 指定目标端口等。
- 指定动作:最后,通过 -j 指定动作,如 DNAT(目标网络地址转换)、SNAT(源网络地址转换)或 MASQUERADE(伪装)等。
# 将来自 192.168.1.10 的数据包的源地址转换为 1.2.3.4
[root@centos /]# iptables -t nat -A POSTROUTING -s 192.168.1.10 -j SNAT --to-source 1.2.3.4# 查看已经转换多的地址
[root@centos /]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
PREROUTING_direct all -- anywhere anywhere
PREROUTING_ZONES_SOURCE all -- anywhere anywhere
PREROUTING_ZONES all -- anywhere anywhere Chain INPUT (policy ACCEPT)
target prot opt source destination Chain OUTPUT (policy ACCEPT)
target prot opt source destination
OUTPUT_direct all -- anywhere anywhere Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
POSTROUTING_direct all -- anywhere anywhere
POSTROUTING_ZONES_SOURCE all -- anywhere anywhere
POSTROUTING_ZONES all -- anywhere anywhere
SNAT all -- 192.168.1.10 anywhere to:1.2.3.4
6.10、端口转换
# 将外部端口 8080 上的流量转发到内部 IP 地址 192.168.1.100 的端口 80 上
[root@centos /]# iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 192.168.1.100:80# iptables:Linux 系统上用于配置内核防火墙规则的命令。
# -t nat:指定操作 NAT 表。
# -A PREROUTING:在 PREROUTING 链中添加规则。PREROUTING 链是在数据包进入网络堆栈之前进行处理的规则链。
# -p tcp:指定要匹配的协议类型为 TCP。
# --dport 8080:指定要匹配的目标端口号为 8080。
# -j DNAT:指定动作为 DNAT(目标网络地址转换)。
# --to-destination 192.168.1.100:80:指定转换后的目标 IP 地址和端口号为 192.168.1.100 和 80。# 查看端口转发
[root@centos /]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
PREROUTING_direct all -- anywhere anywhere
PREROUTING_ZONES_SOURCE all -- anywhere anywhere
PREROUTING_ZONES all -- anywhere anywhere
DNAT tcp -- anywhere anywhere tcp dpt:webcache to:192.168.1.100:80
七、firewalld的使用
centos中默认是安装firewalld防火墙的,所以不需要再自行下载。
7.1、关闭iptables,启动firewalld
# 查看iptables的状态
[root@centos ~]# systemctl status iptables
● iptables.service - IPv4 firewall with iptablesLoaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)Active: active (exited) since Mon 2024-04-29 17:34:46 CST; 15h agoMain PID: 12599 (code=exited, status=0/SUCCESS)Apr 29 17:34:46 centos systemd[1]: Starting IPv4 firewall with iptables...
Apr 29 17:34:46 centos iptables.init[12599]: iptables: Applying firewall rules: [ OK ]
Apr 29 17:34:46 centos systemd[1]: Started IPv4 firewall with iptables.# 停止并禁止自启iptables
[root@centos ~]# systemctl stop iptables
[root@centos ~]# systemctl disable iptables
Removed symlink /etc/systemd/system/basic.target.wants/iptables.service.# 启动firewalld,并设置自启动
[root@centos ~]# systemctl start firewalld
[root@centos ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
7.2、开放端口
# 在 public 区域中打开 http 服务的默认端口
[root@centos ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success# 使配置立即生效
[root@centos ~]# firewall-cmd --reload
success# 查看已经生效的配置
[root@centos ~]# firewall-cmd --list-all-zones
publictarget: defaulticmp-block-inversion: nointerfaces: sources: services: dhcpv6-client sshports: 22/tcp 80/tcpprotocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules:
- firewall-cmd 命令是 Firewalld 提供的一个命令行工具,用于直接从命令行配置和管理防火墙
- –zone 参数指定要操作的区域
- –add-port 参数添加一个端口到指定区域允许流量通过
- –permanent表示永久生效
7.3、关闭端口
# 使public区域的80端口失效
[root@centos ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent
success# 立即生效
[root@centos ~]# firewall-cmd --reload
success# 查看当前生效的配置
[root@centos ~]# firewall-cmd --list-all-zones
publictarget: defaulticmp-block-inversion: nointerfaces: sources: services: dhcpv6-client sshports: 22/tcpprotocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules:
7.4、开放服务
# 开放http服务,这里是将--add-port改为--add-service即可
[root@centos ~]# firewall-cmd --zone=public --add-service=http --permanent
success
[root@centos ~]# firewall-cmd --reload
success
[root@centos ~]# firewall-cmd --list-all-zones
publictarget: defaulticmp-block-inversion: nointerfaces: sources: services: dhcpv6-client http sshports: 22/tcpprotocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules:
7.5、关闭服务
# 关闭http服务
[root@centos ~]# firewall-cmd --zone=public --remove-service=http --permanent
success
[root@centos ~]# firewall-cmd --reload
success
[root@centos ~]# firewall-cmd --list-all-zones
publictarget: defaulticmp-block-inversion: nointerfaces: sources: services: dhcpv6-client sshports: 22/tcpprotocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules:
7.6、配置策略
# 在 public 区域中允许来自 IP 地址为 192.168.0.100 的主机访问 HTTP 服务
[root@centos ~]# firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.100" service name="http" accept'
success
[root@centos ~]# firewall-cmd --reload
success
[root@centos ~]# firewall-cmd --list-all-zones
publictarget: defaulticmp-block-inversion: nointerfaces: sources: services: dhcpv6-client sshports: 22/tcpprotocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules: rule family="ipv4" source address="192.168.0.100" service name="http" accept
八、SElinux
SELinux(Security-Enhanced Linux)是一个安全模块,它通过强制访问控制(MAC)机制来限制进程对资源的访问,以此提高系统的安全性。在没有使用SELinux的操作系统中,资源的访问控制是基于自主访问控制(DAC),即用户拥有的权限决定资源是否能被访问。这种机制存在缺陷,尤其是root用户几乎可以无限制地访问所有资源。SELinux通过赋予每个文件、目录、进程等一个安全上下文,配合事先定义好的安全策略,来判断哪些操作是允许的,哪些是禁止的,从而防止未经授权的访问和潜在的安全威胁。
SELinux的主要用途是提供最小权限原则的安全策略,确保系统中的服务进程只能访问必要的资源。
8.1、SElinux的工作流程
为资源分配安全上下文:这涉及到文件、目录和进程,安全上下文包含了类型、角色、用户等信息,用于标识所属的安全域和访问权限。
定义安全策略:安全策略是SELinux的核心,它包含了一系列的规则,用于判断进程能否访问某个资源或执行某个操作。
实施访问控制:当进程尝试访问资源时,SELinux会根据进程的安全上下文、资源的安全上下文以及安全策略来决定是否允许此访问。
要配置SELinux,通常需要进行以下操作:
修改配置文件:编辑/etc/sysconfig/selinux文件来设置SELinux的运行模式。
更改运行模式:可以使用setenforce命令临时切换SELinux的模式,0代表宽容模式(permissive),1代表强制模式(Enforcing)。
管理安全上下文:使用ls -Z、ps -Z等命令查看安全上下文,使用mv、cp等命令管理文件的安全上下文。
布尔值配置:通过getsebool、setsebool等命令调整SELinux的各项布尔值设置,以开启或关闭某些服务的功能。
管理策略模块:利用semanage等工具来管理策略模块,进一步细化安全策略的应用。
8.2、SElinux配置
[root@centos ~]# cd /etc/sysconfig/# 修改SELINUX=disabled可以决定是否使用selinux,目前是进制状态
[root@centos sysconfig]# cat selinux# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
相关文章:
Linux防火墙与SElinux
文章目录 一、防火墙介绍二、iptables和firewalld的区别操作方式:配置层面:性能和管理: 三、iptables与firewalld的优缺点iptablesfirewalld 四、iptables的工作流程五、firewalld的工作流程六、iptables安装与使用6.1、关闭firewalld服务6.2…...
【MySQL】基本查询(上):创建、读取
1.Create(创建) 语法: INSERT [INTO] table_name [(column [, column] ...)] VALUES (value_list) [, (value_list)] ...value_list: value, [, value] ... 接下来我们用这个下表作为例子: -- 创建一张学生表 CREATE TABLE students ( id INT UNSIGN…...
在线刷题系统测试报告
一、项目背景 1. 本项目是一个在线刷题系统,灵感来源于力扣和牛客等刷题平台,旨在锻炼自己的代码能力和剖析系统整体结构与各模块之间关系的能力。系统支持用户注册与登录,查看题目列表与题目详情,在线提交代码并提供反馈。 2. 该…...
即时通讯增加Redis渠道
情况说明 在本地和服务器分别启动im服务,当本地发送消息时,会发现服务器上并没有收到消息 初版im只支持单机版,不支持分布式的情况。此次针对该情况对项目进行优化,文档中贴出的代码非完整代码,可自行查看参考资料[2] 代码结构调…...
C++list
list简介 list是我们的链表,而且是带头双向循环链表,如下图 我们都知道,链表是由一个一个的节点组成的,它的成员由下面几个部分组成 通过对前面string,vector的学习,其实再来看我们的链表及其成员函数,是…...
设计模式 - 结构型
结构型 适配器模式,代理模式,桥接模式,装饰器模式,外观模式,组合模式,享元模式, 单一职责避免子类爆炸Bridge 模式对象的实现Decorator 模式对对象的职责,不生成子类接口隔离Adapt…...
STM32编码器接口
一、概述 1、Encoder Interface 编码器接口概念 编码器接口可接收增量(正交)编码器的信号,根据编码器旋转产生的正交信号脉冲,自动控制CNT自增或自减,从而指示编码器的位置、旋转方向和旋转速度每个高级定时器和通用…...
2024客户世界年度大会开幕,码号卫士赋能数字运营服务新升级
10月15日,2024年客户世界年度的大会在通州北投希尔顿酒店开幕。作为行业内的一个重要活动,本次大会以“数字运营支撑服务产业新升级”为主题,吸引了众多行业专家和企业代表。 据悉,本次大会以“数字运营支撑服务产业新升级”为主题…...
AcWing 802. 区间和(离散化算法,python)
本篇博客详细讲解一下离散化知识点,通过讲解和详细列题带大家掌握离散化。 题目: 原题链接:https://www.acwing.com/problem/content/description/804/ 假定有一个无限长的数轴,数轴上每个坐标上的数都是 0。 现在,…...
【网页设计】CSS 盒子模型
目标 能够准确阐述盒子模型的 4 个组成部分能够利用边框复合写法给元素添加边框能够计算盒子的实际大小能够利用盒子模型布局模块案例能够给盒子设置圆角边框能够给盒子添加阴影能够给文字添加阴影 1. 盒子模型 页面布局要学习三大核心, 盒子模型, 浮动 和 定位. 学习好盒子模…...
如何通过构建对应的api服务器使Vue连接到数据库
一、安装数据库驱动 在后端安装 MySQL 数据库驱动,比如在 Node.js 环境中可以使用 mysql2 包来连接 MySQL 数据库。在项目目录下运行以下命令安装: npm install mysql2或者使用 yarn: yarn add mysql2二、创建数据库连接模块 创建一个专门…...
新手给视频加字幕的方法有哪些?4种加字幕方法推荐!
在视频制作中,字幕不仅是传递信息的重要手段,还能增强视频的观感和专业性。对于新手来说,如何给视频添加字幕可能是一个挑战。本文将介绍字幕的类型、推荐添加字幕的工具,以及详细添加字幕方法,帮助新手轻松掌握视频字…...
Oracle实际需要用到但常常被忽略的函数
1、Oracle中nvl()与nvl2()函数 函数nvl(expression1,expression2)根据参数1是否为null返回参数1或参数2的值; 函数nvl2(expression1,expression2,expression3)根据参数1是否为null返回参数2或参数3的值 【函数格式】:nvl(expression1,expression2) 若…...
代码随想录算法训练营Day23
局部最优——>全局最优&无反例,试试贪心 455.分发饼干 力扣题目链接:. - 力扣(LeetCode) class Solution {public int findContentChildren(int[] g, int[] s) {Arrays.sort(s);Arrays.sort(g);int gindex0;int count0;…...
vue使用table实现动态数据报表(行合并)
<template><div class"previewTable"><h2>***项目研发数据报告</h2><table id"previewTable" width"100%"><tr><th>项目名称</th><td colspan"6">{{ resultData.proName }}<…...
YARN调度原理详解
YARN(Yet Another Resource Negotiator)是 Hadoop 集群的资源管理和作业调度框架,它的设计旨在更好地管理和调度 Hadoop 集群中的资源。YARN 解决了传统 Hadoop MapReduce 中资源管理与作业调度紧耦合的问题,使得不同类型的计算任…...
Go-知识泛型
Go-知识泛型 1. 认识泛型1.1 不使用泛型1.2 使用泛型 2. 泛型的特点2.1 函数泛化2.2 类型泛化 3. 类型约束3.1 类型集合3.2 interface 类型集合3.2.1 内置interface类型集合3.2.2 自定义interface类型集合3.2.2.1 任意类型元素3.2.2.2 近似类型元素3.2.2.3 联合类型元素 3.2.3 …...
Qt 如何 发送与解析不定长报文以及数组不定长报文
文章目录 割方式一,采用QDataStream 解析,可直接设定大小端解析,无需自己转换方式二,采用结构体字节对齐方式解析发送接收方割 方式一,采用QDataStream 解析,可直接设定大小端解析,无需自己转换 需要注意的是结构体定义要去掉字节对齐,否则会崩溃,因为由自定义数据结…...
Rust默认使用UTF-8编码来解析源代码文件。如果在代码中包含无法用UTF-8编码表示的字符,编译器会报错!
文章目录 Rust默认编码示例在ANSI编码下中文显示正常的代码在UTF-8编码下将显示不正常在编译时,Rust使用UTF-8编码来解析代码,发现无法用UTF-8编码表示的字符,于是编译器报错 Rust默认编码 Rust 语言默认使用 UTF-8 编码来解析源代码文件。如…...
【jeston】torch相关环境安装
参考:玩转NVIDIA Jetson (25)— jetson 安装pytorch和torchvision 我的jeston信息: torch install 安装环境 conda create -n your_env python3.8 conda activate your_envpytorch_for_jeston 安装.whl文件 验证࿱…...
别再只盯着KNN了:聊聊Wi-Fi指纹定位中那些被低估的匹配算法与实战选择
超越KNN:Wi-Fi指纹定位中的高阶匹配算法与工程化选型指南 商场里找不到心仪店铺的焦虑、仓库中耗时的手动货品盘点、医院里紧急设备定位的延迟——这些场景背后都指向同一个技术痛点:室内定位精度不足。当大多数开发者习惯性采用KNN算法时,我…...
根据您提供的写作范围,我为您总结的标题为:“昆通泰MCGS7.7嵌入版:6车位停车场监控系统仿...
6车位停车场监控系统昆通泰MCGS7.7嵌入版仿真运行带运行效果视频6车位停车场监控系统用昆通泰MCGS7.7嵌入版做仿真,真的是新手友好型项目——不用扛硬件、不用接复杂通讯,靠内部变量和几段脚本就能把核心逻辑跑通,还能直观看到实时效果&#…...
Milvus向量数据库Docker安装避坑指南:从配置到可视化工具Attu的完整流程
Milvus向量数据库Docker安装避坑指南:从配置到可视化工具Attu的完整流程 当开发者第一次接触向量数据库时,往往会遇到各种意想不到的"坑"。作为一款开源的向量数据库,Milvus因其高性能和易用性而广受欢迎,但在Docker环境…...
终极指南:如何从零开始打造你的第一台六足机器人
终极指南:如何从零开始打造你的第一台六足机器人 【免费下载链接】hexapod 项目地址: https://gitcode.com/gh_mirrors/hexapod5/hexapod 你是否梦想过亲手制作一台能够灵活行走、稳定爬行的六足机器人?想要体验机器人制作的乐趣,却担…...
【24年最新算法】首发CPO-XGBoost回归+交叉验证 基于冠豪猪优化算法-XGBoost多变量回归预测
✅作者简介:热爱科研的Matlab仿真开发者,擅长毕业设计辅导、数学建模、数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。🍎 往期回顾关注个人主页:Matlab科研工作室👇 关注我领取海量matlab电子书和…...
Qwen3-0.6B-FP8多语言落地:支持粤语、闽南语、藏语等方言指令理解实测
Qwen3-0.6B-FP8多语言落地:支持粤语、闽南语、藏语等方言指令理解实测 1. 引言:当AI能听懂你的家乡话 想象一下,你正在用粤语和AI助手聊天,让它帮你写一份工作报告;或者用闽南语问它今天的天气,它不仅能听…...
无人机控制中的模糊控制:一维与二维模糊控制及其实现要点
无人机 控制方面 模糊控制 有一维模糊和二维模糊两种,文字说明资料已遗失,数学模型可以根据仿真图推导,直接运维simulink会报错,是因为没有导入模糊规则,在运行simulink之前需要在命令窗口输入workreadfis work.fis ,这…...
2025年开源工具jable-download:视频下载工具高效解决方案
2025年开源工具jable-download:视频下载工具高效解决方案 【免费下载链接】jable-download 方便下载jable的小工具 项目地址: https://gitcode.com/gh_mirrors/ja/jable-download 在数字化内容消费日益增长的今天,视频资源的获取与保存成为许多用…...
TC3XX Autosar系统中文配置手册:包含19个模块的详细解析与联系指南
tc3xx autosar EB中文配置手册,需要联系。 一共有大约19个模块。 在汽车电子开发领域,TC3xx系列芯片AUTOSAR架构的组合越来越常见。最近研究EB(Elektrobit)配置工具时,发现其19个核心模块的配置逻辑其实藏着不少"…...
SpringBoot+Vue实战:手把手教你搭建社区居民健康档案管理系统(附完整源码)
SpringBootVue实战:从零构建社区居民健康档案管理系统 在数字化转型浪潮下,社区卫生服务正经历着从纸质档案到智能化管理的转变。对于Java开发者而言,这不仅是技术练兵的好机会,更是解决实际社会需求的切入点。本文将带你用Spring…...
