Okey,没有注意到您宁愿不使用iptables。安装后socat
,您可以在I上创建这样的端口转发器:
"LOCAL/LISTEN" PORT "TARGET" DEST : PORT
sudo socat TCP4-LISTEN:N,reuseaddr,fork TCP4:T:N
喜欢
sudo socat TCP4-LISTEN:888,reuseaddr,fork TCP4:1.2.3.4:888
有关更多信息,请参见socat手册页。
这是进行端口目标NAT(网络地址转换)的iptables方法。
# allow forwarding
sysctl -w net.ipv4.ip_forward=1
# forward port 888 to host 1.2.3.4:888
iptables -I PREROUTING -t nat -p tcp --dport 888 -j DNAT --to 1.2.3.4:888
# most likely you'll need this to get routing back to your device to work.
# try without this first.
iptables -I POSTROUTING -t nat -j MASQUERADE
有点“安全”的版本,您可以在其中定义允许连接/转发的网络
# forward port 888 to host 1.2.3.4:888 allowd from net 2.2.2.0/24
iptables -I PREROUTING -t nat -p tcp -s 2.2.2.0/24 --dport 888 -j DNAT --to 1.2.3.4:888
iptables -I POSTROUTING -t nat -s 2.2.2.0/24 -j MASQUERADE