Updating the RDP port for an Azure VM

5/5 - (3 votes)

This week, I found myself unable to log into an Azure-hosted VM due to a new managed firewall rule. The new rule was put in at priority 0 and it specifically blocks inbound 3389.

Now, with it blocked, I’m unable to log into the server to update it.  This is quite a chicken-and-egg situation.

Oops.

Fortunately, there’s a workaround. You can update the RDP port on your servers to a non-standard port through the portal itself.

Here we go!

  1. Log into the Azure portal (https://portal.azure.com).
  2. Navigate to your virtual machine.
  3. Under Operations, select Run command.
  4. Select SetRDPPort.  This runs a pre-loaded script in the VM agent.
  5. Set the RDPPORT value and click Run.
  6. Review the output to ensure that it has completed.
  7. Under Settings, select Networking.
  8. Click Add inbound port rule.
  9. Enter any appropriate network scoping restrictions.
  10. Set the Destination port ranges value to the one entered in Step 5 and click Add.
  11. After the rule has been added, update your RDP client with the appropriate destination port as well.

And you’re off to the races!