✅ Asterisk NAT Traversal and RTP Flow Handling
In our Asterisk setup, the server is deployed behind a NAT, and the clients (extensions/softphones) are on the public side or NATed networks. Since we do not want to require any client-side configuration (such as STUN, TURN, or ICE), we handle NAT traversal entirely on the server side within the Asterisk pjsip.conf endpoint configuration.
To ensure that media (RTP) flows through Asterisk — allowing us to monitor RTP streams in tools like sngrep — we set:
This forces Asterisk to remain in the media path. When direct_media is set to yes, the RTP stream bypasses Asterisk and flows directly between endpoints. While this allows proper voice communication, the RTP does not pass through Asterisk, hence it is not visible in sngrep or other monitoring tools running on the Asterisk server.
We also observed that without the following NAT-related settings, calls were getting disconnected after approximately 30 seconds. This was due to missing RTP and NAT traversal issues. Adding these settings resolved the disconnection issue:
These settings ensure that Asterisk correctly handles symmetric RTP, rewrites the contact IP to match the source IP of the request, and forces the use of the received port (instead of the one advertised by the client), effectively allowing proper NAT traversal and call stability.