DEV Community

Cover image for STUN,TURN and ICE servers - NAT traversal for WebRTC
Omer Sayem
Omer Sayem

Posted on

STUN,TURN and ICE servers - NAT traversal for WebRTC

Because of the absence of IP address space and the need to keep a hidden system's engineering obscure to outside clients, NATs are utilized. These decipher inside private IP delivers to outside open IP addresses.Approaching traffic into the private system is steered through an open location restricting that happens on the NAT gadget. This coupling is made when an inside machine with a private IP address attempts to get to an open IP address (through the NAT).

VoIP and WebRTC requires to pass media packets like video/audio into two peers which needs to pass external packets into internal networks.For these situation webRTC needs mechanisms like STUN , TURN and ICE server. Whats these do ! going forward.

We know webRTC is p2p connection. So in a private network connection between two client don't need any server.

Alt Text

But when a client A from private network need to connect to Client B who is in a public network , it gets block by NAT firewall and it doesn't know the public ip to connect. TO rescue first see how STUN server do.

Client query the STUN server for his public ip and STUN provides public IP.With this provided public IP Client A can connect to Client B .

Alt Text

SO, problem solved! Not yet ! STUN servers doesn't provide same public IP if the client call in different servers. so the bindings is not unique. Thats a problem ! another life-saving mechanism is TURN server.

TURN server actually don't provide any Public IP , its relays media . it takes media from client A and provide to client B , without looking the packet. Compare to STUN server it's very much operation expensive. To reduce cost both STUN and TURN can be use in case of STUN server failure .

Alt Text

These STUN and TURN servers has dawbacks.STUN is backend inexpensive but doesn't work always . TURN server is reliable but backend expensive .Finally ICE servers comes handy !

What ICE server do , its holds everything , its a collector . It collects local IP , STUN server's reflexive IP , TURN sever's relay media addess and stored in a remore peer via Session Description Protocol (SDP) . WebRTC client receives the ICE address of itself and the peers and send media through connectivity checking .

Alt Text

Thats all upto ICE server which is used in most of the WebRTC implimentation . Good news there more optimized WebRTC Natting named ICE Trickle . Maybe talks about it some other day . Happy learning !

Latest comments (0)