Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

How to Install and Run Local TURN Server on AWS for WebRTC

Sharing is caring!

Traversal Using Relays around NAT (TURN) is a protocol that assists in traversal of network address translators (NAT) or firewalls for multimedia applications. For most WebRTC applications to function a server is required for relaying the traffic between peers, since a direct socket is often not possible between the clients (unless they reside on the same local network). The common way to solve this is by using a TURN server. There are currently several options for TURN servers available online, both as self-hosted applications (like the open-source COTURN project) and as cloud provided services. In this article I describe how to setup your own TURN server on your AWS instance. Below are the steps.

Step 1

$ wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
$ tar xvfz libevent-2.1.8-stable.tar.gz
$ cd libevent-2.1.8-stable
$ ./configure
$ make
$ sudo make install

Step 2

Go to Coturn and download the latest version. I used turnserver-
$ wget http://coturn.net/turnserver/v4.5.0.7/turnserver-
$ tar xvfz turnserver-
$ cd turnserver-
$ export LDFLAGS=-L/usr/local/opt/openssl/lib
$ export CPPFLAGS=-I/usr/local/opt/openssl/include
$ ./configure
$ make
$ make install

Step 3

Setup TURN server users (for more info see Coturn Wiki).
$ sudo turnadmin -a -u admin -r rtcrandom -p s3cret
$ sudo turnadmin -A -u admin -p s3cret

Step 4

Start the server as a daemon (Note STUN requires username and password otherwise it will reject any requests!)
$ screen -S "coturn" -dm turnserver -u 'rtcrandom:s3cret' -v -n  -p 3478 -L -r rtcrandom -X\  --no-dtls --no-tls