2014-04-03 50 views
-1

我想弄清楚如何添加與IPTables 1:1 NAT,但只在一個端口上,我知道如何轉發所有流量,但似乎無法找到在單一端口上的內容,如IPTables 1:1 NAT在單個端口

192.168.1.1:21 -> 172.16.1.1:21 
192.168.1.2:21 -> 172.16.1.2:21 
192.168.1.3:21 -> 172.16.1.3:21 
192.168.1.4:21 -> 172.16.1.4:21 

我不能用做說,因爲還有其他的應用也做其他端口的流量重定向只允許一個端口。

我到目前爲止的所有內容都是這樣的,但它沒有指定它最初作爲參數登陸的IP。

sysctl net.ipv4.ip_forward=1 
iptables -t nat -A PREROUTING -p tcp --dport port -j DNAT --to-destination ip:port 
iptables -t nat -A POSTROUTING -j MASQUERADE 

回答

2

使用-d標誌指定原始目標。

iptables -t nat -A PREROUTING -d <external-ip> -p tcp --dport port -j DNAT --to-destination <internal-ip>:port