Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Windows Server

Set up RD Gateway on Windows Server: RDP over HTTPS

Set up RD Gateway on Windows Server: install the role, add a trusted certificate, write the CAP and RAP policies, point clients at it, then close port 3389.

CloudSat teamNovember 18, 20268 min read
Abstract illustration of a single glowing archway in a dark wall, with thin paths of light converging through it toward a row of softly lit screens
On this pageWhat the gateway changes

Remote Desktop Gateway is a Windows Server role service that wraps RDP inside HTTPS. Clients connect to the gateway on port 443, prove who they are, and the gateway checks two policies before it opens a connection to the desktop behind it. The desktop's own port 3389 never has to face the internet. This guide sets up a gateway on Windows Server 2016 to 2025, either in front of a single server or for several servers on a private network, and covers the certificate, the policies, the client side and the logs.

What the gateway changes

Direct RDP Through RD Gateway
Open to the internet TCP and UDP 3389 on every server TCP 443, plus UDP 3391 if you allow it, on the gateway only
First check on a new connection The RDP listener of the target server The gateway's user and resource policies
Servers a user can reach Any with an open port Only those listed in the resource policy
Record of who went where Each server's own logs One gateway log with user, client address, target and duration
Networks that allow only web traffic Often blocked Usually fine, since it is HTTPS

The gateway checks passwords against the same Windows accounts, so long passwords and a lockout policy still matter. What it adds is a single front door with rules and an audit trail.

Before you start

You need:

  • Windows Server 2016, 2019, 2022 or 2025. The steps use RD Gateway Manager, a graphical console, so run them on a server with the Desktop Experience.
  • A DNS name for the gateway, such as gateway.example.com, pointing at the server's public address.
  • A certificate for exactly that name, covered below.
  • Inbound TCP 443, and UDP 3391 for the optional UDP transport, allowed by the firewall in front of the server.

A domain is not required. On a standalone server the policies refer to local groups and people sign in with local accounts.

Install the role

Run PowerShell as administrator:

Install-WindowsFeature -Name RDS-Gateway -IncludeManagementTools

The role brings in Internet Information Services and Network Policy Server, which keeps the gateway's connection policies on the same machine. Check the Restart Needed column of the output and restart if it says yes.

Next, create a local group for the people allowed through, so the policies name a group instead of individuals:

New-LocalGroup -Name 'RDG Users' -Description 'Allowed through RD Gateway'
Add-LocalGroupMember -Group 'RDG Users' -Member 'alice'

Membership in this group only opens the gateway. Each person still needs Remote Desktop rights on the target server, through Administrators or Remote Desktop Users.

Give the gateway a certificate clients trust

Direct RDP lets you click past a self-signed certificate. A gateway does not: Remote Desktop Connection refuses to use one whose identity it cannot verify. The certificate needs:

  • the gateway's DNS name in its subject or subject alternative names,
  • the Server Authentication purpose and its private key, and
  • a chain the clients already trust, which in practice means a public certificate authority.

Free ACME certificates work, but they renew often, so make sure your renewal process also hands each new certificate to the gateway. A self-signed certificate is fine for a test if you import it into Trusted Root Certification Authorities on every client.

To install a PFX file through the console, open RD Gateway Manager (tsgateway.msc), right-click the server name, choose Properties, open the SSL Certificate tab, select Import a certificate into the RD Gateway, then Browse and Import Certificate. The same job in PowerShell suits scripted renewals:

$pfxPassword = Read-Host -AsSecureString 'PFX password'
$cert = Import-PfxCertificate -FilePath C:\certs\gateway.pfx -CertStoreLocation Cert:\LocalMachine\My -Password $pfxPassword

Import-Module RemoteDesktopServices
Set-Item -Path RDS:\GatewayServer\SSLCertificate\Thumbprint -Value $cert.Thumbprint
Restart-Service TSGateway

Write the two policies

Every connection has to pass two checks. The connection authorization policy (RD CAP) decides who may use the gateway at all. The resource authorization policy (RD RAP) decides which computers they may reach through it. The wizard builds both in one pass:

  1. In RD Gateway Manager, expand the server and then Policies. Right-click Connection Authorization Policies and choose Create New Policy > Wizard.
  2. Choose Create an RD CAP and an RD RAP (recommended) and name the CAP.
  3. Keep password authentication and add the RDG Users group. Leave the client computer group empty.
  4. On the device redirection page, decide what sessions may bring along. Turning off drive and clipboard redirection stops files from moving in either direction, at some cost in convenience.
  5. Set an idle timeout and a session timeout if abandoned sessions should close on their own.
  6. Name the RAP, keep the same user group, and point it at an RD Gateway-managed group that lists each target exactly as clients will type it: computer name, full DNS name or IP address.
  7. Allow connections to port 3389 only, unless your servers listen elsewhere, and finish.

