Connect to Remote Desktop through Cloudflare Tunnel
The Remote Desktop Protocol (RDP) provides a graphical interface for users to connect to a computer remotely. RDP is most commonly used to facilitate simple remote access to machines or workstations which users cannot physically access. However, this also makes RDP connections the frequent subject of attacks, since a misconfiguration can inadvertently allow unauthorized access to the machine.
With Cloudflare Zero Trust, you can enjoy the convenience of making your RDP server available over the Internet without the risk of opening any inbound ports on your local server.
Cloudflare Zero Trust offers two solutions to provide secure access to RDP servers:
- Private subnet routing with Cloudflare WARP to Tunnel
- Public hostname routing with
cloudflared access
Set up an RDP server in GCP
This example walks through how to set up an RDP server on a Google Cloud Platform (GCP) virtual machine (VM), but you can use any machine that supports RDP connections.
- In your Google Cloud Console, create a new project.
- Go to Compute Engine > VM instances.
- Select Create instance.
- Name your VM instance, for example
windows-rdp-server
. - Configure your VM instance:
- Scroll down to Boot Disk and select Change.
- For Operating system, select Windows Server.
- Choose a Version with Desktop Experience, for example Windows Server 2016 Datacenter.
- Once your VM is running, open the dropdown next to RDP and select View gcloud command to reset password.
- Select Run in Cloud Shell.
- Run the command in the Cloud Shell terminal. You will be asked to confirm the password reset.
- Copy the auto-generated password and username to a safe place.
Install Microsoft Remote Desktop
You can use any RDP client to access and configure the RDP server.
To access the server through Microsoft Remote Desktop:
- Download and install Microsoft Remote Desktop.
- Once downloaded, open Microsoft Remote Desktop and select Add a PC.
- For PC name, enter the public IP address of your RDP server. In GCP, this is the External IP of the VM instance.
- For User account, select Add User Account and enter your auto-generated password and username.
- Select Add. The PC will display in Microsoft Remote Desktop.
- To test basic connectivity, double-click the newly added PC.
- When asked if you want to continue, select Continue.
You can now remotely access and configure your RDP server.
Connect to RDP server with WARP to Tunnel
You can use Cloudflare Tunnel to create a secure, outbound-only connection from your server to Cloudflare’s edge. This requires running thecloudflared
daemon on the server. Users reach the service by installing the Cloudflare WARP client on their device and enrolling in your Zero Trust organization. Remote devices will be able to connect as if they were on your private network. By default, all devices enrolled in your organization can access the service unless you build policies to allow or block specific users. 1. Connect the server to Cloudflare
Create a Cloudflare Tunnel for your server by following our dashboard setup guide. You can skip the connect an application step and go straight to connecting a network.
In the Private Networks tab for the tunnel, enter the private IP address of your server (or a range that includes the server IP). In GCP, the server IP is the Internal IP of the VM instance.
(Optional) Set up Zero Trust policies to fine-tune access to your server.
2. Set up the client
In order for devices to connect to your Zero Trust organization, you will need to:
- Deploy the WARP client on your devices in Gateway with WARP mode. The Cloudflare certificate is only required if you want to display a custom block page or perform HTTP filtering.
- Create device enrollment rules to determine which devices can enroll to your Zero Trust organization.
3. Connect as a user
Once the WARP client is configured, you can use your RDP client to connect to the server’s private IP address (instead of the public IP address used initially).
To connect in Microsoft Remote Desktop:
- Open Microsoft Remote Desktop and select Add a PC.
- For PC name, enter the private IP address of your RDP server. In GCP, this is the Internal IP of the VM instance.
- For User account, enter your RDP server username and password.
- To test Zero Trust connectivity, double-click the newly added PC.
- When asked if you want to continue, select Continue.
You now have secure, remote access to the RDP server.
Connect to RDP server with cloudflared access
Cloudflare Tunnel can also route applications through a public hostname, which allows users to connect to the application without the WARP client. This method requires having cloudflared
installed on both the server machine and on the client machine, as well as an active zone on Cloudflare. The SSH traffic is proxied over this connection, and the user logs in to the server with their Cloudflare Access credentials.
The public hostname method can be implemented in conjunction with routing over WARP so that there are multiple ways to connect to the server. You can reuse the same tunnel for both the private network and public hostname routes.
1. Connect the server to Cloudflare
Create a Cloudflare Tunnel by following our dashboard setup guide.
In the Public Hostnames tab, choose a domain from the drop-down menu and specify any subdomain (for example,
rdp.example.com
).For Service, select RDP and enter the RDP listening port of your server (for example,
localhost:3389
). It will likely be port80
,443
, or3389
.Select Save hostname.
(Recommended) Add a self-hosted application to Cloudflare Access in order to manage access to your server.
2. Connect as a user
Install
cloudflared
on the client machine.Run this command to listen on the RDP port:
$ cloudflared access rdp --hostname rdp.example.com --url rdp://localhost:3389This process will need to be configured to stay alive and autostart. If the process is killed, users will not be able to connect.
While
cloudflared access
is running, connect from an RDP client such as Microsoft Remote Desktop:- Open Microsoft Remote Desktop and select Add a PC.
- For PC name, enter
localhost:3389
. - For User account, enter your RDP server username and password.
- Double-click the newly added PC.
- When asked if you want to continue, select Continue.
When the client launches, a browser window will open and prompt the user to authenticate themselves.