Remote Desktop (RDP) 3389 Port Change and Access Security

Remote Desktop Protocol (RDP) is a protocol developed by Microsoft and built on a client-server architecture. It allows a user to sign in to a remote system and work through a graphical interface. On the server side, the Remote Desktop Services (TermService) service accepts the connections and listens on TCP port 3389 by default. Newer versions also use the UDP transport on the same port.

3389 is one of the most frequently scanned ports on the internet. For this reason, changing the port that RDP listens on is a common method of reducing the visibility of a system in automated scans. In this article, I explain what a port change provides and what it does not, how I make the change through the registry and PowerShell, the firewall and verification steps, the rollback procedure, and the layers that actually protect RDP access. Enabling Remote Desktop and installing the RDS roles are outside the scope of this article.

The registry location and the steps to change the port are the same on Windows Server 2016, 2019, 2022 and 2025. The default state of the TLS protocols and the impact of vulnerabilities such as BlueKeep, however, depend on the Windows version.

1- Risks of the Default RDP Port

Tools such as Shodan, Nmap and Masscan detect port 3389 within minutes. If this port is reachable on a server that is exposed to the internet, the system enters automated attack lists without any targeting. The table below summarises the main risks that an open RDP port brings.

Risk Description
Brute-force and password spray Common user names and weak passwords are tried automatically. Without an Account Lockout Policy, the number of attempts is unlimited.
BlueKeep (CVE-2019-0708) A vulnerability that allows remote code execution before authentication. It affects Windows 7, Windows Server 2008 R2 and earlier, and was fixed by the May 2019 updates.
Man-in-the-Middle (MITM) RDP uses a self-signed certificate by default. If the user accepts the certificate warning out of habit, an attacker who intercepts the connection is not noticed.

2- What a Port Change Provides and What It Does Not

A port change only makes it harder for bots that scan only 3389 to find the system, and it clearly reduces the noise in the logs. An attacker who scans the whole port range, however, finds the new port quickly and sees that RDP responds. In other words, this change reduces visibility, but it does not change the attack surface.

For the same reason, a port change does not protect against a vulnerability either. Protection against a vulnerability such as BlueKeep comes from updates and NLA. Protection against password attempts comes from an Account Lockout Policy, MFA and restricting access at the network level. I explain these layers in sections 8 and 9.

3- Pre-Change Checklist

Before I start the change, I verify the following items.

Check Expected State
Permissions Local Administrator or equivalent permissions on the server
Remote Desktop Enabled on the server, and the connection over 3389 works without problems
Alternative access Access through the console, iLO/iDRAC, Hyper-V or VMware Console is ready
New port In the 1024-49151 range and not used by another application on the server
Network devices A rule for the new port is planned on the firewall, NAT and security devices in the path
RD Gateway If it is used, the Allowed ports setting in the RD RAP is planned to allow the new port

When I choose the port, I avoid the well-known ports from 0 to 1023 and the dynamic range from 49152 to 65535. The dynamic range contains the ephemeral ports that Windows uses for outbound connections, and a port chosen from this range can cause a conflict later. I use 5011 in this example.

I read the current port value with the following command in a PowerShell session opened with administrator privileges.


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

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

If I see PortNumber : 3389 in the output, the server listens on the default port. I then check that the new port is free. If the command returns no output, 5011 is not in use on the TCP side.


Get-NetTCPConnection -LocalPort 5011 -ErrorAction SilentlyContinue
Get-NetUDPEndpoint -LocalPort 5011 -ErrorAction SilentlyContinue

4- Changing the RDP Port Through the Registry

The port that RDP listens on is stored in the PortNumber (REG_DWORD) value under the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp key. The same value applies to both the TCP and the UDP listener. I first make the change step by step in Registry Editor, and at the end of the section I give the PowerShell equivalent of the same operation.

If you perform this operation over an RDP session, create the firewall rule in section 5 before you restart the service. Otherwise, you lose RDP access to the server.

Step 1 - Opening Registry Editor

I type regedt32 in the Run dialog. Since Windows XP and Windows Server 2003, regedt32 and regedit open the same Registry Editor, and there is no feature difference between them.

RDP port 3389

Step 2 - Opening the Find Window

When Registry Editor opens, I click Edit in the menu, and then Find....

RDP port 3389

Step 3 - Searching for the RDP-Tcp Key

In the Find window, I type RDP-Tcp and click Find Next. The search can first reach a copy under another control set, such as ControlSet001. The correct location is the key under CurrentControlSet, so if I reach a different location, I continue the search with F3. Pasting the key path directly into the address bar gives the same result.

RDP port 3389

Step 4 - Locating the RDP-Tcp Key

