根据多个来源(例如https://stackoverflow.com/questions/11719572/how-to-simulate-different-nat-behaviours),iptables的MASQUERADE
行为类似于对称NAT(即端点相关映射和端点相关过滤行为)。
我按照下列方式在 Linux 机器上设置了 NAT:
sysctl net.ipv4.ip_forward=1
iptables -A FORWARD -i enp7s0 -o enp1s0 -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate related,established -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.1.1.0/24 -o enp1s0 -j MASQUERADE
(enp7s0
是 LAN 接口,10.1.1.0/24
是 LAN 子网,enp1s0
是 WAN 接口)
然后我使用 STUN 运行 NAT 行为测试(在内部网络上的另一个系统上):
$ turnutils_natdiscovery stunserver2024.stunprotocol.org -m
-= Mapping Behavior Discovery =-
========================================
RFC 5780 response 1
No ALG: Mapped == XOR-Mapped
0: (1892021): INFO: IPv4. Response origin: : 3.132.228.249:3478
0: (1892021): INFO: IPv4. Other addr: : 3.135.212.85:3479
0: (1892021): INFO: IPv4. UDP reflexive addr: 1.2.3.4:58197
0: (1892021): INFO: IPv4. Local addr: : 0.0.0.0:58197
========================================
RFC 5780 response 2
No ALG: Mapped == XOR-Mapped
0: (1892021): INFO: IPv4. Response origin: : 3.135.212.85:3478
0: (1892021): INFO: IPv4. Other addr: : 3.132.228.249:3479
0: (1892021): INFO: IPv4. UDP reflexive addr: 1.2.3.4:58197
0: (1892021): INFO: IPv4. Local addr: : 0.0.0.0:58197
========================================
NAT with Endpoint Independent Mapping!
========================================
$ turnutils_natdiscovery stunserver2024.stunprotocol.org -f
-= Filtering Behavior Discovery =-
========================================
RFC 5780 response 1
No ALG: Mapped == XOR-Mapped
0: (1892024): INFO: IPv4. Response origin: : 3.132.228.249:3478
0: (1892024): INFO: IPv4. Other addr: : 3.135.212.85:3479
0: (1892024): INFO: IPv4. UDP reflexive addr: 1.2.3.4:34370
0: (1892024): INFO: IPv4. Local addr: : 0.0.0.0:34370
STUN receive timeout..
STUN receive timeout..
========================================
NAT with Address and Port Dependent Filtering!
========================================
如您所见,映射是与端点无关的,因此根据旧术语,它将是端口限制锥形 NAT 。
为了确保万无一失,我使用 OPNsense 进行了测试,测试实用程序正确检测到了对称 NAT。
问题是:为什么我的发现与我在网上找到的信息不同?有没有办法在 Linux 上使用对称 NAT?