Windows 使用 netsh 实现端口转发

netsh Windows About 981 words

前提条件

需要以管理员权限运行。

新增端口转发

命令

netsh interface portproxy add v4tov4 listenport=本地监听端口 connectaddress=转发到的地址 connectport=转发到的端口

示例:监听本地18080端口,将来自18080的流量转发到127.0.0.18080端口。(可转发到远程地址)

netsh interface portproxy add v4tov4 listenport=18080 connectaddress=127.0.0.1 connectport=8080

查看所有的转发端口

netsh interface portproxy show all

输出

PS C:\> netsh interface portproxy show all

侦听 ipv4:                 连接到 ipv4:

地址            端口        地址            端口
--------------- ----------  --------------- ----------
*               18080       127.0.0.1       8080

查看端口转发的设置

netsh interface portproxy dump

输出

PS C:\> netsh interface portproxy dump

#========================
# 端口代理配置
#========================
pushd interface portproxy

reset
add v4tov4 listenport=18080 connectaddress=127.0.0.1 connectport=8080


popd

# 端口代理配置结束

删除转发规则

注意:listenaddress填写的是show all中侦听的地址。

netsh interface portproxy delete v4tov4 listenport=18080 listenaddress=*

清空当前所有配置规则

netsh interface portproxy reset
Views: 1,598 · Posted: 2022-06-28

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh