Private WebRTC endpoints are often shielded from the public internet by a network that does the...
Quick Guide for STUN/TURN and WebRTC.
Why STUN/TURN?
In order to do WebRTC across different networks, we need to bypass firewalls and we also have all kinds of restrictions set by ISPs, in order to bypass this restrictions and punch a hole in the receptors firewalls to get media through we need to rely on a STUN/TURN server, to either find the right route if possible (STUN), or act as a relay server for the media passing through (TURN), in this brief guide we setup a basic STUN/TURN server.
We’ll use an open source implementation of a STUN/TURN server, Coturn.
Installing Coturn.
Assuming you are on a Ubuntu 14.04 LTS server run the following commands:
# in ubuntu versions above 14.04 coturn is already on the base repositories | |
echo "deb http://ftp.us.debian.org/debian jessie main" >> /etc/apt/sources.list | |
gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553 | |
gpg -a --export 8B48AD6246925553 | apt-key add - | |
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010 | |
gpg -a --export 7638D0442B90D010 | apt-key add - | |
apt-get update | |
apt-get install coturn |
When the installation is ready, run the following command in your terminal:
$ turnserver -avn -u user:password -r yourdomain.com | |
# “a” use long-term credentials, “v” verbose output, “n” do not load a configuration file. | |
# "u" Specify user and password credentials to be used. | |
# "r" Specify default realm, can be your domain. | |
# to check if coturn is running you can run | |
$ netstat -lnp | grep 3478 |
Testing your STUN/TURN server.
In order to test your TURN server, you can make use of this tool provided by the WebRTC team: https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
Input your server information like this:

A successful output from testing TURN should look like this:

You can see two rows that say relay, this indicates that the TURN server is working correctly, if there’s nothing that says relay on this output, the TURN server is not working as expected.
Keep in mind, this is not a setup appropriate for production environments, it’s simply to have a way to test your WebRTC application without the need of purchasing a TURN server or getting it by other means.
If you want to know more about WebRTC solutions, need assessment, or just want to have a quote on our services, Contact us!