On Windows Server, Remote Desktop (RDP) uses port 3389 by default, and this is one of the ports most frequently scanned by bots on the internet. In this guide we explain how to change the RDP port with PowerShell and how to configure the firewall.
An incorrect configuration can cut off your access to the server. Make sure VNC/console access in your client panel works and, if possible, take a snapshot.
Step 1: Choose a new port
Choose a port between 1024 and 65535 that is not used by another service. In this guide we'll use 33890 as an example.
Step 2: Open PowerShell as administrator
Type PowerShell in the Start menu, right-click it and select Run as administrator. Check the current port:
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name "PortNumber"Step 3: Add a firewall rule
Before changing the port, create an inbound rule for the new port:
$port = 33890
New-NetFirewallRule -DisplayName "RDP-TCP-$port" -Direction Inbound -Protocol TCP -LocalPort $port -Action Allow -Profile Any
New-NetFirewallRule -DisplayName "RDP-UDP-$port" -Direction Inbound -Protocol UDP -LocalPort $port -Action Allow -Profile AnyStep 4: Change the RDP port
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name "PortNumber" -Value $portStep 5: Restart the Remote Desktop service
Restart-Service -Name TermService -ForceThis command ends your current RDP session. If the service doesn't restart, reboot the server:
Restart-ComputerStep 6: Connect using the new port
In the Remote Desktop Connection (mstsc) app, enter the IP address and port separated by a colon in the Computer field:
SUNUCU_IP_ADRESI:33890Step 7: Close the old port
Once you are sure the connection via the new port works, you can disable the default RDP rules:
Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Disable-NetFirewallRuleThe group name may differ depending on Windows' language settings (e.g. Uzak Masaüstü on a Turkish system). You can find the rules with the Get-NetFirewallRule | Where-Object DisplayName -like "*Remote Desktop*" command.
Additional security recommendations
- Strong password: Use a complex password of at least 14 characters for the Administrator account.
- Account lockout: Lock the account after a certain number of failed logins via Local Security Policy (secpol.msc).
- NLA: Make sure Network Level Authentication is enabled.
- IP restriction: If possible, open RDP access only to your own IP addresses.
- Updates: Run Windows Update regularly.
Conclusion
Changing the RDP port stops most automated attacks right at the door. To run Windows Server, take a look at our DDoS-protected VDS servers.
Frequently Asked Questions
What is the default RDP port?
The Remote Desktop Protocol uses TCP port 3389 by default.
I can't connect after changing the port. What should I do?
Make sure the firewall rule has been added and the server has been restarted. If access is completely lost, you can connect to the server via VNC/console in your client panel and revert the setting.
