Skip to main content

Overview

ICE (Interactive Connectivity Establishment) is the mechanism WebRTC uses to establish peer-to-peer connections through NATs and firewalls. Proper ICE configuration is critical for reliable connectivity across different network environments.
Most ICE configuration is done through the SettingEngine. This guide focuses specifically on ICE-related settings.

ICE Servers

ICE servers (STUN/TURN) help discover public IPs and relay traffic when direct connection fails.

Basic Configuration

ice-servers.go
From configuration.go:14-59.

Multiple STUN Servers

multiple-stun.go

TURN Server Configuration

TURN servers relay traffic when direct connection and STUN fail:
turn-server.go
From iceserver.go:16-75.

TURN over TLS

turn-tls.go

Multiple Protocols

multi-protocol.go

ICE Transport Policy

Control which ICE candidates are used:
transport-policy.go
Using ICETransportPolicyRelay requires a TURN server and will fail if none is available.

Network Types

Control which network types are used for ICE candidates:
network-types.go
From settingengine.go:286-290.

ICE Timeouts

Configure connection timeouts and keepalive:
timeouts.go

Timeout Details

1

Disconnected Timeout (default: 5s)

How long without network activity before ICE considers the connection disconnected. The connection can recover from this state.
2

Failed Timeout (default: 25s)

How long after disconnected before ICE considers the connection failed. Recovery is unlikely after this.
3

Keepalive Interval (default: 2s)

How often to send keepalive packets when no media is flowing. Prevents NAT bindings from timing out.
From settingengine.go:218-237.

Candidate Acceptance Timeouts

acceptance-timeouts.go
From settingengine.go:239-257.

Port Range

Limit the UDP port range used for ICE:
port-range.go
Limiting the port range is useful for firewall configurations. Make sure the range is large enough for your use case.
From settingengine.go:264-279.

Single Port (UDPMux)

Serve all WebRTC traffic on a single UDP port:
udp-mux.go
See full example at examples/ice-single-port/main.go.
UDPMux is extremely useful for servers that need predictable port usage for firewall rules.

ICE-TCP

Enable ICE over TCP:
ice-tcp.go
See full example at examples/ice-tcp/main.go.
ICE-TCP is useful when UDP is blocked but is generally slower than UDP.

Network Interface Filtering

Control which network interfaces are used:
interface-filter.go
From settingengine.go:292-298.

IP Address Filtering

Filter which IP addresses are used:
ip-filter.go
From settingengine.go:300-306.

NAT 1:1 Mapping

Configure external IP addresses for NAT environments:
nat-mapping.go
SetNAT1To1IPs is deprecated. Use SetICEAddressRewriteRules for more control.
address-rewrite.go
From settingengine.go:345-368.

ICE Lite

Enable ICE Lite mode (for servers):
ice-lite.go
ICE Lite is used when the endpoint has a public IP and doesn’t need to perform full ICE. Typically used on servers.
From settingengine.go:281-284.

mDNS Configuration

Configure mDNS for local network discovery:
mdns.go
From settingengine.go:405-416.
Only use custom mDNS hostnames for single PeerConnection. Multiple PeerConnections with the same hostname will cause undefined behavior.

Static ICE Credentials

Set static ICE username and password:
static-credentials.go
Static credentials are useful for signalless WebRTC where peers have pre-configured connection parameters.
From settingengine.go:418-425.

ICE Binding Requests

Limit the number of ICE binding requests:
binding-requests.go
From settingengine.go:485-489.

Loopback Candidates

Include loopback interface in candidates:
loopback.go
From settingengine.go:370-374.

Complete Example

complete-ice.go

Debugging ICE Issues

1

Enable ICE Logging

Use custom logging to see ICE candidate gathering and connectivity checks.
2

Monitor Connection States

Track ICE connection state changes:
3

Log ICE Candidates

See what candidates are gathered:
4

Test STUN/TURN Servers

Verify your STUN/TURN servers are reachable and properly configured.

SettingEngine

Complete SettingEngine reference

Custom Logging

Debug ICE with custom logging