Changing the RDP Port and Securing Windows Server
The moment you expose your Windows server to the internet, automated scanners from all over the world start probing Remote Desktop (RDP) port 3389. A few hours is all it takes to see hundreds of failed login attempts in your event log.
In this guide, we explain how to change the RDP port on Windows Server step by step, how to test it without locking yourself out of the server and the security settings you must apply in addition to changing the port.
The RDP port is changed with the PortNumber value of the RDP-Tcp key in the registry. Then an allow rule for the new port is added to Windows Firewall and the Remote Desktop service is restarted. Changing the port greatly reduces automated scans and brute-force attempts, but it isn't a security measure on its own. It should be used together with strong passwords, NLA, an account lockout policy, IP restrictions and updates.
- 01 Why Change the RDP Port?
- 02 Before You Start: Don't Lock Yourself Out
- 03 How to Choose a New Port
- 04 Changing the RDP Port with PowerShell
- 05 Changing It with Registry Editor
- 06 Connecting on the New Port and Closing the Old Rule
- 07 Changing the Port Isn't Enough: RDP Security Measures
- 08 Monitoring Failed Login Attempts
- 09 Frequently Asked Questions
- 10 Conclusion
Why Change the RDP Port?
Remote Desktop Protocol (RDP) lets you manage a Windows server remotely through a graphical interface, and by default it uses TCP and UDP port 3389. Because this port is known to everyone, automated bots on the internet constantly scan 3389 and try common username and password combinations on the servers they find.
Changing the port cuts out most of this "noise". Your event logs get cleaner, your server deals with fewer brute-force attempts and it becomes easier to spot a real attack attempt.
A targeted attacker can scan all ports in a few minutes and find which port RDP is running on. So treat changing the port as a first step; the real protection comes from the measures in section 7.
Before You Start: Don't Lock Yourself Out
The most common mistake when changing the RDP port is restarting the service without adding a firewall rule for the new port. When that happens, your connection drops and you can't get back into the server via RDP. Before you start, check the following:
- βAlternative access: I've tested that VNC or web console access in my provider's panel works.
- βExternal firewall: If there's a separate firewall in the provider's panel or on a network device, I've noted that I'll open the new port there too.
- βPrivileges: I'm working in a session with Administrator privileges.
- βBackup: If it's an important server, I've taken a snapshot or backup before the change.
How to Choose a New Port
- Choose a port between 1024 and 49151. Ports below 1024 are reserved for well-known services. 49152 and above is the range Windows uses for temporary (dynamic) connections and may cause conflicts.
- Use a number that's hard to guess. Ports that resemble 3389, such as 3390, 3388 or 33890, are also tried by bots. An unrelated number such as 38921 is better.
- Check that the port is free. Make sure no other application is using the port you choose.
Get-NetTCPConnection -LocalPort 38921 -ErrorAction SilentlyContinue If the command produces no output, the port is free. We use 38921 in the examples in this guide; enter the port you chose.
Changing the RDP Port with PowerShell
The fastest and least error-prone method is PowerShell. Right-click PowerShell in the Start menu, open it with Run as administrator and follow the steps in order.
See the current port
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name PortNumber The PortNumber value in the output is 3389 by default.
Add the firewall rule first
This step must be done before changing the port. Because RDP uses both TCP and UDP, we add two rules:
New-NetFirewallRule -DisplayName "RDP 38921 TCP" -Direction Inbound -Protocol TCP -LocalPort 38921 -Action Allow
New-NetFirewallRule -DisplayName "RDP 38921 UDP" -Direction Inbound -Protocol UDP -LocalPort 38921 -Action Allow Change the port
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name PortNumber -Value 38921 Restart the Remote Desktop service
Restart-Service -Name TermService -Force This command ends your open RDP session. That's normal; you'll reconnect on the new port in the next section. In rare cases where the service doesn't restart, you may need to restart the server.
Changing It with Registry Editor
If you prefer a graphical interface to the command line, you can do the same with Registry Editor. Don't forget to add the firewall rule beforehand here too (Windows Defender Firewall, Advanced Settings, Inbound Rules, New Rule, Port).
- Press Win + R, type
regeditand press Enter. - Go to this key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp - Double-click the PortNumber value in the right pane.
- Select Decimal as the Base. This step is important; a number typed while Hexadecimal is selected means a different port.
- Enter the new port number, click OK and restart the Remote Desktop service or the server.
Connecting on the New Port and Closing the Old Rule
On your own computer, open Remote Desktop Connection (mstsc) and, in the computer field, enter the server address followed by a colon and the new port:
mstsc /v:203.0.113.10:38921 The IP address in the example is for documentation purposes; enter your own server address. If the connection succeeds, you can disable the default 3389 rules that are no longer used:
Disable-NetFirewallRule -Name RemoteDesktop-UserMode-In-TCP, RemoteDesktop-UserMode-In-UDP If you can't connect on the new port, log in to the server via VNC or the web console in your provider's panel. Check that the firewall rule was added, that the registry value was entered correctly in decimal and whether there's a separate firewall on the provider's side. If necessary, you can set the PortNumber value back to 3389 and restart the service.
Changing the Port Isn't Enough: RDP Security Measures
Keep Network Level Authentication (NLA) enabled
NLA requires authentication before the user login screen loads. That way, server resources aren't spent on unauthenticated connections and exploiting some RDP vulnerabilities becomes harder. It's enabled by default on current Windows Server versions; to check and enable it:
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1 Strong passwords and an account lockout policy
Use unpredictable passwords of at least 14 characters. In Local Security Policy (secpol.msc, Account Policies, Account Lockout Policy), make the account lock temporarily after a certain number of failed attempts. This makes brute-force attacks practically useless.
A separate admin account instead of Administrator
Most attacks target the "Administrator" username. Create a new administrator account with a different name for yourself, test that you can connect with it, then disable or rename the built-in Administrator account.
Only allow specific IP addresses
If your office or home has a static IP address, opening RDP only to those addresses is one of the most effective measures. You can add a remote address restriction to the rule you added in section 4:
Set-NetFirewallRule -DisplayName "RDP 38921 TCP" -RemoteAddress 198.51.100.25
Set-NetFirewallRule -DisplayName "RDP 38921 UDP" -RemoteAddress 198.51.100.25 If you don't have a static IP address, a safer approach is to not expose RDP to the internet at all and connect to the server through a VPN first. For that, see our WireGuard setup guide.
Don't neglect Windows updates
In the past, serious RDP vulnerabilities such as BlueKeep (CVE-2019-0708) allowed servers to be taken over without authentication. Vulnerabilities like these are closed by updates. Run Windows Update regularly and don't postpone security updates.
Limit the users with RDP access
Only add accounts that really need it to the "Remote Desktop Users" group. Disable unused accounts or accounts belonging to former employees.
Monitoring Failed Login Attempts
Windows records failed login attempts in the Security log with event ID 4625, and successful logins with ID 4624. To see the latest failed attempts:
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} -MaxEvents 20 When you compare this list before and after changing the port, you'll clearly see the difference. If you still see heavy attempts after changing the port, your server is being scanned in a targeted way; seriously consider IP restrictions or moving to a VPN.
Frequently Asked Questions
Does changing the RDP port slow down the server?
No. The port number doesn't affect performance. On the contrary, because bots make fewer constant login attempts, the server carries less unnecessary load.
How do I connect from my phone or Mac after changing the port?
In Microsoft's Remote Desktop apps (Windows App), just enter server-address:port in the PC name field.
Are the steps the same on Windows Server 2016, 2019, 2022 and 2025?
Yes. The registry key, firewall commands and service name are the same on all of these versions.
Is adding only a TCP rule enough?
A connection can be made over TCP alone, but RDP also uses UDP for a smoother experience. That's why we recommend adding both rules.
Does changing the port protect against ransomware?
Not on its own. A significant share of ransomware attacks start through internet-facing RDP services with weak passwords. Strong passwords, account lockout, IP restrictions, updates and regular backups together provide the real protection.
Conclusion
Changing the RDP port on Windows Server takes a few minutes and keeps most automated attacks away from your server. The right order matters: first confirm alternative access, then add the firewall rule, and only then change the port and restart the service. When you complement the port change with NLA, strong passwords, account lockout, IP restrictions and regular updates, your Windows server becomes much more secure.
If you haven't chosen an operating system yet, take a look at our guide Windows VDS or Linux VDS.
You can use Windows Server on Netiyo VDS servers and securely configure your server, running in our data center in Turkey, with the steps in this guide. For higher performance, you can also explore our dedicated server options.
Explore VDS Server Plans