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.
$ 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
$ sudo make install
Go to Coturn and download the latest version. I used turnserver-188.8.131.52.tar.gz.
$ wget http://coturn.net/turnserver/v184.108.40.206/turnserver-220.127.116.11.tar.gz
$ tar xvfz turnserver-18.104.22.168.tar.gz
$ cd turnserver-22.214.171.124
$ export LDFLAGS=-L/usr/local/opt/openssl/lib
$ export CPPFLAGS=-I/usr/local/opt/openssl/include
$ make install
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
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 172.31.25.195 -r rtcrandom -X 126.96.36.199\172.31.25.195 --no-dtls --no-tls