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

Use Windows as a router

· 52CE 我爱测

I need a client application to connect to a server in a different network. Another computer is connected to both networks as shown here: Client Computer Server 192.168.1.10 <---------> 192.168.1.20 192.168.2.30 <---------> 192.16…

问题原文

原帖链接 · Maxime · CC BY-SA 4.0

I need a client application to connect to a server in a different network. Another computer is connected to both networks as shown here:

   Client                         Computer                        Server
192.168.1.10 <---------> 192.168.1.20  192.168.2.30 <---------> 192.168.2.40
              network 1                              network 2
               (wifi)                                (ethernet)

I need the middle computer (Windows) to act as a router to forward any connection to port 502 to the server. Network 2 is an internal network of an industrial machine, so I'd like to keep it separate from the main network 1 as much as possible, and avoid reconfiguring routers. That means only connecting to the middle computer and redirecting the packets from there if possible.

What is the best way to achieve this?

I already tried netsh interface portproxy add v4tov4 listenport=502 listenaddress=192.168.1.20 connectport=502 connectaddress=192.168.2.40 which works well, but only until the next reboot. If the rule is created or activated just before the wifi connects, it doesn't work, even though it is still visible in netsh interface portproxy show all. Only deleting and recreating the rule, or restarting the iphlpsvc service can get it to work again. Is there a way to fix this?

Is there a better tool, or a better way to do it, like using simple routing or a similar technique? Or are NAT and port forwarding required?

已采纳解答

原帖链接 · Maxime · CC BY-SA 4.0

As suggested in the comments, the simplest solution is to use listenaddress=0.0.0.0 which does seem to make netsh portproxy more reliable.

A better way to do it would be to use or develop a proxy application.

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

资料来源与适用范围

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

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

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