如何路由或使用 iptables 将一个服务器端口转发到不同子网上的客户端

如何路由或使用 iptables 将一个服务器端口转发到不同子网上的客户端

设置(全部是Linux):

client IP address: 192.168.2.15 (interface eth1)
box IP address: 192.168.2.2 (interface eth1)
box IP address: 192.168.101.11 (interface eth0)
server IP address: 192.168.101.12 (interface eth0)

客户端需要通过端口 2300 访问服务器,但位于不同的子网。我该如何配置 iptables 以便客户端接受 box 作为其子网上的服务器?换句话说,如何在客户端和服务器之间路由流量以便:

传出:

192.168.2.15 -> 192.168.2.2 ==> 192.168.101.11 -> 192.168.101.12 (all port 2300)

返回:

192.168.101.12 -> 192.168.101.11 ==> 192.168.2.2 -> 192.168.2.15 (all port 2300)

我已经研究这个问题有一段时间了,似乎这应该是很简单的,但我还不熟悉 iptables。

谢谢!

答案1

虽然这可能不是理想的解决方案,但似乎有效。使用 netcat:

mkfifo proxypipe
while true; do nc -l 9010 0<proxypipe | nc 192.168.101.12 9000 1> proxypipe; done 

请注意,我使用 9010 作为客户端的服务器端口。尽管如此,这仍然完美地在本地复制了服务器。

相关内容