Run your own TURN relay
Some networks cannot establish a direct WebRTC connection. A TURN relay can carry the encrypted connection between the two browsers. HushPeer does not provide a TURN server or account; you run and pay for your own relay.
Before you begin
Use a Linux server with a public IP, Docker Compose, and access to its cloud security group and firewall. The example starts with TURN over UDP. If the server sits behind NAT, map its public address to its private address.
1. Create the Docker configuration
Create a private directory on the server. Save this as compose.yaml:
services:
coturn:
image: quay.io/coturn/coturn:latest
container_name: coturn
restart: unless-stopped
network_mode: host
command: ["-c", "/etc/coturn/turnserver.conf"]
volumes:
- ./turnserver.conf:/etc/coturn/turnserver.conf:ro
Host networking lets coturn use its UDP relay port range directly. It requires a Linux Docker host. The same image is available as coturn/coturn:latest on Docker Hub.
In the same directory, save turnserver.conf. Replace the example realm and password:
listening-port=3478
fingerprint
lt-cred-mech
realm=turn.example.com
user=whispeer:REPLACE_WITH_A_LONG_RANDOM_PASSWORD
min-port=49160
max-port=49259
no-multicast-peers
no-tls
log-file=stdout
pidfile=/var/tmp/turnserver.pid
Keep the real password out of Git. The coturn image runs as UID 65534. On a standard Linux Docker host, chown 65534:65534 turnserver.conf and chmod 600 turnserver.conf let the container read it while restricting other local users. Adapt the UID if Docker user namespaces are enabled.
If a public IP maps to a private NIC address, add external-ip=PUBLIC_IP/PRIVATE_IP. On hosts with several NICs, set listening-ip=PRIVATE_IP and relay-ip=PRIVATE_IP as appropriate. The relay UDP ports need one-to-one forwarding.
2. Open the ports and start coturn
| Protocol | Port | Purpose |
|---|---|---|
| UDP | 3478 | TURN client connection |
| TCP | 3478 | TURN over TCP (optional) |
| UDP | 49160–49259 | Relay allocations |
Allow these ports in both the cloud security group and server firewall. The UDP relay range must match turnserver.conf.
docker compose up -d
docker compose logs --tail=50 coturn
3. Enter the relay in HushPeer
On both devices, open HushPeer → Relay settings and enter:
| Field | Value |
|---|---|
| TURN address | turn:turn.example.com:3478?transport=udp |
| Username | whispeer |
| Credential | The password after user=whispeer: |
For the first test, enable Relay only on both devices. Once connected, the conversation info should show “Through relay server.” You can then disable Relay only to allow direct connections when available. Settings stay in the current browser tab.
Optional: TURN over TLS
For turns:, obtain a publicly trusted certificate for your TURN hostname or public IP. Mount the certificate and key read-only, make them readable by coturn, remove no-tls, and add:
tls-listening-port=5349
cert=/etc/coturn/certs/fullchain.pem
pkey=/etc/coturn/certs/privkey.pem
Add ./certs:/etc/coturn/certs:ro to the service volumes, allow TCP 5349, and enter turns:turn.example.com:5349?transport=tcp in HushPeer. Renew the certificate and reload coturn before it expires. Ordinary browsers reject self-signed certificates.
Troubleshooting and capacity
docker stats coturn
docker compose logs -f coturn
If a connection fails, check the public address and NAT mapping, security group and firewall, TURN settings on both devices, credentials, and UDP relay port range. A running container alone does not prove the relay ports are reachable from the internet.
For a small setup, plan roughly 256–512 MB of memory and adjust to actual docker stats usage. Relay traffic passes through your server, so bandwidth, data charges, and port capacity often matter more than idle memory.