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
tar xvfz libevent-2.1.8-stable.tar.gz
./configure
sudo make install
Step 2
Go to Coturn and download the latest version. I used turnserver-4.5.0.7.tar.gz.
tar xvfz turnserver-4.5.0.7.tar.gz
export LDFLAGS=-L/usr/local/opt/openssl/lib
./configure
make install
Step 3
Setup TURN server users (for more info see Coturn Wiki).
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 172.31.25.195 -r rtcrandom -X 35.158.16.195\172.31.25.195 --no-dtls --no-tls