大网数据广告活动
远程桌面与会话

Change Remote Desktop listening port on Windows and Windows Server

· 52CE 我爱测

Learn to change the Remote Desktop listening port on Windows and Windows Server for enhanced security or configuration.

Remote Desktop allows remote connections to computers running Windows or Windows Server over the Remote Desktop Protocol (RDP), listening on port 3389 by default. For security or configuration purposes, you might want to change this listening port. This article provides step-by-step instructions to modify the listening port using either PowerShell or the Registry Editor.

Prerequisites

Before you begin, make sure you have the following items:

  • Administrator access, or equivalent, to the computer you want to connect to.

  • A computer with Remote Desktop enabled. For more information, see Enable Remote Desktop.

  • A client to test the changes from, such as Remote Desktop Connect (mstsc.exe) or Windows App.

Configure the Remote Desktop listening port

The listening port for Remote Desktop is specified in the registry. To change the registry value, here's how to change it using PowerShell or the Registry Editor. Select the relevant tab for the method you prefer.

PowerShell

To change the listening port using PowerShell, follow these steps:

  1. Open PowerShell as an administrator.

  2. Check the current port by running the following PowerShell command:

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

    The output is similar to the following 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
    
  3. Change the port by running the following PowerShell command. Be sure to replace <Port Number> with the new port number.

    $portValue = '<Port Number>'
    
    Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name 'PortNumber' -Value $portValue
    

Registry Editor

To change the listening port using the Registry Editor, follow these steps:

  1. Select the Start button, type Registry Editor, open Registry Editor from the best match list.

  2. Using the navigation pane, expand the key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp**`

  3. In the main pane, select PortNumber

  4. From the menu bar, select Edit > Modify, then select Decimal.

  5. Type the new port number, and then select OK.

  6. Close the Registry Editor, and restart your computer.


Add the new port to the Windows Firewall

If you use the Windows Firewall, you need to add a new inbound rule to allow traffic on the new port. For more information about the different methods you can use to configure the Windows Firewall, see Windows Firewall tools.

Important: If you use any other firewall make sure you or your administrator permit connections to the new port number.

To create new Windows Firewall rules to allow the new port by running the following PowerShell command as an administrator. Be sure to replace <Port Number> with the new port number.

$portValue = '<Port Number>'

New-NetFirewallRule -DisplayName 'RDPPORTLatest-TCP-In' -Profile Public -Direction Inbound -Action Allow -Protocol TCP -LocalPort $portValue
New-NetFirewallRule -DisplayName 'RDPPORTLatest-UDP-In' -Profile Public -Direction Inbound -Action Allow -Protocol UDP -LocalPort $portValue

Test the new Remote Desktop listening port

The next time you connect to this computer by using the Remote Desktop Connection or other client, enter the hostname along with the new port. For example, if you changed the port to use 3390 on computer pc1.contoso.com, the address is pc1.contoso.com:3390.

Related content

Source: Microsoft Learn / Windows Server documentation by Microsoft and contributors (upstream author metadata: robinharwood). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Server documentation
适用范围
Windows Server · Source date 06/30/2025
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。