Skip to content

How to setup Coturn (with Docker)

Untested

Description

coturn is a free open source implementation of TURN and STUN Server. The TURN Server is a VoIP media traffic NAT traversal server and gateway.

Files and Folders

Create the folder structure.

cd ~/services
mkdir -p coturn
touch coturn/turnserver.conf

Config file

First, generate a strong secret:

openssl rand -hex 32

Copy it to your clipboard!

Then, add this to turnserver.conf:

listening-port=3478
realm=your-server-hostname
listening-ip=your-local-ip
relay-ip=your-local-ip
external-ip=your-public-ip
fingerprint
use-auth-secret
static-auth-secret=the-strong-secret-you-generated-a-few-seconds-ago
total-quota=100
bps-capacity=0
stale-nonce=600
no-multicast-peers
listening-port=3478
realm=akdscloud.eu
listening-ip=192.168.100.50
relay-ip=192.168.100.50
external-ip=79.112.49.99
fingerprint
use-auth-secret
static-auth-secret=6916dd4b841e9bcb12c226696ec510f9a9c3aaa775bd526e6e3400866d6d3cff
total-quota=100
bps-capacity=0
stale-nonce=600
no-multicast-peers

Docker

  1. Add the coturn section to your docker-compose.yml file:

      coturn:
        image: coturn/coturn:latest
        container_name: coturn
        network_mode: host  # Required for TURN server to work properly
        restart: unless-stopped
        volumes:
          - ./coturn/turnserver.conf:/etc/coturn/turnserver.conf:ro
        environment:
          - TURNSERVER_CONFIG_FILE=/etc/coturn/turnserver.conf
    
  2. Download and start the coturn docker image:

    docker compose up -d coturn
    

Configuration

The only way to know if the service actually works as intended is to see if other services can use it successfully.

You'll need to configure your Audio/Video call service(s) to use your (co)turn service.

Port forwarding

First, you'll need to go to your router settings and forward port 3478 to the server where your coturn service is running.

Warning

Make sure it's for both TCP and UDP.
If it's just TCP, it won't work!

Matrix/Synapse

Add this to your homeserver.yaml configuration (probably in /home/dan/services/matrix/synapse/):

turn_uris: 
    - "turn:akdscloud.eu:3478?transport=udp"
    - "turns:akdscloud.eu:3478?transport=tcp"
turn_shared_secret: "your_very_secret_key_here"  # Use the same secret you set in turnserver.conf
turn_user_lifetime: 86400000
turn_allow_guests: true

Nextcloud Talk

Go to Nextcloud admin panel > Talk settings.

Add new TURN server

turn: only
akdscloud.eu:3478
"your generated secret" (from turnserver.conf)
UDP and TCP

Check if it's running by clicking the pulse button on the right.

If the pulse button turns into a green checkmark, then everything is ok!
If the pulse button turns into a red warning icon, then the TURN server isn't running properly.

Add new STUN server

akdscloud.eu:3478

Jitsi Meet

Make sure you have these in your docker-compose.yml under jvb --> environment:

    jvb:
        environment:
            - JVB_ADVERTISE_IPS=${JVB_ADVERTISE_IPS}
            - JVB_STUN_SERVERS=akdscloud.eu:3478
    prosody:
        environment:
            - STUN_HOST=akdscloud.eu
            - STUN_PORT=3478
            - TURN_CREDENTIALS=${TURN_CREDENTIALS}
            - TURN_HOST=akdscloud.eu
            - TURN_PORT=3478
            - TURN_TRANSPORT=tcp,udp

Add/modify the following variables in the .env file:

TURN_CREDENTIALS=<put your TURN server's secret here>
JVB_ADVERTISE_IPS=<put you machine's public IP here> (e.g. 5.14.163.81)

Github page