Red Hat Training
A Red Hat training course is available for RHEL 8
8.4.2. 使用 nftables 配置伪装
伪装使路由器动态地更改通过接口到接口 IP 地址发送的数据包的源 IP。这意味着,如果接口被分配了一个新 IP,nftables
会在替换源 IP 时自动使用新的 IP。
将通过 ens3
接口离开主机的数据包源 IP 替换为 ens3
上设置的 IP。
流程
创建一个表:
# nft add table nat
向表中添加
prerouting
和postrouting
链:# nft add chain nat postrouting { type nat hook postrouting priority 100 \; }
重要即使您没有向
prerouting
链中添加规则,nftables
框架也会要求此链与传入的数据包回复匹配。请注意,您必须将
--
选项传递给nft
命令,以防止 shell 将负优先级值解释为nft
命令的选项。向
postrouting
链中添加一条规则,来匹配ens3
接口上传出的数据包:# nft add rule nat postrouting oifname "ens3" masquerade