Skip to main content

how to setup and configure turn server using coturn

  • Prerequisites

  • Use Open Relay Project Instead

  • Step 1 Installing Coturn

  • Step 2 Configuring Coturn

    • Configuring new Turn server with Coturn
    • Using Open Relay Project
  • Step 3 Testing the Turn Server

  • Benefits of using Coturn

  • disadvantages of using COturn

  • Benefits of using Open Relay Project

  • Disadvantages of using Open Relay Project

  • Optional: Adding Domain to your Turn Server

  • Optional: Running Turn Server on Docker

  • Resources

  • Conclusion

Step 1 Installing Coturn​

Coturn is a open source STUN and TURN server implementation that can be used for NAT traversal and a general purpose network traffic TURN server and gateway

In this section we will install Coturn to your linux machine and enable the process,

First, Update the OS repo versions to the latest by running

sudo apt-get update

and

sudo apt-get upgrade

then to install coturn

sudo apt-get install coturn

If you want the Coturn to start automatically whenever you turn on the server. Follow the below steps:

  1. go to file /etc/default/coturn
sudo nano /etc/default/coturn

or

sudo vim /etc/default/coturn

Open the file and find the line

TURNSERVER_ENABLED=1

uncomment it and save the file. Now, start the coturn server

systemctl start coturn

Step 2 Configuring Coturn​

Let us now set up some basic configuration settings like adding

  • external IP address and
  • adding basic auth

Before modifying the configuration file it is recommended to make a copy of the original configuration file if we need in the future

mv /etc/turnserver.conf /etc/turnserver.conf.original

This will rename the original file name from turnserver.conf to turnserver.conf.original

Next replace the Coturn server realm and server name.

# TURN server name and realm
realm=<DOMAIN>
server-name=<SERVER_NAME>

What is realm?

It is a "key" to access a group of address that have a common "owner". A TURN server can have one "default realms" or more "named realms" in its database. And any realm has its own users and each of them have a proper login/password couple to identify access and working sessions.

If we do not edit this file it will use the default realm value. We can have a general realm where all users connect

next let us set up the TURN servers external IP and the listening IP. External IP is the IP that the TURN server is assigned (this you will get from the aws or any other cloud provider that you are using).

Listening IP is the is that the TURN server will listen to. If you want the TURN server to listen to all IP Addresses set the listening IP to 0.0.0.0

# IPs the TURN server will listen to 
listening-ip=0.0.0.0

#external-ip=IP_ADDRESS

Next we will define the ports that the server will listen to and other ports for that are open for communication.

# Main listening Port
listening-port=4001

# External IP-Address of your TURN server
external-ip=IP-Address