Port Forwarding in Windows
转自:http://woshub.com/port-forwarding-in-windows/
Since Windows XP there is a built-in ability in Microsoft Windows to set up network ports forwarding. Due to it, any incoming TCP connection (IPv4 or IPv6) to local port can be redirected to another local port or even to port on the remote computer. And it is not necessary for system to have a service that listens to this port.
In Linux, port redirection is configured quite simply using iptables. On Windows Server systems, the Routing and Remote Access Service (RRAS) is used to organize port forwarding. However, there is an easier way to configure the port forwarding, which works well in any version of Windows.
Port forwarding in Windows can be configured using Portproxy mode of the command Netsh. The syntax of this command is as follows:netsh interface portproxy add v4tov4 listenaddress=localaddress listenport=localport connectaddress=destaddress connectport=destport
where
- listenaddress – is a local IP address waiting for a connection.
 - listenport – local listening TCP port (the connection is waited on it).
 - connectaddress – is a local or remote IP address (or DNS name) to which the incoming connection will be redirected.
 - connectport – is a TCP port to which the connection from listenport is forwarded to.
 
Let’s imagine that our task is to make the RDP service to respond on a non-standard port, for example 3340 (the port can be changed in the settings of the service, but we will use RDP to make it easier to demonstrate forwarding). To do this, you need to redirect incoming traffic from TCP port 3340 to another local port – 3389 (standard rdp port).
Start the command prompt as an administrator and perform the following command:
netsh interface portproxy add v4tov4 listenport=3340 listenaddress=10.1.1.110 connectport=3389 connectaddress=10.1.1.110

Where 10.10.1.110 – the current IP address of this computer.
Using netstat make sure that port 3340 is listened now:
netstat -ano | findstr :3340


IPv6 support must be enabled on the network interface for which the port forwarding rule is created.

These are the prerequisites for correct port-forwarding. Without the IP Helper service and without IPv6 support enabled, the port redirection won’t work.
You can find out what process is listening to this port use its PID (in our example, the PID is 636):
tasklist | findstr 636
Let’s try to connect to this computer from a remote system using any RDP client. Port 3340 should be specified as the RDP port.It is specified after the colon following the RDP server address, for example, 10.10.1.110:3340:

The connection should be established successfully.
netsh advfirewall firewall add rule name=”forwarded_RDPport_3340” protocol=TCP dir=in localip=10.1.1.110  localport=3340 action=allow
When creating an incoming firewall rule for port 3340 via Windows Firewall graphical interface, no program needs to be associated with it. This port is only listened by the network driver.
You can create any number of Windows port forwarding rules. All netsh interface portproxy rules are persistent and are stored in the system after a Windows restart.
Display the list of forwarding rules in the system:
netsh interface portproxy show all
In our case there is only one forwarding rule from port 3340 to 3389:
Listen on ipv4:             Connect to ipv4:
Address         Port        Address         Port
--------------- ----------  --------------- ----------
10.1.1.110     3340        10.1.1.110     3389

netsh interface portproxy dump#========================
# Port Proxy configuration
#========================
pushd interface portproxy
reset
add v4tov4 listenport=3340 connectaddress=10.1.1.110 connectport=3389
popd
# End of Port Proxy configuration

To remove a specific port forwarding rule:
netsh interface portproxy delete v4tov4 listenport=3340 listenaddress=10.1.1.110
To clear all current port forwarding rules:
netsh interface portproxy reset
If you want to forward an incoming TCP connection to another computer, the command can look like this:
netsh interface portproxy add v4tov4 listenport=3389 listenaddress=0.0.0.0 connectport=3389 connectaddress=192.168.100.101
This rule will redirect all incoming RDP requests (to port 3389) from this computer to a remote computer with an IP address 192.168.1.101.
Another portproxy feature is an opportunity to make it look like any remote network service is operating locally.
For example, forward the connection from the local port 5555 to the remote address 157.166.226.25 (CNN website):
netsh interface portproxy add v4tov4 listenport=5555 connectport=80 connectaddress= 157.166.226.25 protocol=tcp
Now if you go to http://localhost:5555/ in your browser, CNN Start page will open. So despite the browser addresses the local computer, it opens a remote page.

Port forwarding can also be used to forward a port from an external address of a network card to a virtual machine port running on the same computer.
Also, there were cases when in Windows Server 2012 R2 the port forwarding rules worked only until the system was rebooted, and after restart they were reset. In this case, you need to check whether there is a periodic disconnection on the network interface, and whether the IP address changes when the OS boots (it is better to use a static IP). As a workaround, I had to add a script to the Windows scheduler with the netsh interface portproxy rules that run on the system startup.
In Windows Server 2003 / XP, you must additionally set the IPEnableRouter parameter to 1 in the registry key HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters.
Port Forwarding in Windows的更多相关文章
- How To Set Up Port Forwarding in Linux
		
