前言
Windows 下面有一个类似于linux下面DNAT的功能(netsh),netsh 是windows 系统自XP版本之后出现的强大工具,可以实现windows 下面的网络配置,我用过的有:重启网卡、配置转发;当然它远不止这些功能,还有防火墙策略的设定、wlan的配置、dhcp的更改等等;
环境
PS:我在服务器上面开启了一个80端口的监听,用来做测试;
操作步骤
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=192.168.1.107 connectport=80 connectaddress=192.168.1.107
- netstat interface portproxy add v4tov4 是固定格式;
- listenport 要转发的端口,这里这个不是实际机器上面的监听端口,为啥要这么取名,我也不是很清楚;
- listenaddress 是要转发的地址,如果这里有多个网卡,就用的不是这个地址了;
- connectport 是实际监听服务的网卡信息;
- connectaddress:是实际要链接的网卡地址;
netsh interface portproxy reset
清空当前系统中存在的转发规则
netsh interface portproxy show all
查看当前系统中存在的转发规则;
PS:上面这种转发默认是TCP的,UDP的我还没来得及实验;可以考虑加一下这个参数试验一下(protocol=tcp),加到最后即可