Deployment of STUN/TURN Server
Prerequisites
System Requirements:
- Ubuntu machine with version 20/22
- 4 GB RAM
- 4 Core CPU
- 50 GB Storage
- Public IP Address/Domain or a 1:1 NAT with public IP Address/Domain
Ports published in the Firewall/NAT or forwarded to the machine:
- 3478 TCP/UDP
- 49152-65535 UDP
- Behind NAT 1:1 port mapping
Network Performance:
- High PPS (Packet-Per-Second Performance)
- Low network jitter (<=30ms)
- Low Latency (<=150ms)
Procedure
To install the STUN/TURN server on the Linux machine, follow the below steps:
Open the terminal server using SSH and run the below commands:
sudo apt-get update
sudo apt-get install openssl coturnTake the backup of the existing config file using the below command:
sudo cp /etc/turnserver.conf /etc/turnserver.orig
Edit the file “/etc/default/coturn” to ensure that coTURN always runs at startup using the below command:
sudo nano /etc/default/coturn
In the file, please search for the line TURNSERVER_ENABLED=1 and uncomment it.
Edit the configuration file and replace it with the settings mentioned in the sample file below. Once done, save the “turnserver.conf” file at the path “/etc/turnserver.conf”.
Sample config file:
realm=VALID_DOMAIN_NAME
server-name=VALID_DOMAIN_NAME
fingerprint
listening-ip=PRIVATE_IP_ADDRESS
relay-ip=PRIVATE_IP_ADDRESS
external-ip=PUBLIC_IP_ADDRESS/PRIVATE_IP_ADDRESS
listening-port=3478
min-port=49152
max-port=65535
user=username:password
lt-cred-mech
Now, start or restart the coTURN server by running the following commands:
To start:
systemctl start coturn
To restart:
sudo systemctl status coturn
sudo service restart coturn
Testing the STUN/TURN Server
Once the STUN/TURN server is installed and configured, test it to check whether it works as expected. To do so, visit the site Trickle ICE.
Add the STUN and TURN server details using the below format:
For STUN URI: stun:{IP Address/domain}:{Port}
For TURN URI: turn:{IP Address/domain}:{Port}
Enter the username and password for TURN URI, and click Add Server.
- Once done, initiate the test by clicking the Gather Candidates button.
- If the result contains "Done" status and a "relay" Component Type, as shown above, the STUN/TURN server works perfectly.