12.3. 使用 nftables 配置源 NAT
在路由器中,源 NAT(SNAT)可让您将通过接口发送的数据包 IP 改为专门的 IP 地址。然后,路由器会替换传出数据包的源 IP。
流程
创建一个表:
# nft add table nat将
postrouting链添加到表中:# nft add chain nat postrouting { type nat hook postrouting priority 100 \; }向
postrouting链中添加一条规则,该规则将使用192.0.2.1替换通过ens3的传出数据包的源 IP :# nft add rule nat postrouting oifname "ens3" snat to 192.0.2.1