In this article we are going to learn how to setup a TURN server in Google Cloud.

TURN servers are used in NAT traversal and are essential in WebRTC adn VoIP communications

NOTE: Google does not offer a TURN server service.

You can use TURN server Cloud Providers like

Offer 99.999% Uptime and a 50 GB/mo Free Plan

Prerequisites

We need to have the following to setup a TURN server on Google Cloud

  • A Google Cloud Account
  • Basic knowledge of command line and how to create an Google Cloud Instance
  • Basic knowledge of what is an IP address and internet protocols

Step 1: Creating an Google Cloud Instance

In this section we are going to create a google cloud instance

Google Cloud Instance
  1. Login to your Google Compute instance console
  2. On the dashboard create a new VM instance.
  3. Choose a Debian or an Ubuntu operating system
  4. Select the type of VM instance you want according to your TURN server needs. This is important because you need to correctly estimate the CPU, ram and bandwidth requirements based on your estimated TURN server usage
  5. Configure the security group to open necessary ports such as port 22 for ssh and port 3478  port 80 and 443 for CoTURN
  6. Review the settings and then launch the instance
  7. Then ssh into your instance

What is Metered TURN Server?

Metered TURN server is a TURN server as a service that you can use in your WebRTC applications. The Metered TURN server is highly available, reliable and offers both STUN and TURN Capabilities.

The Metered TURN service runs on port 80 and 443 to bypass corporate firewalls, many corporate/enterprise firewall only allow port 80 or 443, it also supports turns + SSL for maximum compatibility.

Metered Global TURN servers

  1. TURN server API: TURN server management with powerful API. You can do things like Add/ Remove credentials via the API, Retrieve Per User / Credentials and User metrics via the API, Enable/ Disable credentials via the API, Retrive Usage data by date via the API.
  2. Global Geo-Location targeting: Automatically directs traffic to the nearest servers, for lowest possible latency and highest quality performance.
  3. Servers in 12 Regions of the world: Toronto, Miami, San Francisco, Amsterdam, London, Frankfurt, Bangalore, Singapore,Sydney
  4. Low Latency: less than 50 ms latency, anywhere across the world.
  5. Cost-Effective: pay-as-you-go pricing with bandwidth and volume discounts available.
  6. Easy Administration: Get usage logs, emails when accounts reach threshold limits, billing records and email and phone support.
  7. Standards Compliant: Conforms to RFCs 5389, 5769, 5780, 5766, 6062, 6156, 5245, 5768, 6336, 6544, 5928 over UDP, TCP, TLS, and DTLS.
  8. Multi‑Tenancy: Create multiple credentials and separate the usage by customer, or different apps. Get Usage logs, billing records and threshold alerts.
  9. Enterprise Reliability: 99.999% Uptime with SLA.
  10. Enterprise Scale: : With no limit on concurrent traffic or total traffic. Metered TURN Servers provide Enterprise Scalability
  11. 50 GB/mo Free: Get 50 GB every month free TURN server usage with the Free Plan
  12. Runs on port 80 and 443
  13. Support TURNS + SSL to allow connections through deep packet inspection firewalls.
  14. Support STUN
  15. Supports both TCP and UDP

You can create an account on Metered website and get 50GB of Free TURN usage every month

Step 2 : Connecting to the instance

  1. from the Google Cloud dashboard select 'Instances' from the left-hand corner and
  2. choose the instance that we created for the purposes of installing CoTURN and select that instance
  3. Follow the instructions to ssh to the server from your local machine

Step 3 : Update the server

Once you are connected to the server through SSH, update and upgrade all the packages by running the below commands

sudo apt update
sudo apt upgrade

Step 4 Installing CoTURN

Once we have upodated all the packages it is time to install the CoTURN  open source project for running TURN service on our google instance

sudo apt install -g coturn

Step 5 Configuring CoTURN

open the configuration file of the CoTURN that you have just installed

cd coturn
sudo nano /etc/turnserver.conf
  • then uncomment the below fields by removing the # before them
listening-port=3478
fingerprint
lt-cred-mech
use-auth-secret
static-auth-secret=YOUR_SECRET_KEY
realm=your-domain.com
total-quota=100
bps-capacity=0
stale-nonce
no-loopback-peers
no-multicast-peers
  • Replace 'YOUR_SECRET_KEY' with a secure key of your own and 'your-domain.com' with your domain and save the file

Enable CoTURN whenever your instance starts or restarts

go to this file

sudo nano /etc/default/coturn

and uncomment TURNSERVER_ENABLED=1 and save the file

Step 6: Starting the CoTURN server

you can start the CoTURN server by using the following command

sudo systemctl enable coturn

Step 7: Verify the CoTURN server is working

type the below command to verify whether the coturn server is working or not

sudo systemctl status coturn

you can see a message that the coturn server is running

WebRTC Stun Turn Servers | Metered
Add one-to-one or Group Video and Audio Calling to your app or website with Metered Video Call SDK
Metered TURN server

Here is the pricing for Metered TURN server cloud service

Plan NameGrowthBusinessEnterprise
Price99 USD / mo199 USD /mo499 USD / mo
Included TURN Usage150 GB / mo500 GB / mo2 TB / mo
Overage Charges0.4 USD / GB0.2 USD / GB0.1 USD / GB
Email SupportYesyesyes
Uptime99.999%99.999%99.999%

You can sign up for Metered TURN service here:

WebRTC Stun Turn Servers | Metered
Add one-to-one or Group Video and Audio Calling to your app or website with Metered Video Call SDK
Metered TURN server

Bonus: Costs and Considerations involved when running Google TURN Server

Here are some of the consideration when running your own TURN server on google

  1. Bandwidth Requirements
  2. Instance requirements
  3. Maintainence issues
  4. Security
  5. Reliability

1. Bandwidth Requirements

when creating your own TURN server, you need to consider bandwidth requirements.

You can calculate an estimate based on how much you are going to use. For example a video call between two clients requires a 2 Mbps connection approximately

Plus you also need to calculate what is the internet connection speed to your instance, for example if you have 1 GBps speed and if you consume more than this them the instance will be throttled

2. Instance requirements

As TURN servers transport encrypted traffic a good amount of CPU performance is required to run TURN servers

If you choose a small instance with high bandwidth then your CPU will hit 100% and throttle your TURN server

If you choose a large instance then your requirements then you will be leaving CPU performance on the table

3. Maintainence issues

If you are running a TURN server yourself then you need to maintain it as well. Updating dependencies and installing security patches yourself.

This might include some downtime as well and an DevOps engineer to maintain the TURN server

4. Security

TURN servers are prone to DDoS attacks and other types of hacking that is prevalent now-a-days. Google does include free DDoS protection with every instance

5. Reliability

TURN server might go down, or instance might go into a limbo. Google cloud instances does go into limbo sometimes and thus needs to be restarted

One of the ways to mitigating this is running multiple instances but that solution increases costs

You might be interested in some of our other articles

Conclusion

Running you own server is a complicated endeavour. A much easier and effective way I think is to go for a TURN server service provider like Metered Video

Here is a run down on all the different TURN server along with their associated benefits and costs