具有 DNAT 目标的 iptables 到多端口范围转换

iptables with DNAT target to multiple port range translation

我想使用iptables 来设置DNAT 目标。多端口虚拟 服务器是我想要做的目的。但是我发现DNAT不能 将多端口映射到目标多端口。例如

iptables -t nat -A PREROUTING -p tcp --dport 1000:2000 -j DNAT --到目的地 192.168.1.100:3000-4000

我觉得这条规则应该是 1000 ------> 3000 1001 ------> 3001 ......................... 2000 ------> 4000

我试过用whireshark抓包。不管原装 数据包是 1000、1001、2000 等等,它们似乎转换为端口 3000只。那是有线的 iptables 只将许多端口映射到一个 港口.

有什么建议吗?

谢谢。

iptables-extensions' man page 声明内核 2.6.11-rc1 和更新版本不支持指定多个目标端口:

In Kernels up to 2.6.10 you can add several --to-destination options. For those kernels, if you specify more than one destination address, either via an address range or multiple --to-destination options, a simple round-robin (one after another in cycle) load balancing takes place between these addresses. Later Kernels (>= 2.6.11-rc1) don't have the ability to NAT to multiple ranges anymore.