更改计算机上的远程桌面的侦听端口Change the listening port for Remote Desktop on your computer

适用于:Windows 10、Windows 8.1、Windows 8、Windows Server 2019、Windows Server 2016、Windows Server 2012 R2、Windows Server 2008 R2Applies to: Windows 10, Windows 8.1, Windows 8, Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2008 R2

通过远程桌面客户端连接到计算机(Windows 客户端或 Windows Server)时,计算机上的远程桌面功能会通过定义的侦听端口(默认情况下为 3389)“侦听”连接请求。When you connect to a computer (either a Windows client or Windows Server) through the Remote Desktop client, the Remote Desktop feature on your computer "hears" the connection request through a defined listening port (3389 by default). 可以通过修改注册表来更改 Windows 计算机上的侦听端口。You can change that listening port on Windows computers by modifying the registry.

  1. 启动注册表编辑器。Start the registry editor. (在“搜索”框中键入 regedit。)(Type regedit in the Search box.)
  2. 导航到以下注册表子项:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-TcpNavigate to the following registry subkey: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
  3. 查找端口号Find PortNumber
  4. 单击“编辑”>“修改” ,然后单击“十进制” 。Click Edit > Modify, and then click Decimal.
  5. 键入新端口号,然后单击“确定” 。Type the new port number, and then click OK.
  6. 关闭注册表编辑器,然后重新启动计算机。Close the registry editor, and restart your computer.

下次使用远程桌面连接连接到此计算机时,必须键入新端口。The next time you connect to this computer by using the Remote Desktop connection, you must type the new port. 如果正在使用防火墙,请确保将防火墙配置为允许连接到新端口号。If you're using a firewall, make sure to configure your firewall to permit connections to the new port number.

可运行以下 PowerShell 命令来查看当前端口:You can check the current port by running the following PowerShell command:

Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber"

例如:For example:

PortNumber   : 3389
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations
PSChildName  : RDP-Tcp
PSDrive      : HKLM
PSProvider   : Microsoft.PowerShell.Core\Registry

还可运行以下 PowerShell 命令来更改 RDP 端口。You can also change the RDP port by running the following PowerShell command. 在此命令中,我们会将新的 RDP 端口指定为 3390。In this command, we'll specify the new RDP port as 3390.

若要向注册表添加新的 RDP 端口:To add a new RDP Port to the registry:

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber" -Value 3390
New-NetFirewallRule -DisplayName 'RDPPORTLatest' -Profile 'Public' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 3390