# RustDesk Server

> Self-hosted remote desktop infrastructure, TeamViewer/AnyDesk alternative.

- Category: Home Lab & Self-Hosting
- Difficulty: beginner
- Components: rustdesk-server, rustdesk-relay
- Tags: remote-desktop, rustdesk, self-hosted, teamviewer-alternative
- Source: https://docker.recipes/homelab/rustdesk-server

## Overview

RustDesk is an open-source remote desktop solution that provides a self-hosted alternative to proprietary services like TeamViewer and AnyDesk. Originally developed as a cross-platform remote desktop client, RustDesk includes server components that enable organizations to maintain complete control over their remote access infrastructure, eliminating reliance on third-party services and ensuring sensitive data never leaves their network perimeter. The server implementation consists of two primary components: hbbs (ID/rendezvous server) and hbbr (relay server), which work in tandem to facilitate secure peer-to-peer connections.

The hbbs component functions as the central coordination hub, managing client registration, authentication, and initial connection brokering between remote desktop sessions. Meanwhile, hbbr serves as the relay server that handles NAT traversal and maintains connections when direct peer-to-peer communication isn't possible due to network configurations or firewall restrictions. This dual-server architecture ensures reliable connectivity across diverse network topologies while maintaining the performance benefits of direct connections whenever feasible.

This stack is particularly valuable for organizations requiring compliance with data residency regulations, companies with stringent security policies that prohibit external remote access services, and technical teams seeking customizable remote desktop solutions. System administrators managing distributed teams, MSPs providing remote support services, and privacy-conscious users who prefer self-hosted alternatives will find this configuration essential for maintaining secure, auditable remote access capabilities without subscription costs or external dependencies.

## Features

- Ed25519 cryptographic key-based authentication for tamper-resistant client verification
- Mandatory encryption enforcement preventing unencrypted remote desktop sessions
- Automatic NAT traversal through dedicated relay server for complex network topologies
- Cross-platform client support including Windows, macOS, Linux, iOS, and Android
- Direct peer-to-peer connections bypassing relay when network conditions permit
- Centralized connection logging and session management through hbbs coordination
- Custom server configuration allowing white-label deployment for service providers
- UDP and TCP dual-protocol support optimizing performance based on network conditions

## Use cases

- Enterprise IT departments replacing TeamViewer subscriptions with self-hosted remote support
- Managed service providers offering branded remote desktop access to clients
- Educational institutions providing secure remote lab access to students and faculty
- Healthcare organizations ensuring HIPAA-compliant remote workstation access
- Financial services maintaining SOX compliance while enabling remote work capabilities
- Government agencies requiring air-gapped remote desktop infrastructure
- Software development teams accessing development servers and testing environments securely

## Prerequisites

- Docker Engine 20.10+ and Docker Compose V2 for container orchestration support
- Minimum 512MB RAM allocation for both hbbs and hbbr server processes
- Available ports 21115-21119 for client connections and inter-service communication
- Static IP address or dynamic DNS configuration for client endpoint discovery
- Firewall rules permitting inbound UDP/TCP traffic on designated RustDesk ports
- SSL certificate management strategy for production deployments with custom domains

## docker-compose.yml

```yaml
services:
  hbbs:
    image: rustdesk/rustdesk-server:latest
    container_name: rustdesk-hbbs
    command: hbbs
    environment:
      - ENCRYPTED_ONLY=1
    volumes:
      - rustdesk-data:/root
    ports:
      - "21115:21115"
      - "21116:21116"
      - "21116:21116/udp"
      - "21118:21118"
    networks:
      - rustdesk-network
    restart: unless-stopped

  hbbr:
    image: rustdesk/rustdesk-server:latest
    container_name: rustdesk-hbbr
    command: hbbr
    volumes:
      - rustdesk-data:/root
    ports:
      - "21117:21117"
      - "21119:21119"
    networks:
      - rustdesk-network
    restart: unless-stopped

volumes:
  rustdesk-data:

networks:
  rustdesk-network:
    driver: bridge
```

## .env

```bash
# RustDesk Server
# Public key will be generated in rustdesk-data volume
# Configure clients with your server IP and public key
```

## Usage notes

- ID server (hbbs) handles connections
- Relay server (hbbr) for NAT traversal
- Get public key from data/id_ed25519.pub
- Configure clients with server IP + key
- Encrypted connections only

## Troubleshooting

- Clients cannot discover server: Verify ports 21115-21116 are accessible and DNS resolution points to correct server IP address
- Connection established but screen sharing fails: Check that port 21117 (relay server) is properly forwarded and hbbr container is running
- Authentication failures with correct key: Ensure ENCRYPTED_ONLY=1 is set and clients are using the public key from id_ed25519.pub file
- High CPU usage on relay server: Monitor concurrent connections and consider scaling hbbr instances for environments exceeding 50 simultaneous sessions
- Intermittent disconnections during sessions: Verify UDP port 21116 is not blocked by ISP or corporate firewall policies
- Unable to retrieve public key for client configuration: Check that rustdesk-data volume is properly mounted and containers have write access to /root directory

