Prompt

How do I set up TURN and STUN for video calls?

Technology / API Platforms1 observationLast seen Nov 2, 2026

Latest observation

Nov 2, 2026OpenAI APIWeb search: off

To set up STUN and TURN for video calls, you’re usually configuring WebRTC so peers can find each other and relay media when direct connectivity fails.

Quick concept

  • STUN: helps clients discover their public IP/port.
  • TURN: relays media when direct peer-to-peer connection is blocked by NAT/firewalls.
  • In production, you typically need both:
    • STUN for direct connections when possible
    • TURN as a fallback for reliability

1) Choose a TURN/STUN server

You can:

  • Use a managed provider
  • Self-host with coturn (most common open-source option)

If you want full control, coturn is a good choice.


2) Install coturn (example on Ubuntu/Debian)

sudo apt update
sudo apt install coturn

Enable the service:

sudo nano /etc/default/coturn

Set:

TURNSERVER_ENABLED=1

3) Basic coturn config

Edit:

sudo nano /etc/turnserver.conf

Example config:

listening-port=3478
tls-listening-port=5349

fingerprint
lt-cred-mech

realm=yourdomain.com
server-name=yourdomain.com

use-auth-secret
static-auth-secret=YOUR_LONG_RANDOM_SECRET

total-quota=100
bps-capacity=0

no-multicast-peers
no-loopback-peers

# Recommended for production behind NAT:
external-ip=YOUR_PUBLIC_IP

Notes

  • realm should match your domain
  • static-auth-secret is used for temporary credentials
  • external-ip is important if the server is behind NAT
  • You’ll usually need both UDP and TCP open, and TLS if possible

4) Open firewall ports

At minimum:

  • 3478/udp and 3478/tcp for TURN/STUN
  • 5349/tcp for TURN over TLS
  • A relay port range for media relaying

Example with ufw:

sudo ufw allow 3478/udp
sudo ufw allow 3478/tcp
sudo ufw allow 5349/tcp
sudo ufw allow 49152:65535/udp

You can restrict the relay range in coturn:

min-port=49152
max-port=65535

Then only open that range.


5) Start/restart coturn

sudo systemctl restart coturn
sudo systemctl enable coturn

Check status:

sudo systemctl status coturn

6) Configure your WebRTC app

In your client code, pass ICE servers to RTCPeerConnection.

Example:

const pc = new RTCPeerConnection({
  iceServers: [
    { urls: 'stun:yourdomain.com:3478' },
    {
      urls: 'turn:yourdomain.com:3478',
      username: 'user',
      credential: 'pass'
    },
    {
      urls: 'turns:yourdomain.com:5349',
      username: 'user',
      credential: 'pass'
    }
  ]
});

7) Use TURN authentication properly

For production, don’t hardcode static usernames/passwords in the client.

Better approach:

  • Your backend generates short-lived TURN credentials
  • The client fetches them just before starting a call

If using use-auth-secret, generate ephemeral credentials using the shared secret.

Typical pattern:

  • username = expiration timestamp
  • password = HMAC-SHA1 of username using static-auth-secret

8) Test connectivity

Useful checks:

  • Verify STUN works: public IP discovery
  • Verify TURN relay works when direct path fails
  • Use browser WebRTC stats or tools like:
    • chrome://webrtc-internals
    • coturn logs

You can also test with:

  • trickle-ice WebRTC ICE tester
  • turnutils_uclient from coturn

9) Common pitfalls

  • Firewall not opening relay ports
  • Wrong public IP / NAT config
  • Not using TLS on restrictive networks
  • Using static credentials in client code
  • Forgetting TCP/TLS fallback
  • Binding TURN only to localhost
  • DNS not pointing to server correctly

10) Recommended production setup

A practical setup looks like this:

  • stun:yourdomain.com:3478
  • turn:yourdomain.com:3478?transport=udp
  • turn:yourdomain.com:3478?transport=tcp
  • turns:yourdomain.com:5349?transport=tcp

And:

  • coturn with long-term credentials or auth-secret
  • TLS certificate from Let’s Encrypt
  • relay port range restricted and firewall-opened
  • backend-generated ephemeral TURN creds

If you want, I can give you:

  1. a working coturn config file,
  2. a Node.js backend to generate TURN credentials, or
  3. a full WebRTC example with STUN/TURN setup.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.