Skip the option that allows users to reach any network resource. With it, a stolen password opens whatever the gateway's own network can reach, not only the desktops you meant to publish.

Point clients at the gateway

Test the path from a client first:

Test-NetConnection gateway.example.com -Port 443

In Remote Desktop Connection (mstsc), click Show Options and type the target on the General tab exactly as it appears in the RAP. Then open Advanced, click Settings under Connect from anywhere, choose Use these RD Gateway server settings, enter gateway.example.com, keep Ask for password (NTLM) and tick Use my RD Gateway credentials for the remote computer so you type the password once. With a local account on a standalone gateway, sign in as SERVERNAME\username. Windows App on macOS, iOS and Android has a gateway field in each saved PC's settings.

To hand the same settings to other people, save them in an .rdp file:

full address:s:WIN-APP01
gatewayhostname:s:gateway.example.com
gatewayusagemethod:i:1
gatewayprofileusagemethod:i:1
gatewaycredentialssource:i:0
promptcredentialonce:i:1

gatewayusagemethod:i:1 means always use the gateway, and gatewaycredentialssource:i:0 asks for a password.

Close the direct path

Once a connection works through the gateway, remove 3389 from the firewall in front of every server behind it. When the gateway and the desktop are the same machine, the gateway reaches the desktop inside the server, so the public 3389 rule can go entirely. On a CloudSat Windows VPS, that means a cloud firewall with TCP 443 (and UDP 3391 if you use it) in place of the Windows preset's 3389 rule (Create and apply cloud firewalls).

Servers on a private network behind the gateway should accept RDP only from the gateway's address, here 198.51.100.5:

Set-NetFirewallRule -Name 'RemoteDesktop-UserMode-In-TCP', 'RemoteDesktop-UserMode-In-UDP' -RemoteAddress 198.51.100.5

Watch and maintain the gateway

RD Gateway writes to Applications and Services Logs > Microsoft > Windows > TerminalServices-Gateway > Operational. Event 200 means a user passed the connection policy and 201 that one was refused; 302 records a connection to a resource, and 303 its end, with the bytes transferred and the session length:

Get-WinEvent -LogName 'Microsoft-Windows-TerminalServices-Gateway/Operational' -MaxEvents 25 |
  Select-Object TimeCreated, Id, Message | Format-List

Because the gateway checks passwords with Windows accounts, failed gateway sign-ins also appear as event 4625 in the Security log and count toward the lockout policy; securing RDP against brute-force attacks shows how to read them.

Patch it like any internet-facing service. In January 2020 Microsoft fixed two remote code execution flaws in the gateway's UDP transport that required no sign-in (CVE-2020-0609 and CVE-2020-0610). If you do not need UDP, clear Enable UDP transport on the Transport Settings tab of the gateway's properties and close 3391. For a second factor at the gateway, Microsoft's NPS extension connects it to Microsoft Entra multifactor authentication, which needs your users to exist in Microsoft Entra ID.

Licensing

Microsoft's documentation says each user or device that connects to a Remote Desktop Session Host needs an RDS client access license once the 120-day grace period ends. It is less explicit about a gateway that only fronts the two administrative sessions every Windows Server allows. Check the Product Terms that apply to your license, or ask whoever sold it, before you assume you need none.

FAQ

Does RD Gateway need Active Directory?

No. On a standalone server the policies use local groups and people sign in with local accounts. A domain adds central accounts and groups, which start to matter once several servers sit behind one gateway.

Can the gateway and the desktop be the same server?

Yes. List the server's own name in the RAP and connect to that name through the gateway. For a single machine, it is the simplest way to take 3389 off the internet without a VPN.

Do I still need a VPN?

Not for Remote Desktop. A VPN still earns its place when people also need file shares, databases or other services on the private network, which the gateway does not carry.

Why does the client refuse the gateway's certificate?

The name the client connects to must match the certificate, and the certificate's chain must be trusted on the client. Connecting to the gateway by IP address, or with a self-signed certificate the client has not imported, fails even when direct RDP to the same server works.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.