Registry Editor finds the RDP-Tcp key and selects it. In the right pane, I see the PortNumber entry that holds the port value.

RDP port 3389

Step 5 - Changing the PortNumber Value

I double-click the PortNumber entry. In the window that opens, the value is shown in Hexadecimal by default, and 3389 appears here as d3d. I first change the Base option to Decimal, then replace the value 3389 with 5011 and click OK.

RDP port 3389

RDP port 3389

Step 6 - Checking the Change

I see the new value in the Data column of the PortNumber entry.

RDP port 3389

Checkpoint
The Data column must show 0x00001393 (5011). At this stage, the value is only written to the registry, and RDP still listens on 3389 until the service is restarted.

The Same Operation with PowerShell

Using PowerShell instead of Registry Editor allows me to make the same change on multiple servers in a repeatable way. I run the following command in a PowerShell session opened with administrator privileges. Replace the value 5011 with the port that you chose.


$portValue = 5011
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name 'PortNumber' -Value $portValue

5- Firewall Rule and Restarting the Service

The built-in Remote Desktop - User Mode (TCP-In) and (UDP-In) rules in Windows Defender Firewall are bound to 3389 and do not cover the new port. For the server to accept the incoming connection, I add 2 Inbound rules for the new port, 1 for TCP and 1 for UDP. An outbound rule is not needed because the server only accepts the connection.


$portValue = 5011
New-NetFirewallRule -DisplayName 'RDP-5011-TCP-In' -Profile Domain,Private -Direction Inbound -Action Allow -Protocol TCP -LocalPort $portValue
New-NetFirewallRule -DisplayName 'RDP-5011-UDP-In' -Profile Domain,Private -Direction Inbound -Action Allow -Protocol UDP -LocalPort $portValue

The example command on Microsoft Learn uses only the Public profile. On a domain-joined server, the network connection is usually in the Domain profile, and a rule written to the wrong profile does not allow the connection. I check which profile the server is in with Get-NetConnectionProfile and set the -Profile value accordingly. It is also possible to add the permitted IP range to the rule with the -RemoteAddress parameter to restrict access to the management network only.

If there is another firewall or a NAT device between the server and the client, the new port must be opened there as well. After I confirm that the port is ready, I restart the service. The PortNumber value is read when the service starts, so the new port takes effect only after this step.


Restart-Service -Name TermService -Force
Restarting the service disconnects all open RDP sessions on the server. Perform the operation during a maintenance window or plan to restart the server.

6- Verifying the New Port and Connecting from the Client

On the server side, I check in PowerShell whether the new port is being listened on. If I see Listen in the State column for the first command and a UDP endpoint for 5011 for the second command, the listener is running on the new port. The same check can also be done in Command Prompt with netstat -an | findstr :5011, where you look for the LISTENING line.


Get-NetTCPConnection -LocalPort 5011 -State Listen
Get-NetUDPEndpoint -LocalPort 5011

The fact that the server listens on the port does not mean that the client can reach it. I perform the real verification, which also covers the firewalls in the path, from the client with Test-NetConnection. Replace {Server Name} with the name or IP address of your own server. The output must show TcpTestSucceeded : True.


Test-NetConnection -ComputerName {Server Name} -Port 5011

When I connect, I type the server name or IP address, a colon and the new port number in the address field of Remote Desktop Connection (mstsc). For example, 10.26.5.100:5011. If no port is specified, the client tries to connect to 3389. There is no GPO setting that directs the port on the client side, so the port is specified in the address field or in the .rdp file.

RDP port 3389

If Remote Desktop Gateway is used in the environment, the Allowed ports setting in the RD RAP (Resource Authorization Policy) allows only 3389 by default. If this setting is not updated to include the new port, connections made through the gateway are rejected.

7- Rollback and Troubleshooting

To roll back the change, I set the PortNumber value back to 3389, restart the service and remove the firewall rules that I created for the new port. If I also perform this operation over RDP, I first check that the built-in rules for 3389 are enabled.


Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name 'PortNumber' -Value 3389
Restart-Service -Name TermService -Force
Remove-NetFirewallRule -DisplayName 'RDP-5011-TCP-In','RDP-5011-UDP-In'

If the connection to the new port fails, I perform the checks from the server outwards.

Symptom Check
The port does not appear in the Listen state Check that the TermService service is running and that the PortNumber value was entered correctly in Decimal.
The service starts but no listener is created In Event Viewer, check the Microsoft-Windows-TerminalServices-RemoteConnectionManager logs and whether the port is used by another application (port conflict).
Listen is present on the server, TcpTestSucceeded : False from the client Check the profile of the Windows Defender Firewall rule and the rules on the network devices in the path.
The port is reachable but sign-in fails Check the user rights and the Remote Desktop restrictions that come from a Group Policy Object (GPO) (section 8).

