Using TURN Servers
Overview
This document describes how to enable VoIP relaying (TURN) on a homeserver.
The palpo Matrix homeserver supports integration with TURN servers via the TURN server REST API. This allows the homeserver to generate usable TURN server credentials using a secret key shared with the TURN server.
This document uses the coturn server as an example for configuration instructions.
Prerequisites
For TURN relaying to function correctly, the TURN service must be deployed on a server/endpoint with a public IP address.
If TURN is deployed behind NAT, port forwarding is required, and the NAT gateway must have a public IP. Even if configured correctly, NAT can cause issues and is generally not recommended.
Additionally, the homeserver requires further configuration.
Configuring Palpo
Your homeserver configuration file has a [turn] section for TURN server configuration.
For example, the following is a relevant configuration snippet from matrix.org. The turn_uris are for a TURN server listening on the default port without TLS.
After updating the homeserver configuration, restart palpo:
- If using synctl:
- If using systemd:
- If using docker compose:
Then reload the client (or wait up to an hour for settings to refresh automatically).
Installing and Configuring Coturn
Coturn is a free, open-source TURN/STUN server implementation. A TURN server acts as a NAT traversal server and gateway for VoIP media traffic.
Initial Installation
The TURN daemon coturn can be installed in various ways, such as via package manager or from source.
Debian/Ubuntu
Install the Debian package directly:
This installs and starts a systemd service named coturn.
Installing from Source
-
Download the source code from the latest release page on GitHub, extract it, and enter the directory.
-
Configure the build:
If
libevent2is required, install it as recommended for your system. Database support can be ignored. -
Compile and install:
Docker Compose Installation
Create a compose.yml file and add the coturn configuration:
Then run:
For more installation details, refer to the official documentation.
Configuration
-
Edit
/etc/turnserver.conf. The main configurations are as follows:The
static-auth-secretcan be generated usingpwgen:The
realmmust be specified and is typically set to your server name. -
It is recommended to configure coturn to output logs to syslog:
Alternatively, configure it to write to a log file. See the coturn example configuration for details.
-
For security recommendations, a minimal configuration includes:
-
To support TLS/DTLS, add the following configuration:
If using Let's Encrypt certificates, note that Element Android/iOS may not support them; ZeroSSL is recommended.
-
The firewall must allow TURN ports (default 3478, 5349, and UDP relay ports 49152-65535).
-
If TURN is behind NAT, configure
external-ip:Optional: Restrict listening to the local IP:
When IPv6 is supported, configure IPv4 and IPv6 separately.
-
Restart the TURN server:
-
For Debian package or systemd:
-
For source installation:
-
Troubleshooting
Common symptom: Calls between different networks get stuck on "Connecting." Troubleshooting suggestions:
-
Check if the firewall allows TURN ports (3478, 5349, and UDP relay ports 49152-65535).
-
Try enabling only non-encrypted TCP/UDP listening (WebRTC media streams are always encrypted).
-
Some WebRTC implementations (e.g., Chrome) have poor IPv6 support; consider removing AAAA records and using IPv4 only.
-
In NAT scenarios, ensure port forwarding and
external-ipconfiguration are correct. -
Enable
verboselogging in coturn or debug logging in eturnal. -
On the browser side, use
chrome://webrtc-internals/or Firefox's about:webrtc to view connection logs. -
Test Matrix TURN configuration using https://test.voip.librepush.net/ or test the TURN server with https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/.
-
Generate test usernames/passwords using the following shell command:
-
Temporarily configure static username/password in coturn:
After modifying the configuration, restart coturn. Remember to revert to the original configuration after testing.
If TURN is configured correctly, the test results should include at least one relay entry.
{/* 本行由工具自动生成,原文哈希值:d7e5c1620cc9f3e43657950742e7996c */}