Howwise RSS
VoIP & Phone Systems8 min read

Asterisk One Way Audio NAT: Diagnose and Fix PJSIP Settings

Short answer

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.

Key takeaways
  • 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.

TopologyMain problemSettings that matter
PBX on LAN, public SIP trunkAsterisk puts a private IP in the SDP sent to the providerexternal_media_address, external_signaling_address, local_net, forwarded RTP range
Remote phones behind their own NATPhone Contact and SDP hold private IPsrtp_symmetric, force_rport, rewrite_contact, direct_media=no, qualify_frequency
BothBoth of the above, plus LAN phones must keep private addressesAll of the above and complete local_net
WebRTC clientsICE candidates, DTLS-SRTPicesupport, 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/12
Warning: If the public IP is dynamic, external_media_address does not accept a changing value by itself. It can take a hostname that Asterisk resolves when the transport loads, so use a dynamic DNS name and reload (pjsip reload) after an ISP change, or use a static IP.

Which 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.

OptionWhat it doesWhen needed
direct_media=noKeeps Asterisk in the RTP pathAlways with NAT, trunks and remote phones
rtp_symmetric=yesSends RTP to the address and port RTP was received from (comedia latching)Remote phones, trunks that advertise private IPs
force_rport=yesReplies to the real source port instead of the Via rport-less valuePhones behind NAT
rewrite_contact=yesReplaces the Contact with the real source IP and port seen on REGISTERRegistered phones behind NAT
qualify_frequency=25OPTIONS keepalive on the AOR that refreshes the NAT mappingRegistered 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:19302
Tip: NAT mappings expire. A registered phone that goes quiet for longer than the router's UDP timeout loses inbound calls, so keep qualify_frequency between 20 and 30 seconds.

How 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.

  1. Run pjsip set logger on and place a test call.
  2. Find the INVITE or 200 OK that Asterisk sent and read c= and m=audio.
  3. Run rtp set debug on and look for both Sent RTP and Got RTP.
  4. Use sngrep for a live call flow with SDP details.
  5. 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 101
Warning: Debug logging on a busy production PBX is heavy and can expose phone numbers and credentials in the SIP log. Test on a quiet system and turn it off when done.

How 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 seeMeaningFix
No RTP leaving the PBXAsterisk is not sending, often no media negotiated or codec mismatchCheck the SDP answer, codecs, and endpoint settings
RTP leaves LAN but not seen on WANRouter or firewall drops itForward the RTP range, disable SIP ALG, check rules
RTP leaves WAN but nothing returnsFar end sends elsewhere or filtersCheck SDP c= and m= from your side, provider firewall, rtp_symmetric
RTP arrives at the wrong IPPrivate IP in SDP or wrong external_media_addressFix local_net and external_media_address
RTP arrives but no Got RTP in AsteriskFirewall blocks the port or the range does not matchAlign 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 available
Tip: Test from both sides. If you only test from one phone, you cannot tell which direction fails, and you may blame the trunk when the extension is at fault.

What 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.

SymptomLikely cause
Silence on outbound onlyProvider cannot reach your RTP, or private IP in your SDP
Silence on inbound onlyInbound RTP port blocked or wrong forward
Audio drops after about 30 sACK not reaching the PBX, SIP ALG, or NAT timeout
Audio on some calls onlyRTP range mismatch or SIP ALG
Silence on every call, no Sent RTPNot NAT: codec mismatch or missing SDP answer
  1. Call internal to internal and confirm audio both ways.
  2. Call internal to external and confirm both ways.
  3. Call external to internal and confirm both ways.
  4. Put the call on hold, resume it, and confirm audio.
  5. Transfer the call and check the SDP in the re-INVITE with pjsip set logger on.
  6. 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.

Related topics:asteriskpjsipnatrtpfreepbx