本文共 1918 字,大约阅读时间需要 6 分钟。
iptables 是 Linux 系统中最常用的防火墙工具,主要用于管理网络流量。以下是 iptables 的一些基本概念:
在 RHEL 8 中,默认使用 firewalld。但有时可能需要切换回 iptables:
dnf install iptables-services -ysystemctl stop firewalldsystemctl disable firewalldsystemctl mask firewalldsystemctl enable --now iptables
dnf install firewalld -ysystemctl stop iptablessystemctl disable iptablessystemctl mask iptablessystemctl enable --now firewalld
# 保存到文件iptables-save > /etc/sysconfig/iptables
service iptables save
默认策略包含 5 条链:
链名 | 含义 |
---|---|
input | 输入 |
output | 输出 |
forward | 转发 |
postrouting | 路由之后 |
prerouting | 路由之前 |
默认的 3 张表:
表名 | 含义 |
---|---|
filter | 经过内核的数据 |
nat | 不经过内核的数据 |
mangle | 特殊情况 |
数据包状态:
状态 | 含义 |
---|---|
RELATED | 已建立连接 |
ESTABLISHED | 正在连接 |
NEW | 新连接 |
systemctl stop iptablessystemctl disable iptablessystemctl mask iptablessystemctl enable --now firewalld
firewalld 支持多个域:
域名 | 描述 |
---|---|
trusted | 接受所有网络连接 |
home | 家庭网络 |
work | 工作网络 |
public | 公共网络 |
dmz | 军级网络 |
block | 拒绝所有 |
drop | 丢弃所有 |
internal | 内部网络 |
external | 外部网络 |
# 查看 listening 端口netstat -antupye | grep sshd
iptables -Lfirewall-cmd --list-all
ping 172.25.254.3ssh root@172.25.254.203
通过以上配置,能够实现对网络流量的有效管理,确保系统安全且功能正常。
转载地址:http://lwrlz.baihongyu.com/