How to setup a TURN server on Ubuntu Linux

This straightforward guide gets you up and running with your own TURN server on Ubuntu Linux in just 10 minutes, perfect for smoothing out those communication hiccups. We offer a variety of resources to make setup a breeze, including a quick TL;DR, a detailed written guide with clear screenshots, and a helpful video walkthrough. Plus, clear up any confusion with our informative FAQ section. Take control of your network communication and enjoy crystal-clear calls today!

What is a TURN server?

A TURN server (Traversal Using Relays around NAT) acts as a middleman for devices behind firewalls or complex NAT configurations. Unlike STUN, which just reveals public IP addresses, TURN relays data itself. Imagine it as a postal worker – each device sends its data packets to the TURN server, which then forwards them on to the other device, enabling communication even when direct connections are blocked.

Setting up your own TURN server on Ubuntu Linux (video instructions)

The next video is a tutorial onsetting up your own TURN server on Ubuntu Linux in crystal-clear detail. Follow along step-by-step as we navigate the Terminal: updating packages, installing software, configuring settings, and finally launching your server. It may sound jarring, but do not worry, as it is barely 4 minutes long. By the end, you will be a TURN server pro, empowering direct communication within your network – perfect for video or audio calls.

Setting up your own TURN server on Ubuntu Linux (quick steps)

  1. Open Terminal
  2. Update packages
  3. Install coturn
  4. Open config file
  5. Set listening port
  6. Enable verbose logging
  7. Enable long term credential mechanism
  8. Set realm
  9. Set log file path
  10. Add username and password
  11. Open coturn file
  12. Start turn server
  13. Restart coturn service

Setting up your own TURN server on Ubuntu Linux (detailed written guide)

First, open Terminal and enter the following to update your packages:

sudo apt-get -y update

Once the update is complete, use the next command to install coturn, as seen in Figure 1:

sudo apt-get install coturn -y

Update packages and install coturn
Figure 1 - Update packages and install coturn

With the usage of the command below, create a backup of the config file (Figure 2):

sudo cp /etc/turnserver.conf /etc/turnserver.conf.bak

Backup config file
Figure 2 - Backup config file

sudo nano /etc/turnserver.conf

open turnserver conf with nano
Figure 3 - Open config file with Nano

Next, enter this command to set your desired listening port, as shown in Figure 4:

listening-port=3478

Set listening port
Figure 4 - Set listening port

Enable verbose logging by entering the next command, as you can see in Figure 5:

verbose

Enable verbose logging
Figure 5 - Enable verbose logging

To enable long term credential mechanism, use the following command (Figure 6):

lt-cred-mech

Enable long term credential mechanism
Figure 6 - Enable long term credential mechanism

Set your desired realm via the command below, similarly to Figure 7:

realm=mycompany.com

Set realm
Figure 7 - Set realm

Set your log file's path by entering the next command, highlighted in Figure 8:

log-file=/var/tmp/turn.log

Set log file path
Figure 8 - Set log file path

Add your username and password with this command (Figure 9):

user=ozekitestuser:abc123

Add user
Figure 9 - Add user

Go back to the Terminal and open your coturn file by entering the command below, as seen in Figure 10:

sudo nano /etc/default/coturn

Figure 10 - Open coturn file

Once inside, enter the following command to enable your turn server, as demonstrated by Figure 11:

TURNSERVER_ENABLED=1

Enable turn server
Figure 11 - Enable turn server

Finally, head back to the Terminal and restart the coturn service with the next command:

sudo service coturn restart

Restart coturn service
Figure 12 - Restart coturn service

Is there a way for me to test my TURN server?

Yes, you can test your TURN server's ICE triclking functionality. Click here if you would like to learn more.

Are TURN servers TCP or UDP?

TURN servers are flexible, able to utilize both UDP and TCP for data relay. UDP is the go-to choice for its speed, crucial for real-time applications, but it does not guarantee delivery. When speed is not paramount and data integrity is critical, like in file transfers, TCP steps in with its reliable, ordered delivery, even if it might introduce some lag.

More information