Guides

Remote Desktop Gateway (RD Gateway): what it is and how to set it up

Remote Desktop Gateway puts RDP behind HTTPS on port 443. When a VPS needs one, how to install it on Windows Server 2022/2025, the certificate, mstsc, errors.

Published ~8 min read
On this page

Short answer: a Remote Desktop Gateway (RD Gateway) is a Windows Server role service that wraps RDP in HTTPS, so clients on the internet reach your Windows machines through TCP port 443 (plus UDP 3391) instead of an open port 3389. You install it with Server Manager or one PowerShell line, give it a certificate for its public name, allow users with an RD CAP and target machines with an RD RAP, and point mstsc at it with /g.

PowerShell (Administrator) · Windows Server 2022, 2025
# on the gateway: list the Remote Desktop role services, then install the gateway
Get-WindowsFeature -Name RDS*
Install-WindowsFeature -Name RDS-Gateway -IncludeManagementTools

# on your PC: connect to SERVER through the gateway
mstsc /v:SERVER /g:rdgw.example.com

-IncludeManagementTools matters: Microsoft’s Install-WindowsFeature reference says the cmdlet, unlike the Server Manager wizard, leaves management tools out unless you ask for them, and without them you have no RD Gateway Manager. Everything below follows Microsoft Learn as read on 13 November 2026; nothing here was run on a live gateway for this article.

What an RD Gateway is

Microsoft describes RD Gateway as the Remote Desktop Services role that gives users on public networks secure, encrypted access to internal desktops and apps without a VPN. The client opens a TLS connection to the gateway, the gateway authenticates the user (it uses the built-in IIS for that), checks two kinds of policy and then forwards the RDP traffic to the internal machine on port 3389. The machines behind it never need a port open to the internet.

  • RD CAP (connection authorization policy): who may connect to the gateway, for example members of a Windows group. CAPs are stored locally by default or on a central server running NPS (Network Policy Server); Microsoft notes that the NPS role is present by default on a machine configured as an RD Gateway.
  • RD RAP (resource authorization policy): which computers those users may reach through it. RAPs are always processed on the gateway itself.
  • A user has to match one CAP and one RAP; matching only one is not enough.
  • The Windows service behind it is TSGateway. Microsoft’s high availability guide notes you may have to restart it by hand after changing the certificate.
PortDirectionWhat it carries
TCP 443Internet to gatewayHTTP over SSL, the main RDP transport; changeable in RD Gateway Manager
UDP 3391Internet to gatewayRDP over UDP; also changeable in RD Gateway Manager
TCP and UDP 3389Gateway to internal serversPlain RDP to the target machines
UDP 1812 and 1813Gateway to NPSRADIUS, needed when the gateway talks to a separate NPS server (central RD CAP store)

Microsoft’s port list adds one detail for UDP 3391: firewalls with directional UDP analysis, such as TMG, need UDP “Send Receive” configured. Port 443 is also the standard HTTPS port for websites, so check what already listens on 443 on that server before you install the gateway; the guide to ports 443 and 80 shows how.

Do you need one for a single VPS or dedicated server?

Usually not. A gateway earns its keep when several Windows machines sit on a private network and many users need to reach them from anywhere with policies, logging and optional multifactor sign-in through NPS. It also brings IIS, NPS and a public HTTPS endpoint that you have to patch and watch. For one rented Windows server and one or two administrators, something simpler closes port 3389 just as well:

OptionEffortFits when
Firewall allowlistSet-NetFirewallRule -DisplayGroup "Remote Desktop" -RemoteAddress 203.0.113.10You connect from a fixed IP address
VPN (WireGuard, OpenVPN)One VPN server and a client per deviceYour IP changes or several services need hiding
SSH tunnelssh -N -L 13389:127.0.0.1:3389 admin@SERVEROpenSSH Server already runs on the Windows machine
RD GatewayRole, certificate, CAP, RAP, two portsSeveral internal machines, many users, policy and audit needs

With the SSH tunnel you then connect with mstsc /v:127.0.0.1:13389; setting up the server side is covered in SSH into a Windows machine. On a VPS or dedicated server, remember the provider’s network firewall too, if there is one: whatever you choose, it has to allow the same ports as Windows Firewall. A sensible gateway layout on rented hardware is one small Windows server with a public address running the gateway, and the other servers reachable from it over a private network, with 3389 closed to the internet on all of them.

