Changing the port
1. Open regedit by pressing Windows key + r and typing regedit:
2. Navigate to the following navigation within your registry: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
And locate the PortNumber property.
3. Right-click PortNumber and click Modify. The following window will open where we will have to make sure the base is set to Decimal. We can continue by changing the Value data to the desired RDP port.
When you are done, press ok.
We are finished with the registry editor now. If you have already configured your firewall, you can now reboot the system to apply the changes. If you have not configured your firewall yet, please follow the below steps.
Configuring the Firewall
To allow connection to your machine with this new port we will most likely have to change your firewall settings and add this port as an incoming port.
1. Open the firewall settings by pressing Windows key + r and typing firewall.cpl
2. In the firewall window we will navigate to Advanced settings
This will open the Windows Firewall with Advanced Security window.
3. Here we will right-click Inbound Rules and then click New Rule to add a new inbound firewall rule.
4. This opens a wizard we have to follow, first off we will select the type of rule we would like to create. For our case this is Port and click next.
5. We will use the TCP protocol and specify our remote desktop port (in our case we have changed it to 2023), after this click next.
6. Select Allow the connection and click next
7. Select the profiles where this rule applies and click next
8 . Finally, give this rule a descriptive name to make it easier to find later and click finish.
If you have not rebooted after changing the port in regedit now, you can now reboot.
Now try if you are able to connect through remote desktop with your system with your new port.
You can verify if you have set the port of your remote desktop command correctly by running the following command in Powershell:
Get-ItemProperty -name "PortNumber" -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp"
This should give an output like this:
Congratulations! You have now successfully changed the port for your remote desktop.
For safety, you should now disable the old firewall rules for port 3389.