Self-hosting
RustDesk Network Architecture
RustDesk NAT traversal is the attempt, after hbbs has introduced two clients, to punch a direct UDP or TCP path between them so the session does not have to stay on the relay. The protocol registers each client with the ID server, tests how each NAT behaves, tries hole punching, and uses hbbr when that direct path fails. Documentation says hole punching works in the majority of cases. The server coordinates the attempt. It is not the remote desktop session itself.
This description follows the RustDesk docs reviewed on November 30, 2026. It is an independent explanation of the published design, not a packet capture from this site.
Three roles, two paths
Every normal ID-based session has a controller, the computer a person is sitting at, and a host, the computer that person is allowed to open. Both run the RustDesk client. Both register with hbbs. The controller asks hbbs to reach a given ID. hbbs tells the two clients how to try a direct connection. If the punches land, media flows between the endpoints. Server location then says little about where the picture and keyboard traffic traveled. If the punches miss, both clients connect to hbbr and the relay carries the session. Putting hbbs in a region you prefer does not relocate that direct media, and it does not prove GDPR, HIPAA, or ISO compliance.
The public infrastructure is the same shape with operators you do not choose. A fresh client uses those public servers and can show “Ready, For faster connection, please set up your own server.” Self-hosting replaces the public hbbs and hbbr with processes you run. It does not replace hole punching with a different protocol. The server overview compares the open-source processes with Server Pro. Pro adds a console, an API, and accounts. It uses the same rendezvous and relay roles underneath.
How the traversal proceeds
Registration comes first. The client must reach hbbs on UDP 21116 for registration and heartbeat, and on TCP 21116 for TCP hole punching and the connection service. TCP 21115 is the NAT type test. Those three sockets are how the server learns enough to attempt a punch. Without them, there is no later decision between a direct session and a relay. The port guide lists the rest, including the Pro console on TCP 21114 and the web-client sockets on 21118 and 21119.
Hole punching is the NAT traversal step. Each client, already in contact with hbbs, sends traffic that opens a mapping in its local NAT. The ID server shares the information the other side needs to send into that mapping. When both NATs allow it, the clients see each other and the session proceeds peer to peer. Docs describe this as working in the majority of cases. They do not promise it for every carrier-grade NAT, every symmetric NAT, or every network that blocks inbound mappings. Those pairs use the relay.
The relay is hbbr on TCP 21117. Clients infer that port on the ID server’s host if you leave the relay field empty. You can point the relay at a different machine when you split the roles. You can also set the optional environment ALWAYS_USE_RELAY=Y on hbbs, which the Docker documentation shows as the way to tell clients to use the relay. That variable is a policy switch. A further documented mode publishes only TCP 443 and forces sessions through a WebSocket relay, with no direct peer-to-peer path at all. Use that mode when a security policy forbids hole punching. Expect the relay host to carry the bandwidth those sessions used to exchange directly.
| Path | Who carries the media | When it happens |
|---|---|---|
| Peer to peer after hole punching | The two endpoints. | The usual ID-based session. Docs say this is the majority outcome. |
Relay through hbbr | Your relay, or the public relay if you have not self-hosted. | Punching failed, or ALWAYS_USE_RELAY=Y forced it. |
| WebSocket relay on 443 only | The WSS relay path. | The documented mode with no direct P2P and a single public TCP port. |
| Direct IP access | A direct connection to the host, default port 21118 when enabled. | A different mode, off until direct-server is turned on. The FAQ documents an unencrypted path. |
What the protocol is, and what it is not
RustDesk is not RDP or VNC. Clients use RustDesk’s own session protocol, while hbbs and hbbr handle rendezvous and relay—they are not RDP or RFB gateways. The client docs name VP8, VP9, and AV1 for software encoding and H.264 and H.265 for hardware. Those codecs shape the picture; NAT traversal is the separate layer underneath that decides how the two ends reach each other.
Encryption is scoped. Docs describe peer-to-peer end-to-end encryption based on NaCl for the normal ID-based connection model. Self-hosted encrypted use requires the server public key from id_ed25519.pub, which hbbs generates on first start. That key is not the Pro license key. Direct IP access is outside that claim. Do not describe every connection mode as end-to-end encrypted. Do not describe a successful punch as proof that a relayed session took the same route. Read the path in the client or in your relay logs if the distinction matters for a policy.
An ID whitelist is not authentication. The connecting client reports the ID. Traversal can succeed for a client you did not mean to trust if that client has the public key and the host accepts the password or the click. Network architecture does not replace the approval on the host.
Prerequisites
You need both clients online and pointed at the same ID server, with the same public key. You need hbbs reachable on TCP 21115, TCP 21116, and UDP 21116. You need hbbr reachable on TCP 21117 for every pair that might fail the punch, which in practice means every pair unless you have proven they always connect directly. You need working DNS and a clock that is synchronized on the server. You need the host computer to be one you are allowed to control. Traversal is not a consent mechanism.
Pro adds outbound HTTPS for the license check. The check is not part of hole punching. OSS has no license check. A blocked license call can leave Pro unhappy while the rendezvous ports still answer, or the reverse. Diagnose them separately.
Supported environment
The traversal behavior is a property of hbbs, hbbr, and the client, not of a particular Linux distribution. The documented way to run the processes on Linux is Docker with host networking, so the ID server sees the client’s real address rather than a container bridge address. Seeing the real address matters for NAT classification. Docker Desktop on Windows and macOS does not provide Linux host networking. The official Docker page says to remove --net=host when that setting causes trouble. A server that only ever sees a container IP will classify NAT badly even when the firewall rules look right. Details of the image, the volume ./data:/root, and the commands hbbs and hbbr are on the Docker page.
Clients can sit on any platform the client supports: Windows, macOS, the Linux families in the docs, Android, and iOS as a controller. iOS cannot be the host, so there is no iOS screen to traverse toward. Android can be a host only after the device owner accepts screen capture and enables the input accessibility service. The web client is a Pro feature with a plan-size rule, and it uses the WebSocket ports rather than the native punch in the same way. A Tailscale overlay, covered on the Tailscale integration page, changes the network the punch runs across. It does not replace RustDesk’s encryption rules, and RustDesk does not ship Tailscale.
Bringing the path up
- Run
hbbsandhbbron a Linux host with the official Compose layout or the officialdocker runlines. Keep the data directory. The public key appears asid_ed25519.pubafter the first ID-server start. - Open the native minimum: TCP 21115–21117 and UDP 21116. Leave 21118 and 21119 closed unless a reverse proxy is their only client.
- On both authorized clients, set the ID server and the key. Leave the relay blank if
hbbrshares the ID server’s host. Set the API server only on Pro, to port 21114 or an HTTPS URL. - Confirm each client shows Ready. Ready means registration, not a completed hole punch.
- Start a session you are allowed to start. If it connects quickly between two easy networks, you are likely on the direct path. If it connects only when relay is forced, punching is failing and
hbbris doing the work.
The optional relay-only setting from the Docker documentation looks like this on the ID service:
services:
hbbs:
container_name: hbbs
image: rustdesk/rustdesk-server:latest
environment:
- ALWAYS_USE_RELAY=Y
command: hbbs
volumes:
- ./data:/root
network_mode: "host"
depends_on:
- hbbr
restart: unless-stopped
hbbr:
container_name: hbbr
image: rustdesk/rustdesk-server:latest
command: hbbr
volumes:
- ./data:/root
network_mode: "host"
restart: unless-stopped
Start that file with docker compose up -d only after you have read it. The homepage can also download a publisher file, wget rustdesk.com/oss.yml -O compose.yml or wget rustdesk.com/pro.yml -O compose.yml, and the publisher’s other quick start pipes a remote shell script. Read any script before you run it. For a manual start without Compose, the official page uses:
sudo docker image pull rustdesk/rustdesk-server
sudo docker run --name hbbs -v ./data:/root -td --net=host --restart unless-stopped rustdesk/rustdesk-server hbbs
sudo docker run --name hbbr -v ./data:/root -td --net=host --restart unless-stopped rustdesk/rustdesk-server hbbr
Remove --net=host on Docker Desktop when connections fail. Host networking is how a Linux server sees the addresses NAT traversal depends on.
What you should see
Both clients should show Ready after they accept the ID server and the public key. A session between two networks with ordinary NAT should come up without you having set ALWAYS_USE_RELAY. During that session the relay host should stay comparatively idle, because direct media is between the endpoints. A session that only works after you set the relay variable should move bytes through hbbr, and the relay’s uplink becomes the limit.
“Not ready, please check your connection” happens before traversal. The client never registered, so there is nothing to punch. Check DNS, TCP and UDP 21116, the key, the clock, and docker logs hbbs. A client that is Ready and then fails as soon as you enter a password has gotten past rendezvous and is failing on the media path, on credentials, or on a local permission prompt. Those are different problems. There is no independently confirmed public status dashboard you can consult for a server you run yourself.
Troubleshooting traversal
If every session relays, look at NAT and at policy before you look at codecs. Symmetric NAT and many mobile carriers fall through to hbbr even when the software is healthy. That is the design. Size the relay for it. If no session connects at all, TCP 21117 is closed or hbbr is down. Ready will still be true, because Ready is hbbs. If sessions connect only from some sites, compare those sites’ outbound UDP policy. A network that blocks UDP will not punch a UDP hole.
Host networking bugs masquerade as NAT bugs. On Docker Desktop, a container that cannot use --net=host may observe the wrong source address and give both clients useless punch targets. Move the server to a Linux host or remove host networking the way the official page describes, then retest from two external networks. Do not conclude that “NAT traversal is broken” from a single laptop on the same LAN as the server. Same-LAN tests skip the NAT you are trying to understand, and hairpin NAT can fail a public DNS name that external clients use successfully.
Forcing relay is a clean test. Set ALWAYS_USE_RELAY=Y, restart hbbs, and try the session again. If it works only then, punching is the failed step and the relay is fine. If it still fails, the relay path or the credentials are the failed step. Turn the variable off again if you wanted direct sessions. Leaving it on spends uplink on every connection, including the ones that could have been peer to peer.
Security notes
Traversal assumes the normal ID-based model and the public key. Ship id_ed25519.pub to clients through a channel you trust. Keep the private key on the server, inside the data volume you back up. A client with the wrong key should not complete encrypted self-hosted use. A client pointed at Direct IP access is in the mode the FAQ documents as unencrypted, on by a separate switch, defaulting to port 21118. Leave that switch off unless the network underneath is already protected and you accept the documented limit.
Relay does not grant you a compliance badge. It also does not, by itself, widen the admin console. Keep TCP 21118 and 21119 closed unless a reverse proxy is the only client of those ports. The WebSocket code trusts X-Real-IP and X-Forwarded-For and does not validate them, so a direct caller can spoof an address in rate limits and logs. The 443-only WSS mode is the exception you build on purpose, with the proxy as the only public listener. Minimum native exposure remains TCP 21115–21117 and UDP 21116.
Pro’s license check needs outbound HTTPS. That call is part of running Pro, not part of the punch. OSS does not make it. Neither edition authorizes a session. The person at the host still approves with a password or a click, or the host is a machine your organization administers and has already configured for unattended access. The security guide covers the scam pattern of a stranger asking for an ID and a one-time password. Hang up. Architecture does not make that request legitimate.
Frequently Asked Questions
Does RustDesk always connect peer to peer?
No. The client tries UDP and TCP hole punching. Documentation says that works in the majority of cases. When it fails, hbbr relays the session. ALWAYS_USE_RELAY=Y skips the direct attempt on purpose.
Does the server see the remote desktop when the punch succeeds?
Direct session media is between the endpoints when peer-to-peer succeeds. hbbs has already done registration and signaling. Where you placed the server does not describe the path of that media and does not prove a compliance certification.
Is every RustDesk mode end-to-end encrypted?
Docs describe peer-to-peer end-to-end encryption based on NaCl for the normal ID-based connection model, using the public key from id_ed25519.pub when you self-host. Direct IP access is a different mode, and the FAQ documents an unencrypted path for it.
What does the NAT type test port do?
TCP 21115 lets hbbs classify NAT so the punch attempt is informed. It is part of the minimum native set, together with TCP and UDP 21116 and TCP 21117. It is not the relay and not the Pro console.