Skip to content

Commit 80c170d

Browse files
committed
turn server install guide improved
1 parent b17ab24 commit 80c170d

File tree

5 files changed

+260
-228
lines changed

5 files changed

+260
-228
lines changed

turnserver.conf

Lines changed: 0 additions & 54 deletions
This file was deleted.

turnserver.md

Lines changed: 101 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,135 @@
1-
## Install and setup guide for a TURN Relay Server
1+
# TURN Server Setup Guide
22

3-
#### why? You may want to deploy one to ensure high compatiblity with remote guests. If you try to use the official VDO.Ninja TURN servers for a private deployment, you may find yourself getting kicked off.
3+
## Understanding STUN vs TURN
44

5-
This install script and config file was used with a standard virtual machine server loaded with Ubuntu 20. GCP/AWS servers might need slightly different settings.
5+
WebRTC tries to establish peer-to-peer connections using the following methods, in order:
6+
1. Direct connection
7+
2. STUN - helps peers discover their public IP address and port
8+
3. TURN - relays traffic between peers when direct/STUN connections fail
69

7-
```
8-
sudo apt-get update # update package lists
9-
10-
sudo apt-get install coturn -y # install coturn, the implementation of the TURN server
11-
sudo vi /etc/default/coturn # open the coturn configuration in Vim (you can also use nano or any other editor)
12-
```
13-
...and we uncomment the line:
14-
```
15-
#TURNSERVER_ENABLED=1
16-
```
17-
….leaving it like this:
18-
```
19-
TURNSERVER_ENABLED=1
20-
```
21-
If we want to support TCP / TLS, we need an SSL certificate installed. Certbot has lots of issues to work around, but it's free. If you buy a cert some where else, you may need to convert your certificate to one that's compatible with coturn. Either way, adding TCP/TLS is a pain that isn't needed for 99% of the users out there.
22-
```
23-
sudo add-apt-repository ppa:certbot/certbot # Add the certbot repository
24-
sudo apt-get install certbot -y # Install certbot required for the HTTPS certificate
25-
sudo certbot certonly --standalone # only generate the HTTPS certificate without actually changing any configs
26-
```
27-
If you want to setup a firewall or configure an existing firewall, you can see the below setup and configurations. This can often be skipped for new Ubuntu installations, but I'll leave that up to you
28-
```
29-
sudo apt install net-tools
30-
sudo ufw allow 3478/tcp # The default coturn TCP port
31-
sudo ufw allow 3478/udp # The default coturn UDP port
32-
sudo ufw allow 3479/tcp # Sometimes port+1 is used
33-
sudo ufw allow 3479/udp # Sometimes port+1 is used
34-
sudo ufw allow 443/tcp # The HTTPS TCP port
35-
sudo ufw allow 443/udp # The HTTPS UDP port
36-
sudo ufw allow 49152:65535/tcp
37-
sudo ufw allow 49152:65535/udp
38-
```
39-
If we expect heavy usage of this server, like hundreds of connections, you might want to ensure your system supports enough open sockets. I'm not sure if this actually works or is needed, but you can see this article for example on how to increase the number of available sockets on Ubuntu: https://medium.com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a
40-
41-
If you do want to increase the connection limit, for larger systems, it's as follows:
42-
```
43-
ulimit -n 65535
44-
sudo vim /etc/sysctl.conf
45-
```
46-
Add the following line to the file anywhere (with vim, press i to insert new text and :wq to save and exit)
47-
```
48-
fs.file-max = 65535
49-
```
50-
Once saved, you can apply the changes
51-
```
52-
sudo sysctl -p
53-
```
54-
And that should have set the connection limit to be higher now.
10+
### STUN (Session Traversal Utilities for NAT)
11+
- Lightweight protocol that helps peers behind NAT discover their public IP address
12+
- Low bandwidth usage as it only helps with connection discovery
13+
- No relay costs, but doesn't work when peers are behind strict firewalls
5514

