Asterisk One Way Audio NAT: Diagnose and Fix PJSIP Settings
Asterisk one way audio NAT problems occur because SIP and SDP advertise private IPs, so the far end sends RTP to an unreachable address. Fix it with external_media_address, local_net, rtp_symmetric, direct_media=no and a forwarded RTP range.
- Set external_signaling_address, external_media_address and one local_net line per internal subnet on the PJSIP transport.
- Use direct_media=no, rtp_symmetric=yes, force_rport=yes and rewrite_contact=yes on endpoints behind NAT.
- The RTP range in rtp.conf must match the firewall forward exactly, and SIP ALG should be off.
- Compare the SDP c= and m=audio values with the real RTP source and destination in a capture to see which hop drops audio.
- Retest after hold, resume and transfer, because a re-INVITE can bring back a private address or direct media.
Why does NAT cause one way audio in Asterisk?
Asterisk one way audio NAT faults start with how SIP works. SIP (UDP 5060 by default) sets up the call, while the SDP body inside it tells the far end where to send RTP: the c= line holds the IP and the m=audio line holds the port. If Asterisk writes its private address, such as 192.168.1.10, into that SDP, the far end sends audio to an address that does not exist on the internet.
The same applies to the Via and Contact headers. A phone behind NAT that advertises a private Contact makes Asterisk send in-dialog requests and RTP to a dead address. Your outbound audio can still flow, because the NAT router lets replies through for flows the inside host opened. That is why the symptom is one direction only.
Typical patterns: the caller hears nothing while the callee is fine, or audio appears only after several seconds. The delay happens when symmetric RTP (comedia) finally learns the real source address from the first packets the far end sends.
Pick your topology first, because each needs different settings. Many sites have more than one at once.
Remember the rule behind all of them: Asterisk must advertise its public address to peers outside the LAN and its real address to peers inside it. local_net is the list that makes that decision.
| Topology | Main problem | Settings that matter |
|---|---|---|
| PBX on LAN, public SIP trunk | Asterisk puts a private IP in the SDP sent to the provider | external_media_address, external_signaling_address, local_net, forwarded RTP range |
| Remote phones behind their own NAT | Phone Contact and SDP hold private IPs | rtp_symmetric, force_rport, rewrite_contact, direct_media=no, qualify_frequency |
| Both | Both of the above, plus LAN phones must keep private addresses | All of the above and complete local_net |
| WebRTC clients | ICE candidates, DTLS-SRTP | icesupport, stun_server, media_encryption=dtls |
What PJSIP transport settings fix it?
Set the public addresses on the transport. local_net is what tells Asterisk not to rewrite addresses for LAN peers. Without it, Asterisk treats every peer as external and puts the public IP into SDP sent to your own LAN phones, which then break.
Add one local_net line per internal range, including VPN subnets and any other routed internal networks.
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060
external_signaling_address=203.0.113.10
external_media_address=203.0.113.10
local_net=192.168.0.0/16
local_net=10.8.0.0/24 ; VPN subnet
local_net=172.16.0.0/12Which endpoint and trunk options do I need?
These options go on the endpoint (and the trunk endpoint). Use them for remote phones behind NAT, and direct_media=no everywhere.
direct_media=yes lets Asterisk re-INVITE two endpoints so they exchange RTP directly, bypassing the PBX. That works on one flat LAN, but across NAT each side receives the other's private address, so audio breaks. This is also why transfers can break a working call.
| Option | What it does | When needed |
|---|---|---|
| direct_media=no | Keeps Asterisk in the RTP path | Always with NAT, trunks and remote phones |
| rtp_symmetric=yes | Sends RTP to the address and port RTP was received from (comedia latching) | Remote phones, trunks that advertise private IPs |
| force_rport=yes | Replies to the real source port instead of the Via rport-less value | Phones behind NAT |
| rewrite_contact=yes | Replaces the Contact with the real source IP and port seen on REGISTER | Registered phones behind NAT |
| qualify_frequency=25 | OPTIONS keepalive on the AOR that refreshes the NAT mapping | Registered remote phones |
[1001]
type=endpoint
transport=transport-udp
context=from-internal
disallow=all
allow=ulaw,alaw
direct_media=no
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
aor=1001
[1001]
type=aor
max_contacts=1
qualify_frequency=25 What must the rtp.conf range and router look like?
Asterisk picks RTP ports from the range in rtp.conf. The firewall must forward exactly that UDP range to the PBX. Forwarding only 5060 is not enough, because audio uses different ports, and each call uses an even port for RTP plus the next odd one for RTCP.
Disable SIP ALG on the router. It rewrites SIP headers and SDP using its own view and often corrupts them, which causes audio on only some calls or breakage after re-INVITEs.
Use a static public IP or dynamic DNS, and check that you are not behind CGNAT or double NAT. With CGNAT there is no inbound path, so you need a VPN or a provider that supports symmetric RTP to you.
; /etc/asterisk/rtp.conf
[general]
rtpstart=10000
rtpend=20000
; only for WebRTC or special cases:
icesupport=yes
stun_server=stun.l.google.com:19302How do I diagnose it from the Asterisk CLI?
Start with the SDP Asterisk actually sends. The c= line and the m=audio port must carry the public IP for external peers and the private IP for LAN peers.
Then rtp set debug on shows which direction is missing: lines starting with Sent RTP mean Asterisk transmits, and Got RTP lines mean it receives. Only Sent lines means the far end or the network drops inbound audio.
- Run pjsip set logger on and place a test call.
- Find the INVITE or 200 OK that Asterisk sent and read c= and m=audio.
- Run rtp set debug on and look for both Sent RTP and Got RTP.
- Use sngrep for a live call flow with SDP details.
- Turn debugging off afterwards with rtp set debug off and pjsip set logger off.
asterisk -rvvv
pjsip set logger on
rtp set debug on
pjsip show endpoints
pjsip show transport transport-udp
# before (wrong): Asterisk advertises a private address
c=IN IP4 192.168.1.10
m=audio 12044 RTP/AVP 0 101
# after (correct): public IP, port inside forwarded range
c=IN IP4 203.0.113.10
m=audio 12044 RTP/AVP 0 101How do I prove where the audio stops with a packet capture?
Capture signaling and RTP together, on the PBX and, if possible, on the WAN side too. Open the file in Wireshark, then use Telephony > VoIP Calls > Flow Sequence and Telephony > RTP > RTP Streams. Compare the SDP c= address with the real RTP source and destination.
Capturing both sides shows where packets vanish. If RTP appears on the LAN but not on the WAN, the router is dropping or not translating it. If the WAN shows it leaving with a private IP inside the SDP, the problem is Asterisk. If it leaves correctly and no reply comes, the provider or far end is at fault.
| What you see | Meaning | Fix |
|---|---|---|
| No RTP leaving the PBX | Asterisk is not sending, often no media negotiated or codec mismatch | Check the SDP answer, codecs, and endpoint settings |
| RTP leaves LAN but not seen on WAN | Router or firewall drops it | Forward the RTP range, disable SIP ALG, check rules |
| RTP leaves WAN but nothing returns | Far end sends elsewhere or filters | Check SDP c= and m= from your side, provider firewall, rtp_symmetric |
| RTP arrives at the wrong IP | Private IP in SDP or wrong external_media_address | Fix local_net and external_media_address |
| RTP arrives but no Got RTP in Asterisk | Firewall blocks the port or the range does not match | Align rtp.conf with the firewall forward |
tcpdump -ni any udp port 5060 or portrange 10000-20000 -w nat.pcap
# run the same on the router or a WAN-side mirror if availableWhat are the common mistakes, and how do I verify the fix?
The most frequent mistakes are a missing local_net, so Asterisk rewrites LAN SDP with the public IP; double NAT or CGNAT with no inbound path; a stale external_media_address after an ISP IP change; and a firewall RTP range that differs from rtp.conf.
FreePBX: in Settings > Asterisk SIP Settings > Chan PJSIP, fill External Address and Local Networks. Local Networks are often auto-detected, so confirm they include every subnet. The Chan SIP tab has its own NAT settings. Per extension, set Direct Media, RTP Symmetric, Force rport and Rewrite Contact in the Advanced tab. Click Apply Config after edits, or nothing changes.
After any change, run the checks below. Transfers and hold can trigger a re-INVITE, which can bring back a private address or direct media, so re-read the SDP after those.
| Symptom | Likely cause |
|---|---|
| Silence on outbound only | Provider cannot reach your RTP, or private IP in your SDP |
| Silence on inbound only | Inbound RTP port blocked or wrong forward |
| Audio drops after about 30 s | ACK not reaching the PBX, SIP ALG, or NAT timeout |
| Audio on some calls only | RTP range mismatch or SIP ALG |
| Silence on every call, no Sent RTP | Not NAT: codec mismatch or missing SDP answer |
- Call internal to internal and confirm audio both ways.
- Call internal to external and confirm both ways.
- Call external to internal and confirm both ways.
- Put the call on hold, resume it, and confirm audio.
- Transfer the call and check the SDP in the re-INVITE with pjsip set logger on.
- Confirm that rtp set debug on shows both Sent RTP and Got RTP.
Common questions
Does rtp_symmetric=yes alone fix one way audio?
Often it fixes cases where the far end advertises a private IP, because Asterisk sends back to the address it receives RTP from. It does not help if inbound packets are blocked or if Asterisk itself advertises the wrong address.
Do I need STUN in Asterisk for a PBX with a static IP?
No. With a static public IP, external_media_address and local_net are simpler and more predictable. STUN and ICE matter for WebRTC clients and when the public address is unknown.
Why does audio start only after a few seconds?
Asterisk is waiting to latch onto the first RTP packets from the far end before sending back to the real source. Check that rtp_symmetric is on and that the far end SDP is not advertising an unreachable address.
Can the trunk provider cause one way audio?
Yes, but rule out your side first with a capture. If RTP leaves your WAN with the correct public IP and nothing returns, send the capture and the SDP to the provider.