netsh是微软Windows系统提供一个命令行脚本工具,可以对本地或者远程计算机的网络进行配置。
假设需要将本机(192.168.88.99)的8080端口,转发到内网另一台主机(192.168.88.5)的8081端口,可以在本机上输入如下的命令:
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=192.168.88.99 connectport=8081 connectaddress=192.168.88.5
如果需要删除输入命令:
netsh interface portproxy delete v4tov4 listenport=8080 listenaddress=192.168.88.99
配置完成后可以通过 netstat -ano | findstr :8080,确认一下本机的8080端口是否处于监听状态。
补充一下net interface portproxy
上下文用法:
add v4tov4 [listenport=]<integer>|<servicename>
[connectaddress=]<IPv4 address>|<hostname>
[[connectport=]<integer>|<servicename>]
[[listenaddress=]<IPv4 address>|<hostname>]
[[protocol=]tcp]
delete v4tov4 [listenport=]<integer>|<servicename>
[[listenaddress=]<IPv4 address>|<hostname>]
[[protocol=]tcp]
小技巧:
禁用系统防火墙:
netsh firewall set opmode disable
启用防火墙:
netsh firewall set opmode enable