It's highly recommended to change windows remote desktop default port for added security.
You can change the default port with a few easy steps, first, you'll change the port and define this port in a firewall rule.
Method #1
Change RDP TCP port on Windows Server 2016/2019/2022
- Open registry editor app by searching for
regedit
in windows search or useRUN
. - Locate the following from
regedit
app:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
- look for
PortNumber
and right-click on it andModify
- Make sure to select
Decimal
underBase
option - Change the port number to any number you prefer, let's say
1234
and clickOK
- Quit the registry editor
- Open Firewall (Windows Defender Firewall with Advanced Security)
- From the left sidebar click on
Inbound Rules
- From the right sidebar click on
New Rule
- Select
Port
and clickNext
- Select
TCP
and type the port number inSpecific local port
and clickNext
until you reach the step where you asked to enter a rule name, give the rule a name and ClickFinish
. (Repeat from #7 to #11 for UDP) - Restart the server or execute this PowerShell command
Restart-Service -Force -DisplayName "Remote Desktop Services"
- Try to connect to RDP as usual but when you type the IP, don't forget to type the custom port number after the IP in this format
IP:Port
(e.g. 192.168.1.5:1234)
Method #2
PowerShell
You can also change the RDP port by running the following PowerShell commands. In this command, we'll specify the new RDP port as 1234.
To add a new RDP Port to the registry:
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber" -Value 1234
Then Add Firewall Rule to open port 1234 on the Public profile using PowerShell
New-NetFirewallRule -DisplayName 'RDPPORT_TCP' -Profile 'Public' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 1234
Repeat to open UDP port 1234 (recommended)
New-NetFirewallRule -DisplayName 'RDPPORT_UDP' -Profile 'Public' -Direction Inbound -Action Allow -Protocol UDP -LocalPort 1234
Restart Remote Desktop Service from PowerShell
Restart-Service -Force -DisplayName "Remote Desktop Services"
Find this tutorial on Microsoft.com:
https://support.microsoft.com/en-gb/help/306759/how-to-change-the-listening-port-for-remote-desktop
Watch Video Tutorial: https://www.youtube.com/watch?v=k8mswkiok70