How to create and setup a STUN/TURN server on AWS

How to create and setup a STUN/TURN server on AWS?

Overview

Prerequisites and environment

Install and configure coturn server

This section explains installing and configuring coturn on an Ubuntu 20.04 LTS server.

1) Connect to your Ubuntu server with SSH.

2) Add the Universe repository:

3) Update and upgrade Ubuntu:

4) Reboot the server from the EC2 dashboard or with:

5) Install coturn:

6) Edit the file /etc/default/coturn and un-comment

to have coturn start on boot.

7) Edit the file /etc/turnserver.conf and un-comment

then change it to

to have coturn listen on port 443.

Note: The TURN listener port is used for UDP and TCP (default: 3478). TLS & DTLS can connect to the “plain” TCP & UDP port(s), too if allowed by configuration.

8) Un-comment listening-ip and replace the default IP with your Ubuntu server private IP:

9) Add a user and password for your Genymotion virtual device by un-commenting

and replacing username1 and password1 with your chosen values.

10) Edit the file /lib/systemd/system/coturn.service and add the line

in the [Service] section:

[Service]
User=turnserver
Group=turnserver
Type=forking
RuntimeDirectory=turnserver
PIDFile=/run/turnserver/turnserver.pid
ExecStart=/usr/bin/turnserver --daemon -c /etc/turnserver.conf --pidfile /run/turnserver/turnserver.pid
ExecStartPost=/bin/sleep 2
Restart=on-failure
InaccessibleDirectories=/home
PrivateTmp=yes
AmbientCapabilities=CAP_NET_BIND_SERVICE

11) Reboot the instance.

12) Verify that the coturn server started correctly and is listening to port 443:

If everything is in order, you should see output indicating coturn started and the general relay threads are active, for example:

Configure the Genymotion instance to use your TURN server

Next, configure the Genymotion instance to forward WebRTC to the STUN/TURN server.

1) From the instance UI, go to the Configuration panel.

2) Fill the TURN & STUN box with your STUN/TURN server URIs, username, and password. The URIs should follow:

where xxx.xxx.xxx.xxx is your server private IP.

3) Click APPLY.

The Genymotion instance now uses your TURN/STUN server on port 443 for WebRTC connections.

For more details and alternate methods with command line tools, please refer to Genymotion Device image user guide.

[MARKDOWN]