8- TLS, NLA and User Rights

TLS and the Server Certificate

The encryption of the RDP connection depends on the security layer that is set by the Require use of specific security layer for remote (RDP) connections GPO setting. The default value is Negotiate, and TLS is used if the client supports it. Fixing this setting to SSL ensures that the connection is always established with TLS. The name SSL in the GPO is historical, and the protocol in use is TLS.

The Schannel configuration of Windows determines which TLS version is used. Whether TLS 1.0 and 1.1 are enabled by default depends on the Windows version. In older versions, these protocols are enabled by default, and they must be disabled through Schannel so that the connection is established only with TLS 1.2 or later. This change also affects applications other than RDP, so compatibility must be checked first.

The main source of the MITM risk is usually not the protocol version but the self-signed certificate of the server. When users become used to accepting the certificate warning that they see on every connection, they accept the warning of a fake server that intercepts the connection in the same way. In a corporate environment, distributing a certificate issued by the internal CA for RDP through GPO removes this warning.

Network Level Authentication (NLA)

When NLA is enabled, the user must authenticate with CredSSP before a session is created on the server. As a result, a connection that fails authentication does not consume session resources on the server, and the attack surface of vulnerabilities that are exploited before authentication becomes smaller. NLA also makes the exploitation of BlueKeep require credentials.

NLA does not prevent password attempts. It only ensures that the attempts are made before a session is opened. Protection against brute-force attacks comes from an Account Lockout Policy and MFA. NLA can be enforced with the Require user authentication for remote connections by using Network Level Authentication GPO setting.

User Rights

For a user to sign in with RDP, the following conditions must all be met.

Condition Description
Allow log on through Remote Desktop Services It must be defined for the user or the user's group under Local Policies, User Rights Assignment in secpol.msc. By default, Administrators and Remote Desktop Users are defined on member servers, and only Administrators on domain controllers.
Deny log on through Remote Desktop Services The user or the user's group must not be in this right. The Deny right overrides the Allow right.
Group membership Users who are not administrators must be in the Remote Desktop Users group on the server.
Account status The account must not be Disabled or Locked, and the password must not be expired. When NLA is enabled, a connection cannot be established with an expired password.

9- Layered RDP Security and the Recommended Architecture

A port change is not one of the layers below. It is a visibility reduction step that is added on top of them. The real goal is that the RDP port is not reachable from the internet at all.

Measure What It Provides
Source IP restriction on the firewall Ensures that the RDP port is reachable only from the management network or from specific IP addresses.
VPN Ensures that RDP is reachable only over an authenticated VPN connection, and the port is not exposed to the internet.
Remote Desktop Gateway Carries RDP traffic inside HTTPS (443), and the internal servers are not exposed to the internet. RD CAP and RD RAP control who can connect to which server.
Jump server and Privileged Access Workstation (PAW) Gathers management connections at a single controlled point and prevents highly privileged accounts from signing in from devices that are used for daily work.
Multi-Factor Authentication (MFA) RDP has no built-in MFA. The Microsoft method is to use the NPS Extension for Microsoft Entra MFA with RD Gateway.
Account Lockout Policy Limits password attempts by locking the account after a set number of failed attempts.
Just-in-time access Opens RDP only when it is needed and for a limited time, instead of keeping it open permanently. On Azure VMs, Microsoft Defender for Cloud provides this. In other environments, the same result is achieved by keeping the firewall rule disabled when it is not needed.

The logs show whether these layers work. Windows does not have built-in video recording of RDP sessions, but connection and session events can be monitored with the Event IDs below. Forwarding these records to a central SIEM or log collection system makes it easier to see the volume of failed attempts and the sessions that come from unexpected sources.

Event ID Log Meaning
4624 Security Successful sign-in. RDP sessions appear as Logon Type 10.
4625 Security Failed sign-in attempt.
1149 TerminalServices-RemoteConnectionManager/Operational A connection that completed network-level authentication.
21, 24, 25 TerminalServices-LocalSessionManager/Operational Session logon, disconnection and reconnection to the session.

If the new port appears in the Listen state, Test-NetConnection succeeds from the client and you can sign in to the server:5011 address with mstsc, the port change is complete. From this point, you can disable the built-in firewall rules for 3389 and apply the same change to other servers with the PowerShell commands. Before you expose RDP access to the internet, however, the layers in section 9 must be ready at least at the level of VPN or RD Gateway, NLA and Account Lockout Policy.

I hope you find it useful...

No comments on this article yet. Be the first to comment!

750 characters available.
Security code
Comments are published once approved.
Your email is only used to let you know when your comment is approved. It is never published.