56-
Next, update turnserver.conf with passwords, domain names, and whatever else that needs changing. Example contents are provided below. Once you have updated it, start the TURN server and ensure it started correctly. At the bottom of this page is a sample conf file; I personally use `turnserver3.conf` (https://github.com/steveseguin/vdo.ninja/blob/master/turnserver3.conf), which is hosted in the main repo, for quick TURN deployments.
15+
### TURN (Traversal Using Relays around NAT)
16+
- Relays all traffic through the server when direct/STUN connections fail
17+
- Higher bandwidth usage and server costs
18+
- Required for peers behind symmetric NATs or strict firewalls
19+
- More reliable but should only be used as a fallback
5720

58-
```
59-
sudo vi /etc/turnserver.conf
60-
```
61-
Tip: For those doing their own LAN-deployment, you might want to add STUN-support to the TURN server while at it. Refer to the co-turn documentation for help there though.
21+
## Quick Install
6222

63-
Next, once we have all the settings and configs setup, we can enable the system service for co-turn to auto-start on boot.
23+
The installer script automates the complete TURN server setup process:
6424

65-
This is our service file; it should exist.
66-
```
67-
sudo vi /usr/lib/systemd/system/coturn.service
68-
```
69-
To ensure it's enabled, try this:
70-
```
71-
sudo systemctl daemon-reload
72-
sudo systemctl enable coturn
73-
```
25+
```bash
26+
# Download the installer
27+
wget https://raw.githubusercontent.com/steveseguin/vdo.ninja/develop/turnserver_install.sh.sample
28+
mv turnserver_install.sh.sample turnserver_install.sh
29+
chmod +x turnserver_install.sh
7430

75-
To start the co-turn service and to see if it had any errors:
76-
```
77-
sudo systemctl restart coturn
78-
sudo systemctl status coturn
31+
# Run the installer
32+
sudo ./turnserver_install.sh
7933
```
80-
You can then validate that things are working at the following site:
81-
82-
https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
8334

84-
An example URL is `turn:turnserver.mydomain.com:3478`
85-
or for TCP/TLS, try `turns:turnTLS.mydomain.com:443`
35+
The installer will:
36+
1. Install coturn and dependencies
37+
2. Configure system limits for high connection loads
38+
3. Set up base TURN/STUN configuration
39+
4. Optionally configure SSL/TLS support
40+
5. Create systemd service for auto-start
41+
6. Configure proper permissions
8642

87-
note: If you run into error 701 issues with your TURN server, check that the coturn service has access to your new SSL certificates:
88-
see this issue with coturn: https://github.com/coturn/coturn/issues/268
43+
## Basic Configuration Explained
8944

90-
You might also want to consider buying a better certificiate, as not all Google-related projects properly support certbot certificates, including libwebrtc. see [this issue ticket](https://github.com/coturn/coturn/issues/240#issuecomment-648550885). If you go this route, see [turnserver2.conf](https://github.com/steveseguin/vdo.ninja/blob/master/turnserver2.conf) for an example config.
45+
The basic configuration (`turnserver_basic.conf`) provides a minimal but functional TURN server:
9146

92-
Next, we may want to update the User and Group values in our service file to be "root". This seems to be a quick hacky fix for the issue with Lets Encrypt. .. I welcome a better solution tho. If you move the certs somewhere else, or buy proper certificates, then the default turnserver user/group will work.
47+
```conf
48+
listening-port=3478 # Standard STUN/TURN port
49+
fingerprint # Required for WebRTC
50+
lt-cred-mech # Long-term credential mechanism
51+
user=username:password # Authentication credentials
52+
stale-nonce=600 # Nonce timeout in seconds
53+
realm=turn.example.com # Your server's domain
54+
server-name=turn.example.com
55+
no-multicast-peers # Security measure
56+
dh2066 # Strong DH params
57+
no-stdout-log # Disable stdout logging
58+
```
9359

94-
Ultimately though, if you are still getting the 701 error -- just test to see if the TURN service works; if it does, the error can probably be ignored.
60+
## SSL/TLS Support (Optional)
9561

62+
The installer can configure SSL/TLS support which:
63+
- Enables TURNS (TURN over TLS) on port 443
64+
- Automatically obtains and renews SSL certificates via certbot
65+
- Configures automatic certificate reload without server restart
9666

97-
The following are the contents of an example /etc/turnserver.conf file from above
98-
```
99-
## sudo vi /etc/turnserver.conf
67+
## Testing Your Server
10068

101-
listening-port=3478
102-
## TLS needs an SSL certificate and domain, but enables TCP
103-
tls-listening-port=443
69+
Test your TURN server at: https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
10470

105-
# min-port=49152
106-
# max-port=65535
71+
Example configurations to test:
72+
- STUN/TURN: `turn:your-domain:3478`
73+
- TURNS (if SSL enabled): `turns:your-domain:443`
10774

108-
realm=turn.obs.ninja
109-
server-name=turn.obs.ninja
75+
## Firewall Configuration
11076

111-
## webrtc likes to use this
112-
fingerprint
77+
Required ports:
78+
- 3478 TCP/UDP (STUN/TURN)
79+
- 443 TCP/UDP (TURNS, if enabled)
80+
- 49152:65535 TCP/UDP (Media relay ports)
11381

114-
## Lets just use Google since its more reliable
115-
no-stun
82+
## Advanced Usage
11683

117-
lt-cred-mech
118-
user=SOMESUERNAME:SOMEPASSWQORD
84+
### Reloading SSL Certificates
85+
```bash
86+
sudo systemctl --signal=SIGUSR2 kill coturn
87+
```
11988

120-
stale-nonce=600
89+
### Checking Server Status
90+
```bash
91+
sudo systemctl status coturn
92+
```
12193

122-
## depreciated in newer coturn
123-
# no-loopback-peers
94+
### Updating Configuration
95+
1. Edit `/etc/turnserver.conf`
96+
2. Restart service: `sudo systemctl restart coturn`
12497

125-
## prevents hackers from hacking
126-
no-multicast-peers
98+
## Common Issues
12799

128-
## 1-gbps/100 users = ~ 1-mbps each with this setting then
129-
total-quota=100
100+
1. **Permission denied errors**
101+
- The installer handles this by setting proper capabilities
102+
- Manual fix: `sudo setcap cap_net_bind_service=+ep /usr/bin/turnserver`
130103

131-
cert=/etc/letsencrypt/live/turn.obs.ninja/fullchain.pem
132-
pkey=/etc/letsencrypt/live/turn.obs.ninja/privkey.pem
104+
2. **SSL certificate errors (701)**
105+
- Verify certificate permissions
106+
- Check certificate paths in configuration
107+
- Ensure certificates are readable by turnserver user
133108

134-
## Tweaks to fix some lets encrypt errors
135-
cipher-list="ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384"
136-
no-sslv3
137-
no-tlsv1
138-
no-tlsv1_1
139-
# no-tlsv1_2
140-
dh2066
109+
## Production Considerations
141110

142-
# no-udp
143-
# no-tcp
111+
1. **System Limits**
112+
The installer configures higher system limits for production use:
113+
- File descriptors: 65535
114+
- System max files: 65535
144115

145-
# verbose
146-
no-stdout-log
116+
2. **Monitoring**
117+
- Monitor bandwidth usage
118+
- Watch for high CPU/memory usage
119+
- Track active connections
147120

148-
## optional
149-
proc-user=root
150-
proc-group=root
121+
3. **Security**
122+
- Regularly update credentials
123+
- Monitor for abuse
124+
- Keep coturn and SSL certificates up to date
151125

152-
```
126+
## Support
153127

154-
For those who are using Certificates with their coturn installations, you can use `sudo systemctl --signal=SIGUSR2 kill coturn` to reload the certs in coturn without restarting and disconnecting current users. This can be especially useful for certbot users, who need to update every few months; triggering the command after certbot runs could make life easy.
128+
For issues or questions:
129+
- Create an issue on the VDO.Ninja GitHub repository
130+
- Join the VDO.Ninja Discord community
155131

156-
Anyways, setting this all up is easier said then done. My suggestion is to start simple, get that working, and if needed, improve from there. good luck!
132+
## References
133+
- [Coturn Documentation](https://github.com/coturn/coturn/wiki/turnserver)
134+
- [WebRTC Samples](https://webrtc.github.io/samples/)
135+
- [VDO.Ninja GitHub](https://github.com/steveseguin/vdo.ninja)

turnserver2.conf

Lines changed: 0 additions & 52 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)