Setting up a STUN/TURN Server in Azure
Overview
When deploying Unreal Pixel Streaming, some of your clients might be on networks that have settings that prevent a successful WebRTC connection. In these cases, Epic suggests using a STUN server, or a TURN server. More information can be found in the Epic Unreal Pixel Streaming documentation.
Setting up the machine
The walkthrough assumes a deployed Ubuntu 18.04 machine in Azure. If you are looking how to deploy a Linux VM in Azure, have a look at this quickstart on the Microsoft Docs site.
Setting up the STUN/TURN Server
Coturn is an open-source STUN/TURN Server project, with many configuration options. To deploy Coturn, please have a look at this blogpost on OurCodeWorld that perfectly describes the process.
DNS Option
In the walkthrough DNS is configured. In case you need a domain name, you can register one in Azure, and use Azure DNS to host the DNS for your domain.
SSL Certificate Option
There are many ways to obtain an SSL certificate. An easy and cheap way is to use LetsEncrypt. Setting up LetsEncrypt for a server that uses port 80 for a webserver is extremely easy. Since the Coturn server does use port 80, a manual request with a DNS challenge is easiest:
- Install CertBot
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
- Request the certificate
sudo certbot -d *.yourdomain.com --manual --preferred-challenges dns certonly
Follow the steps certbot is guiding you through.
- Update the Coturn configuration to point to your newly created certificates and restart the service:
sudo nano /etc/turnserver.conf
sudo systemctl restart coturn
Opening network ports
Depending on what you configure, you’ll need to open some network ports for the STUN and/or TURN Server to be reachable. For TLS the default port is 5349, and it needs to be open for UDP and TCP. To do this, follow these steps:
- Go to the Azure Portal at https://portal.azure.com
- Go to the Resource Group that contains your STUN/TURN Server deployment
- Select the Network Security Group
- Click Inbound security rules on the left
- Click + Add on the top of the new blade
- Use the following settings:
- Source: Any
- Source port ranges: *
- Destination: Any
- Service: Custom
- Destination port ranges: 5349
- Protocol: Any
- Action: Allow
- Priority: Lower than 65000
- Name: A descriptive name like Stun-Turn-Port
- Click Add to save the rule
After this your STUN and TURN Server is up and running.