介绍
作为一名系统管理员,管理防火墙设置是保障服务器安全的关键任务。在 Red Hat Enterprise Linux (RHEL) 中,firewalld 是默认的防火墙管理工具,它通过 firewall-cmd 命令行工具进行配置。在本挑战中,你将练习使用 firewall-cmd 来配置防火墙规则,从而控制网络流量。
配置防火墙
你的任务是修改当前的防火墙规则以允许 Web 流量。firewalld 服务已经在你的环境中运行。你需要为标准的 Web 流量端口添加规则,并确保这些更改是永久生效的。
任务
- 任务 1:检查
firewalld服务的当前状态,确保其正在运行。 - 任务 2:添加永久防火墙规则以允许
http(端口 80) 和https(端口 443) 服务。 - 任务 3:重新加载防火墙配置,将永久更改应用到运行时配置中。
- 任务 4:验证
http和https服务是否已列在活动的防火墙规则中。
要求
- 所有防火墙修改必须使用
firewall-cmd命令执行。 http和https的规则必须添加到永久配置中,以便在重新加载后依然有效。- 重新加载后,活动配置必须显示
http和https服务已被允许。
示例
当你成功完成所有任务后,sudo firewall-cmd --list-all 的输出应在服务列表中包含 http 和 https,类似于下方的示例。其他细节可能会有所不同。
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0 eth1
sources:
services: cockpit dhcpv6-client http https ssh
ports:
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
提示
- 使用
sudo firewall-cmd --state来检查防火墙是否正在运行。如果防火墙未运行,你可以通过运行sudo systemctl start firewalld来启动它。 - 若要使规则永久生效,请使用
--permanent标志。 - 在使用
sudo firewall-cmd --reload重新加载防火墙之前,永久规则不会应用到运行中的配置。
总结
在本挑战中,你学习了如何使用 firewall-cmd 在 Red Hat Enterprise Linux 系统上管理防火墙规则。你练习了检查防火墙状态、添加永久服务规则、重新加载防火墙以应用更改以及验证活动配置。这些是任何负责网络安全的系统管理员必须掌握的基本技能。



