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
Multiple STUN Servers
multiple-stun.go
TURN Server Configuration
TURN servers relay traffic when direct connection and STUN fail:turn-server.go
TURN over TLS
turn-tls.go
Multiple Protocols
multi-protocol.go
ICE Transport Policy
Control which ICE candidates are used:transport-policy.go
Network Types
Control which network types are used for ICE candidates:network-types.go
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.
Candidate Acceptance Timeouts
acceptance-timeouts.go
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.
Single Port (UDPMux)
Serve all WebRTC traffic on a single UDP port:udp-mux.go
UDPMux is extremely useful for servers that need predictable port usage for firewall rules.
ICE-TCP
Enable ICE over TCP:ice-tcp.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
IP Address Filtering
Filter which IP addresses are used:ip-filter.go
NAT 1:1 Mapping
Configure external IP addresses for NAT environments:nat-mapping.go
Address Rewrite Rules (Recommended)
address-rewrite.go
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.
mDNS Configuration
Configure mDNS for local network discovery:mdns.go
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.
ICE Binding Requests
Limit the number of ICE binding requests:binding-requests.go
Loopback Candidates
Include loopback interface in candidates:loopback.go
Complete Example
Full ICE Configuration
Full ICE Configuration
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.
Related Resources
SettingEngine
Complete SettingEngine reference
Custom Logging
Debug ICE with custom logging