How to install and configure RD Gateway

  1. 1Install the role service

    In Server Manager, open Add Roles and Features, select Remote Desktop Services, and on the role services page pick Remote Desktop Gateway; Microsoft’s guide notes that the wizard also offers Web Server (IIS) role services, and the defaults are enough. Or run the Install-WindowsFeature line from the top as Administrator. The feature name matches the role service name in Microsoft’s RemoteDesktop module (RDS-GATEWAY), and an archived Microsoft RDS PowerShell walkthrough installs it with -Name RDS-Gateway; Get-WindowsFeature -Name RDS* shows the exact name on your build before you install. You must be in the Administrators group.

  2. 2Import the certificate

    Open RD Gateway Manager (Server Manager, Tools, Remote Desktop Services, Remote Desktop Gateway Manager), right-click your server in the left pane, choose Properties, then the SSL Certificate tab, Import a certificate into the RD Gateway and Browse and Import Certificate. Select the PFX file and enter its password. Requirements are in the certificate section.

  3. 3Create one RD CAP and one RD RAP

    In RD Gateway Manager, create a connection authorization policy naming the user group allowed in, and a resource authorization policy naming the computers that group may reach. Put the computer names your users will type into the client into the RAP’s computer group, so the name they ask for is one the RAP lists.

  4. 4Open TCP 443 and UDP 3391

    Inbound on the gateway, in Windows Firewall and in any firewall in front of it. Keep 3389 open only between the gateway and the internal servers.

  5. 5Test from outside

    Connect with mstsc /v:SERVER /g:rdgw.example.com from a machine on another network, then check the gateway’s event log (shown under errors).

The certificate requirement

  • The name must match. The certificate’s name has to be the FQDN clients use to reach the gateway, whether that is the DNS name of the public IP or a CNAME pointing to it. A bare IP address in the client will not match a certificate issued for a name.
  • Clients must trust it. Microsoft recommends a publicly issued certificate because the gateway faces the internet. A certificate from your own CA works only if every client already has its trust chain; self-signed ones are for tests and proofs of concept.
  • It has to be a PFX with the private key. If your CA gave you PEM files, convert them with OpenSSL as shown in installing OpenSSL on Windows.
  • Renewals are your job. After importing a new certificate, restart the service if clients still see the old one: Restart-Service TSGateway.

How to point mstsc at the gateway

In the dialog: run mstsc, click Show Options, open the Advanced tab and click Settings under Connect from anywhere. In RD Gateway Server Settings, choose Use these RD Gateway server settings, enter the gateway’s FQDN (Microsoft’s procedure says it must be a fully qualified name), and decide about Bypass RD Gateway server for local addresses: it is ticked by default, and Microsoft says to clear it when you want to test the gateway from inside the same network. Then enter the internal computer name on the General tab as usual. If you cannot choose your own settings, Group Policy is enforcing a gateway configuration.

On the command line: mstsc /v:SERVER /g:rdgw.example.com. Microsoft’s mstsc reference points out that /g is only read together with /v.

In an .rdp file: the gateway is a property like any other. These are the lines that matter; the easiest way to get a complete file is to set the gateway in the dialog and save the connection, which also gives you a file to hand to colleagues.

connection.rdp
full address:s:SERVER
gatewayhostname:s:rdgw.example.com
gatewayusagemethod:i:1
gatewayprofileusagemethod:i:1
promptcredentialonce:i:1

The values follow Microsoft’s reference for the client’s gateway properties: gatewayusagemethod 1 means always use the gateway, 2 means use it only if a direct connection to the server cannot be made (the same as ticking the bypass box). gatewayprofileusagemethod 1 means use these explicit settings rather than the administrator’s default. promptcredentialonce:i:1 reuses the same credentials for the gateway and the remote computer, which is the default. Microsoft’s current list of supported RDP properties does not include the gateway lines, which is one more reason to let mstsc write them for you. Its legacy rdp:// URI table lists gatewayhostname and gatewayusagemethod for the macOS, iOS and Android clients. For the other client options, see connecting to RDP from any device.

Common RD Gateway errors