Port forwarding usually used when we want our computer act like a router. Our computer receive the p ...
 - How to do SSH Tunneling (Port Forwarding)
		
How to do SSH Tunneling (Port Forwarding) In this post we will see how ssh works?, what is SSH tunne ...
 - NAT&Port Forwarding&Port Triggering
		
NAT Nat,网络地址转换协议.主要功能是实现局域网内的本地主机与外网通信. 在连接外网时,内部Ip地址需要转换为网关(一般为路由器Ip地址)(端口号也需要相应的转换) 如: ...
 - 路由器port触发与转发---Port Forwarding & Port Triggering
		
What is Port Triggering? If you have not read my explanation of port forwarding do so now. You can f ...
 - OpenSSH高级功能之端口转发(Port Forwarding)
		
在RedHat提供的系统管理员指南中提到OpenSSH不止是一个安全shell,它还具有X11转发(X11 Forwarding)和端口转发(Port Forwarding)的功能.X11功能一般用于 ...
 - NAT&Port Forwarding&Port Triggering
		
NAT Nat,网络地址转换协议.主要功能是实现局域网内的本地主机与外网通信. 在连接外网时,内部Ip地址须要转换为网关(一般为路由器Ip地址)(port号也须要对应的转换) ...
 - 端口转发 Port Forwarding (一)
		
0x00First 最近发现一些好用的端口转发工具和技巧,计划认真梳理一下 SSH.NC.LCX.EW.FRP 0x01 SSH隧道端口转发 目前利用SSH隧道(SSH tunneling)进行端口转 ...
 - SSH Tunnel扫盲(ssh port forwarding端口转发)
		
SSH的的Port Forward,中文可以称为端口转发,是SSH的一项非常重要的功能.它可以建立一条安全的SSH通道,并把任意的TCP连接放到这条通道中.下面仔细就仔细讨论SSH的这种非常有用的功能 ...
 - Port forwarding with xinetd  Ask
		
https://stackoverflow.com/questions/21716673/port-forwarding-with-xinetd --------------------------- ...
 
随机推荐
- 【转帖】互联网加密及OpenSSL介绍和简单使用
			
转帖:https://mritd.me/2016/07/02/%E4%BA%92%E8%81%94%E7%BD%91%E5%8A%A0%E5%AF%86%E5%8F%8AOpenSSL%E4%BB%8 ...
 - [转载] Oracle在windows下面的自动备份以及删除今天的脚本..
			
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
 - 智能制造(MES)四大阶段
			
智能制造的发展会经历标准化.自动化.信息化.智能化四个阶段标准化,对于生产流程.业务流程.生产制造多方面的标准化.质量检测标准化.企业管理.供应链等.标准化是组织现代化生产的重要组成部分,对于生产专业 ...
 - 简单FTP服务器搭建
			
1 配置IIS 打开控制面板-卸载程序-点击 打开或关闭windows功能-勾选 internet信息服务-确定 2 配置iis web站点 开始菜单-搜索iis并进入iis管理器(计算机-右键-管理 ...
 - Java之"instanceof"和"isInstance"代码举例
			
源码: /** * @Date:2018-04-20 * @Description:判断Instance * - instanceof方法返回一个boolean类型的值,意在告诉我们对象是不是某个特定 ...
 - ZOJ1363 Chocolate 【生成函数】 【泰勒展开】
			
题目大意: 有c种不同的巧克力,每种无限个,意味着取出每种的几率每次为1/c.现在你需要取n次.然后将统计每种取出来的巧克力的数量.若为偶数则舍去,否则留下一个.问最后留下m个的概率是多少. 题目分析 ...
 - hdu 3949 XOR (线性基)
			
链接: http://acm.hdu.edu.cn/showproblem.php?pid=3949 题意: 给出n个数,从中任意取几个数字异或,求第k小的异或和 思路: 线性基求第k小异或和,因为题 ...
 - poj1068 【模拟】
			
Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: ...
 - Java8的flatMap如何处理有异常的函数
			
Java8的flatMap函数,作用是:如果有值,为其执行mapping函数返回Optional类型返回值,否则返回空Optional. 见到的映射函数往往都只有一句话,连大括号都不需要加的,如下: ...
 - 从TensorFlow到PyTorch:九大深度学习框架哪款最适合你?
			
开源的深度学习神经网络正步入成熟,而现在有许多框架具备为个性化方案提供先进的机器学习和人工智能的能力.那么如何决定哪个开源框架最适合你呢?本文试图通过对比深度学习各大框架的优缺点,从而为各位读者提供一 ...