WebRTC TURN Relay: NAT Traversal, Credentials, Firewall Rules, and Pricing
How managed TURN relay works with WebRTC ICE, STUN, credential APIs, custom domains, billing, limits, and corporate firewall allowlists.
This page summarises Cloudflare Realtime documentation on Cloudflare Realtime TURN: a managed relay for WebRTC when NATs or firewalls block a direct peer path. It also touches MoQ (Media over QUIC) only where Cloudflare positions it alongside TURN for teleoperation-style workloads.
TURN and STUN in WebRTC: when you need a relay
Section titled “TURN and STUN in WebRTC: when you need a relay”TURN (Traversal Using Relays around NAT) helps applications traverse NATs and firewalls so peers can talk when a direct path fails. It extends STUN, which discovers addresses but does not relay media.
TURN (Traversal Using Relays around NAT) is a protocol that assists in traversing Network Address Translators (NATs) or firewalls in order to facilitate peer-to-peer communications. It is an extension of the STUN (Session Traversal Utilities for NAT) protocol and is defined in RFC 8656.
— Cloudflare, What is TURN?
WebRTC finds a working path with Interactive Connectivity Establishment (ICE). You configure ICE for the networks your endpoints support. Cloudflare’s public STUN server is stun.cloudflare.com:3478; TURN relays when the network requires it.
A TURN server relays traffic when a NAT or firewall prevents two WebRTC endpoints from connecting directly. If a direct connection works, TURN stays out of the path.
— Cloudflare, Cloudflare TURN
WebRTC uses Interactive Connectivity Establishment (ICE) to find a working network path. Configure it for the networks your endpoints support. Cloudflare’s public STUN server is stun.cloudflare.com:3478. STUN helps discover network addresses. TURN can relay traffic when an endpoint’s network requires it.
— Cloudflare, Network connectivity
Install connection-state handlers and time out connection attempts so failures surface clearly. After setting a local description, gather ICE candidates before sending pc.localDescription to your backend.
How a TURN allocation works
Section titled “How a TURN allocation works”A TURN client (your app or browser WebRTC stack) asks the TURN server for an allocation: a relayed transport address on the public internet. Peers send data to that address; the server forwards it to the client, and the client sends outbound traffic through the same relay.
When a TURN server creates an allocation, the TURN server reserves an IP and a port unique to that client.
— Cloudflare, Key concepts to know when understanding TURN
There is no fixed maximum allocation lifetime in Cloudflare’s model: the client must keep the allocation alive with periodic Refresh requests authenticated with valid credentials. Credential lifetime is capped at 48 hours; longer sessions need new credentials before expiry.
TURN versus SFU: which topology fits your app
Section titled “TURN versus SFU: which topology fits your app”TURN and an SFU solve different problems and are often combined.
Use TURN when you have a point-to-point connection between two peers and you need to traverse NATs or firewalls. Both peers exchange media directly through the relay without any server-side media processing.
Use SFU when you need fan-out, meaning one publisher sending media to many subscribers, or many publishers exchanging media in a group.
— Cloudflare, What is the difference between Cloudflare Realtime TURN with a enterprise plan vs self-serve (pay with your credit card) plans? (section: When should I use TURN versus SFU?)
For one-to-one links (for example operator-to-device teleoperation), TURN alone is usually enough. Fan-out to many viewers needs an SFU.
Cloudflare states TURN and Realtime SFU share the same global fleet and data path, so the choice should follow topology, not assumed latency penalties.
| Goal | Typical choice |
|---|---|
| Two peers behind strict NAT/firewall | TURN relay |
| One publisher, many subscribers | SFU (+ TURN where ICE needs relay) |
| Group call with selective tracks | SFU |
RealtimeKit can configure Cloudflare TURN for you; the Realtime SFU includes the same TURN access. You can also generate TURN credentials for your own SFU or pure peer-to-peer app.
Cloudflare Realtime TURN: addresses, ports, and anycast
Section titled “Cloudflare Realtime TURN: addresses, ports, and anycast”Cloudflare TURN relays WebRTC when direct connectivity fails. The service uses Anycast, so you do not deploy regional TURN pools or load balancers yourself.
Cloudflare TURN uses Anycast ↗︎, so you do not have to deploy regional TURN servers or load balancers.
— Cloudflare, How does TURN fit into WebRTC?
| Protocol | Primary address | Primary port | Alternate port |
|---|---|---|---|
| STUN over UDP | stun.cloudflare.com |
3478/udp |
— (see Allow media traffic for RealtimeKit: 53/udp) |
| TURN over UDP | turn.cloudflare.com |
3478/udp |
443/udp |
| TURN over TCP | turn.cloudflare.com |
3478/tcp |
80/tcp |
| TURN over TLS | turn.cloudflare.com |
5349/tcp |
443/tcp |
The host at turn.cloudflare.com also answers STUN binding requests, so one hostname can cover STUN and TURN in many setups.
Custom TURN domains (UDP and TCP only)
Section titled “Custom TURN domains (UDP and TCP only)”Custom domains work for UDP and TCP TURN/STUN, not for TURN over TLS. Setup is a CNAME to turn.cloudflare.com—never an A/AAAA copy of Cloudflare’s IPs.
| Protocol | Custom domains | Primary port | Alternate port |
|---|---|---|---|
| STUN over UDP | Yes | 3478/udp |
— |
| TURN over UDP | Yes | 3478/udp |
443/udp |
| TURN over TCP | Yes | 3478/tcp |
80/tcp |
| TURN over TLS | No | 5349/tcp |
443/tcp |
Do not resolve the address of turn.cloudflare.com or stun.cloudflare.com or use an IP address as the value you input to your DNS record. Only CNAME records are supported.
— Cloudflare, Custom TURN domains
If the zone uses Cloudflare authoritative DNS, set the CNAME to DNS only (grey cloud). Custom hostnames add no extra TURN charge.
TURN keys and short-lived credentials
Section titled “TURN keys and short-lived credentials”TURN keys are long-lived server-side secrets. They are not sent to turn.cloudflare.com as client credentials. Your backend mints short-lived username/password pairs for each session or user.
Cloudflare will issue TURN keys, but these keys cannot be used as credentials with turn.cloudflare.com. To use TURN, you need to create credentials with a expiring TTL value.
— Cloudflare, Generate Credentials
-
Create a TURN key in the Dashboard or API (keep the key server-side).
-
Call the credentials endpoint from your backend:
curl https://rtc.live.cloudflare.com/v1/turn/keys/$TURN_KEY_ID/credentials/generate-ice-servers \--header "Authorization: Bearer $TURN_KEY_API_TOKEN" \--header "Content-Type: application/json" \--data '{"ttl": 86400}' -
Pass the returned
iceServersobject intonew RTCPeerConnection({ iceServers: [...] }). -
Set
ttllonger than the longest expected session; refresh withRTCPeerConnection.setConfiguration()during long calls if needed. -
Revoke compromised credentials early via
POST .../credentials/$USERNAME/revoke(Revoke credentials).
Maximum credential expiry is 48 hours. For scale, separate environments (test, staging, production) with different TURN keys—you can create up to 1,000 keys per account. Optional customIdentifier on credential generation helps aggregate usage and spot abuse via analytics (Replacing existing TURN servers).
The JSON shape is similar to the expired TURN REST draft but omits TTL in the response; adapt on your server if clients require that format (TURN FAQ).
Pricing, free tier, and what gets metered
Section titled “Pricing, free tier, and what gets metered”Standalone TURN bills egress from Cloudflare to the TURN client (per RFC 8656 relay model), including TURN overhead after authentication. STUN at stun.cloudflare.com is free and unlimited.
Cloudflare TURN pricing is based on the data sent from the Cloudflare edge to the TURN client, as described in RFC 8656 Figure 1. This means data sent from the TURN server to the TURN client and captures all data, including TURN overhead, following successful authentication.
— Cloudflare, What is Cloudflare Realtime TURN pricing?
Published rate: $0.05 per GB egress, with 1,000 GB/month free shared across Realtime SFU and TURN (Pricing). Traffic between Realtime TURN and Realtime SFU or Cloudflare Stream (WHIP/WHEP) is not double-charged.
When TURN is used together with the Realtime SFU, Cloudflare documents TURN as available without separate TURN charges in that combined path (TURN Service). TURN usage analytics typically appear within about 30 seconds (TURN FAQ).
Security, privacy, and compliance notes
Section titled “Security, privacy, and compliance notes”With WebRTC, media is encrypted with DTLS before it reaches TURN; Cloudflare relays ciphertext and does not decrypt application media (TURN FAQ). TURN over TLS supports FIPS 140-3 when encryption at the TURN layer is used; end-to-end media protection still depends on WebRTC (or your app layer).
TURN alone does not define media encryption beyond wrapper protocols such as TLS; WebRTC encrypts at the WebRTC level when TURN carries WebRTC.
Enterprise versus self-serve plans do not change TURN feature or performance levels; enterprise adds support, pricing, and SLA arrangements (TURN FAQ).
Protocol support and operational limits
Section titled “Protocol support and operational limits”Client-to-server TURN over UDP, TCP, and TLS is supported per the TURN RFC matrix. Notable unsupported items for integrators:
- TCP relaying (RFC 6062) and IPv6 relay addresses (RFC 6156)—relay addresses are IPv4 only;
REQUESTED-ADDRESS-FAMILYis not honored (TURN FAQ). - DTLS as a TURN transport, TURN-bis dual allocation, and several draft extensions marked “No” on the matrix.
Per-allocation rate limits (each TURN user, not account-wide) include roughly: more than 5 new peer IPs per second, on the order of 5–10 kpps, and 50–100 Mbps data rates; exceeding limits causes packet drops (Limits). There is no special MTU cap documented for the service.
CreatePermission / ChannelBind to private ranges or certain BYOIP targets are denied unless arranged with Cloudflare (TURN FAQ).
Allocations can be disrupted by maintenance or routing shifts; ICE restart on the client is strongly recommended (TURN FAQ).
When both peers use Cloudflare Realtime TURN, traffic between edges may use the Cloudflare backbone, improving loss behavior versus one peer on the public internet only (TURN FAQ).
Corporate firewalls: domains, ports, and IP allowlists
Section titled “Corporate firewalls: domains, ports, and IP allowlists”For application firewalls, allow STUN/TURN to stun.cloudflare.com and turn.cloudflare.com on primary and alternate ports where possible (Allow media traffic). Do not rely only on 53/udp for RealtimeKit paths.
If policy requires IP allowlisting, Cloudflare publishes a short list (IPv4 and IPv6):
2a06:98c1:3200::1/1282606:4700:48::1/128141.101.90.1/32162.159.207.1/32
IPs may change; without an enterprise static-IP arrangement, monitor DNS for turn.cloudflare.com (A/AAAA) and update within 14 days of changes. Hardcoding IPs requires the same monitoring plus DNS failover (TURN FAQ).
MoQ and robotics: when to look beyond TURN
Section titled “MoQ and robotics: when to look beyond TURN”For point-to-point teleoperation, WebRTC plus TURN is the documented fit (TURN FAQ). When you control both ends and want explicit reliability control, Cloudflare also points teams at Media over QUIC (MoQ)—an IETF effort for media over QUIC with semantics beyond generic HTTP streaming (Background, Media over QUIC at Cloudflare). MoQ relays, draft versions, and public test streams are separate from day-to-day TURN setup; evaluate MoQ when TURN/WebRTC semantics are not enough, not as a replacement for basic NAT traversal.
Common mistakes
Section titled “Common mistakes”- Putting TURN keys in the browser instead of minting short-lived credentials on the backend.
- Using A records instead of CNAME for custom TURN hostnames, or proxying the CNAME through the orange cloud when authoritative DNS is on Cloudflare.
- Expecting IPv6 relay or TCP peer relay per RFC extensions Cloudflare does not implement.
- Allowlisting only
53/udpor ignoring alternate ports that ICE may try. - Assuming TURN encrypts media—with WebRTC, DTLS does; TURN is a relay.
- Skipping ICE restart handling when allocations drop during long sessions.
- Setting credential TTL shorter than the call length without refresh or
setConfiguration().
How to check this on your site
Section titled “How to check this on your site”-
From a restricted network, open a WebRTC test page or your app with
iceServersfrom Generate Credentials and confirm whether the selected candidate pair usesrelay(TURN) or host/srflx when you expect relay. -
Verify DNS for custom TURN hostnames: the record must CNAME to
turn.cloudflare.comand match Custom TURN domains (grey cloud if the zone is on Cloudflare DNS). -
On a corporate network, confirm outbound UDP/TCP to
turn.cloudflare.comandstun.cloudflare.comon the ports in Service address and ports (and Network allowlist if you use RealtimeKit). -
After traffic flows, check Realtime TURN usage in Cloudflare analytics (updates in roughly 30 seconds per TURN FAQ) and reconcile with the 1,000 GB shared free tier in Pricing.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.