1.先查看物理网卡的网络情况,ipconfig /all
2.确认公网IP(既虚拟机共享上网的那个网卡的IP),私网IP(就是虚拟机nat桥接的那个IP)
netsh interface portproxy add v4tov4 listenport=外网端口 listenaddress=主IP connectaddress=私网IP connectport=私网IP端口
如下例
netsh interface portproxy add v4tov4 listenport=80 listenaddress=119.146.62.231 connectaddress=192.168.1.251 connectport=80
内网端口可以不一致
netsh interface portproxy add v4tov4 listenport=2022 listenaddress=119.146.62.231 connectaddress=192.168.1.251 connectport=22
删除映射
netsh interface portproxy delete v4tov4 listenaddress=119.146.62.231 listenport=2022
查询端口映射情况
netsh interface portproxy show v4tov4
共享IP端口映射一些常用命令
一、查询端口映射情况
netsh interface portproxy show v4tov4
查询这个IP所有的端口映射。
netsh interface portproxy show v4tov4|find "192.168.1.1"
二、增加一个端口映射
netsh interface portproxy add v4tov4 listenport=外网端口 listenaddress=主IP connectaddress=私网IP connectport=私网IP端口
例如:
netsh interface portproxy add v4tov4 listenport=8888 listenaddress=118.123.13.180 connectaddress=192.168.1.10 connectport=2222
三、删除一个端口映射
netsh interface portproxy delete v4tov4 listenaddress=主IP listenport=外网端口
netsh interface portproxy delete v4tov4 listenport=3306