大网数据广告活动
服务器运维问答

Why IP masquerade (source NAT) in linux kernel fails to set source IP on high packet rates

· 52CE 我爱测

I am trying to test throughput of the standard linux NAT. I have setup the following virtual network: [192.168.42.5] <--> [192.168.42.2:192.168.35.2] <--> [192.168.35.10] The middle host has 2 interfaces, runs ubuntu 14.04 and is…

问题原文

原帖链接 · Necto · CC BY-SA 3.0

I am trying to test throughput of the standard linux NAT. I have setup the following virtual network:

[192.168.42.5] <--> [192.168.42.2:192.168.35.2] <--> [192.168.35.10]

The middle host has 2 interfaces, runs ubuntu 14.04 and is configured as NAT:

sysctl -w net.ipv4.ip_forward=1
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -A FORWARD -i eth2 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth2 -o eht1 -j ACCEPT

The [192.168.42.5] host also has the route rule for the second network:

sudo ip route add 192.168.35.0/24 via 192.168.42.2 dev eth1

Then I run hping3 on the [192.168.42.5] host:

sudo hping3 192.168.35.10  -k -s 3453 -S -n -p 80 -i u1000

And I also watch the communication on the [192.168.35.10] with tcpdump:

sudo tcpdump -i eth1

The system works OK on the rates ~1k Pkt/second. tcpdump displays arriving packets:

IP 192.168.42.5.3453 > 192.168.35.10.http: Flags [S], seq 1520954148, win 512, length 0

But when I increase the packet rate (with -i u700 key), for some reason the NAT fails to rewrite the source address, and the target gets packets like this:

IP 192.168.42.5.3453 > 192.168.35.10.http: Flags [S], seq 1554999038, win 512, length 0

and ignores them having no available route to the 192.168.42.0/24 subnet, so hping3 does not get any response. If that happened, I need to relax and wait for about 1-2 minutes, until I can get NAT to the normal operation even on the slow packet rates.

Why does NAT fail so weirdly? If it lacks capacity, why does it stil forward unmodified packets?

P.S. When I set-up the usual router instead of the NAT (with the corresponding rule in the [192.168.35.10] host), it routinely handles even 10k Pkt/s rates.

已采纳解答

原帖链接 · BillThor · CC BY-SA 3.0

The issue may be the -k flag. From what I see, you set up a very unusual setup creating high volumes of connections with the same source/destination. IPtables is a statefull firewall and tracks each connection individually. I would speculate that you end up creating a high volume of collisions in a hash table. This generally slows down access which may be what you are seeing.

The router may be operating in a stateless or semi-stateful manner. This reduces the overhead involved.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。