Start with the gateway’s own log, under Applications and Services Logs, Microsoft, Windows, TerminalServices-Gateway, Operational. Event 200 means the user met an RD CAP, event 300 that they met an RD RAP and were let through:

PowerShell on the gateway
Get-WinEvent -LogName Microsoft-Windows-TerminalServices-Gateway/Operational |
  Where-Object { $_.Id -in 200, 300 } | Select-Object -First 20 TimeCreated, Id, Message
SymptomLikely causeWhat to do
Client warns the gateway name and certificate do not matchClient uses an IP or another name than the certificateType the exact FQDN on the certificate, or issue one for the name you use
Client cannot verify the gateway's identityPrivate CA or self-signed certificateUse a public certificate, or install the chain on every client
Connection to the gateway times outTCP 443 blocked, or another service holds 443Run Test-NetConnection rdgw.example.com -Port 443 from the client; check both firewalls
Gateway rejects the sign-in, no event 200User is in no RD CAPAdd the user's group to a CAP
Event 200 but no event 300The RAP does not list the computer name usedAdd that name to the RAP's computer group, or use the name it lists
Event 300 logged, desktop still failsGateway cannot reach the target on 3389, or RDP is off thereOpen TCP and UDP 3389 from gateway to target; enable RDP on the target
Works, but no UDP transportUDP 3391 blocked on the way inAllow UDP 3391 inbound (Send Receive on firewalls with directional UDP analysis)

The table is a diagnostic aid built from what events 200 and 300 mean and from the port list, not a list of Microsoft error texts. One more point for Windows Server 2025: Microsoft’s list of deprecated features says TLS 1.0 and 1.1 are disabled by default there. The gateway connection runs over TLS, so expect a very old client that only speaks those versions to fail against a 2025 gateway; updating the client is the cleaner fix than turning the old protocols back on.

Windows Server 2025 and licensing

RD Gateway is still part of Windows Server 2025: Microsoft’s PowerShell reference for 2025 lists RDS-GATEWAY among the Remote Desktop role services, and the list of features removed or no longer developed in Windows Server 2025 (as read on 13 November 2026) does not mention it. Microsoft’s install guide is not tied to one version, so the steps above apply to 2022 and 2025 alike.

On licensing, Microsoft Learn says each user or device connecting to a Remote Desktop Services session host needs an RDS client access licence (CAL), with a 120-day grace period before a licence server is required. The CAL version must be equal to or newer than the session host: Windows Server 2022 CALs do not cover a 2025 session host, while 2025 CALs cover 2016 to 2025. The CAL article does not name a separate licence for the gateway itself. If your gateway only fronts servers that two administrators reach without the Session Host role, read what you get by default with RDP sessions before buying CALs.

Microsoft’s own pages, for reference: Deploy the RD Gateway role and Ports used by Remote Desktop Services.

Frequently asked

What is a Remote Desktop Gateway?

It is a Windows Server role service that carries RDP inside HTTPS, so clients on the internet connect to the gateway on TCP 443 (and UDP 3391) and the gateway forwards them to internal Windows machines on port 3389. Users must match a connection authorization policy (RD CAP) for who may connect and a resource authorization policy (RD RAP) for which computers they may reach. The internal machines then need no RDP port open to the internet.

Which ports does RD Gateway use?

Inbound TCP 443 for HTTP over SSL and inbound UDP 3391 for RDP over UDP; both can be changed in RD Gateway Manager. From the gateway to the internal servers it uses TCP and UDP 3389, and UDP 1812 and 1813 only if the RD CAPs live on a central NPS server.

Do I need RD Gateway for a single Windows VPS?

Usually not. For one server and one or two administrators, limiting the Remote Desktop firewall rules to your own IP address, a VPN or an SSH tunnel closes port 3389 with far less to maintain. A gateway pays off when several internal machines and many users need policy-controlled access from anywhere.

How do I connect to an RD Gateway with mstsc?

Run mstsc /v:SERVER /g:gateway.example.com, where SERVER is the internal computer and the /g value is the gateway's FQDN; /g is only read together with /v. In the dialog the same setting is under Show Options, Advanced, Connect from anywhere, Settings. In an .rdp file it is the line gatewayhostname:s:gateway.example.com together with gatewayusagemethod:i:1 (always use the gateway) and gatewayprofileusagemethod:i:1 (use these explicit settings).

Related articles

All guides