0Pricing
Real-Time Streaming Systems (WebRTC + Live Data) · Aula

Implantando e Protegendo seu Próprio Servidor TURN

Aprenda a hospedar seu próprio servidor TURN com coturn, configurar credenciais com segurança usando tokens limitados por tempo e decidir entre hospedar você mesmo ou usar serviços TURN gerenciados.

Implantando e Protegendo seu Próprio Servidor TURN é uma aula grátis de Real-Time Streaming Systems (WebRTC + Live Data) no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Real-Time Streaming Systems (WebRTC + Live Data), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Real-Time Streaming Systems (WebRTC + Live Data) inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

From Theory to Operation

You understand NAT challenges, STUN, and what TURN does. Now you will actually run a TURN server, secure it, and connect WebRTC to it. The most common open-source choice is coturn.

Why Self-Host TURN

Public STUN is free, but TURN relays media and consumes bandwidth, so it is rarely free. Running your own TURN server gives you control over capacity, cost, and privacy.

Installing coturn

On a Linux server you install coturn from the package manager. It runs as a background service.

sudo apt-get update
sudo apt-get install -y coturn
sudo systemctl enable coturn

Basic Configuration

coturn reads /etc/turnserver.conf. A minimal config sets the realm and listening ports.

listening-port=3478
tls-listening-port=5349
realm=turn.example.com
fingerprint

The Credential Problem

TURN requires authentication or anyone could relay traffic through your server at your expense. Hardcoding a static username and password is risky because clients can leak them.

Time-Limited Credentials

The secure approach is the REST/ephemeral credential mechanism. Your server generates short-lived usernames and passwords derived from a shared secret, so leaked credentials expire quickly.

use-auth-secret
static-auth-secret=your_long_shared_secret

Generating a Credential

Your backend creates a username as an expiry timestamp and signs it with HMAC-SHA1 using the shared secret. The signature becomes the password.

const crypto = require('crypto');
function turnCredential(secret, ttl) {
  const username = String(Math.floor(Date.now() / 1000) + ttl);
  const hmac = crypto.createHmac('sha1', secret);
  hmac.update(username);
  const password = hmac.digest('base64');
  return { username, password };
}

Wiring It Into WebRTC

Pass the TURN URL and ephemeral credentials into the peer connection's ICE server list. WebRTC uses them when direct paths fail.

const pc = new RTCPeerConnection({
  iceServers: [{
    urls: 'turn:turn.example.com:3478',
    username: cred.username,
    credential: cred.password
  }]
});

Use TLS and TCP Fallback

Some restrictive networks block UDP entirely. Offer turns: over TCP on port 443 so media can tunnel through firewalls that only allow HTTPS traffic.

// add a TLS/TCP TURN entry alongside the UDP one
urls: 'turns:turn.example.com:443?transport=tcp'

Self-Host vs Managed

Self-hosting coturn is cheaper at scale but means you handle uptime, bandwidth, and security. Managed TURN providers cost more per GB but remove operational burden. Pick based on your team and traffic.

Operating Responsibly

Monitor bandwidth, rotate the shared secret periodically, restrict relay to authenticated users, and place the server geographically near your users to minimize latency. A well-run TURN server is the safety net that makes calls connect everywhere.

Quick Check

Test your understanding of TURN deployment.

Recap

You learned to deploy and secure TURN:

  • Install and configure coturn with a realm and ports
  • Use use-auth-secret with HMAC-based ephemeral credentials
  • Wire credentials into the ICE server list
  • Offer TLS/TCP on 443 for restrictive networks
  • Weigh self-hosting against managed services

A secure TURN server ensures calls connect even behind tough NATs.

Perguntas Frequentes

A aula “Implantando e Protegendo seu Próprio Servidor TURN” é grátis?

Sim — o texto completo de “Implantando e Protegendo seu Próprio Servidor TURN” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Real-Time Streaming Systems (WebRTC + Live Data), atualize para CoddyKit PRO. O curso de Real-Time Streaming Systems (WebRTC + Live Data) inclui 4 aulas no total.

O que vou aprender em “Implantando e Protegendo seu Próprio Servidor TURN”?

Aprenda a hospedar seu próprio servidor TURN com coturn, configurar credenciais com segurança usando tokens limitados por tempo e decidir entre hospedar você mesmo ou usar serviços TURN gerenciados. Você pratica Real-Time Streaming Systems (WebRTC + Live Data) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Real-Time Streaming Systems (WebRTC + Live Data)?

Nenhuma experiência prévia é necessária. Real-Time Streaming Systems (WebRTC + Live Data) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Implantando e Protegendo seu Próprio Servidor TURN”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Real-Time Streaming Systems (WebRTC + Live Data)?

Sim. Cada aula de Real-Time Streaming Systems (WebRTC + Live Data) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Desafios de NAT e firewalls
  2. Funcionamento dos servidores STUN explicado
  3. Servidor TURN para conexões retransmitidas
  4. Implantando e Protegendo seu Próprio Servidor TURN
← Voltar para Real-Time Streaming Systems (WebRTC + Live Data)