NATs have two attributes influence if a connection will succeed between two WebRTC Agents. Those attributes are filtering
and mapping
.
When you send a packet to an address outside your NAT you create a mapping
. A mapping is your IP:Port
and people usually call it your Public IP
. This is the Public IP
that others can send into. A STUN server is just an echo server that responds with your mapping.
The first mapping type is an Address Independent
NAT. This is the one you want. In this configuration you re-use a mapping
everytime you contact an IP outside your NAT. You can give out your mapping
to remote peers and they can send to you.
The second mapping type is Address Dependent
. In this configuration you create a new mapping
for each remote address. This means that the IP/Port you got back from the STUN server can NOT be used by other peers. In this case you may have to use a TURN server.
filtering
controls who is allowed to send in. Some NATs allow anyone to send traffic in. Like mapping
behavior this is called Address Independent
. Other NATs only allow someone to send traffic in that you have attempted to contact, knows as a Address Dependent
NAT.
Check out WebRTC for the Curious's Connecting Chapter I try to explain this in more depth. Pion also has a tool stun-nat-behavior that prints out the details of your NAT like so.
connecting to STUN server: stun.voip.blackberry.com:3478
=> NAT mapping behavior: endpoint independent
=> NAT filtering behavior: address and port dependent