Emergency server help: get in touch

Troubleshoot SIP Calls with sngrep and the Asterisk PJSIP Logger

How to use sngrep and the Asterisk PJSIP logger to capture a failing call, read the SIP ladder, save a pcap, check RTP audio, and find NAT, codec and authentication problems on Asterisk and FreePBX.

Published Updated 10 min read

sngrep is a terminal tool that captures SIP traffic and draws each call as a ladder diagram, which makes most VoIP faults visible in seconds: who sent what, which response failed, which codecs were offered, and which addresses each side asked to receive audio on. This guide covers installing it, capturing and reading a call, saving a capture to share, checking the RTP audio, and the Asterisk logger as an alternative when sngrep is not available.

Short answer: Install sngrep (apt install sngrep, or from EPEL on AlmaLinux and Rocky), run sngrep -d any port 5060, make a test call, select it and press Enter for the ladder. Press F2 to save it as a pcap or text file. If audio is the problem, check the c= and m=audio lines in each SDP: a private address in the PBX’s offer to the provider means one-way audio. (Reviewed November 2026.)

Install sngrep

# Debian / Ubuntu
apt install sngrep

# AlmaLinux / Rocky 8-10
dnf install epel-release
dnf install sngrep

sngrep -V

sngrep needs root (or the capture capability) to read packets. It does not change anything on the server, so it is safe on a live PBX.

Capture and read a call

sngrep -d any port 5060          # all interfaces, SIP on 5060
sngrep -c -d any port 5060       # only calls (INVITE dialogs), hide OPTIONS and REGISTER

The first screen lists dialogs as they happen. Make the test call, highlight it with the arrow keys and press Enter. The ladder shows each host as a column and each SIP message as an arrow. Press Enter on a message to see it in full, and F6 for the raw text. Things to look for:

  • The final response: follow the dialog to its end before deciding why it failed. A 401 or 407 straight after the first INVITE or REGISTER is a normal authentication challenge, and the client sends the request again with credentials. The response to that retry, or the last final response in the dialog, is the real result: a 4xx, 5xx or 6xx there is the reason the call failed. Look it up in the SIP response codes tool.
  • Repeated arrows: the same INVITE or 200 OK sent again and again means the other side is not receiving it or its reply is lost.
  • Missing ACK: a 200 OK with no ACK after it ends in a BYE about 32 seconds later.
  • SDP: the c= line is where that side wants audio sent, and m=audio gives the port and codecs.

What a normal call looks like

It helps to know a healthy ladder before you hunt for a broken one. A typical outbound call from a PBX to a provider that asks for credentials looks like this:

PBX 198.51.100.10                          Provider 203.0.113.20
  INVITE (SDP)   --------------------------->
                 <---------------------------  407 Proxy Authentication Required
  ACK            --------------------------->
  INVITE (SDP)   --------------------------->  now with Proxy-Authorization
                 <---------------------------  100 Trying
                 <---------------------------  183 Session Progress (SDP)
                 <---------------------------  200 OK (SDP)
  ACK            --------------------------->
                 ... conversation (RTP) ...
  BYE            --------------------------->
                 <---------------------------  200 OK
  • 401 or 407 followed by a second INVITE is normal. It is the digest challenge: the server asks for credentials and the client resends the request with them. It is only a fault if the second request is rejected too.
  • 100 Trying stops the INVITE being retransmitted. 183 with SDP usually carries ringback or announcements from the network.
  • Calls through Asterisk are two dialogs: the phone-to-PBX leg and the PBX-to-provider leg each have their own Call-ID. Select both in the call list with Space and press Enter to see them in one ladder.

sngrep keys and options worth knowing

These are the defaults in sngrep 1.8, the version in Debian 13. Press F1 on any screen for the full list.

Key or optionWhereWhat it does
F3 or /Call listSearch the list as you type
F5Call listClear the captured calls and start fresh
F2 or dLadderCycle SDP display: label SDP arrows with the media address they advertise
F3 or mLadderShow or hide RTP streams
DLadderShow only messages that carry SDP
Space on two messagesLadderCompare them side by side
Esc or qAnyBack one screen, or quit from the call list
-N -qCommand lineCapture without the interface (use with -O)

Anything after the options is a match expression followed by a BPF filter. sngrep -d any 1001 port 5060 captures only dialogs in which a request contains 1001, which is a quick way to follow one extension or number. Write the BPF filter as plain words, not one quoted string: sngrep takes the first extra argument as the match expression if the rest is still a valid filter, so a filter in quotes is treated as text to match and the screen stays empty.

Filter, save and share a capture

Press F7 to filter by number, method or address, and Space to select several dialogs. F2 saves the selection as a pcap (for Wireshark) or plain text. You can also capture straight to a file on a busy server and read it later:

sngrep -d any -O /root/sip-$(date +%F).pcap port 5060    # capture to a file
sngrep -I /root/sip-2026-10-03.pcap                        # read it back

For a fault that only happens now and then, run the capture without the interface, for example in a tmux session. On SIGUSR1 sngrep reopens the -O file, so you can rotate it without stopping the capture:

sngrep -N -q -d any -O /root/sip-capture.pcap port 5060
# later, from another shell: rotate the file
mv /root/sip-capture.pcap /root/sip-capture-$(date +%F-%H%M).pcap
pkill -USR1 -x sngrep

The text export pastes straight into our SIP trace analyzer, which lists NAT, codec and timer problems for you. Replace phone numbers and remove any Authorization headers before you send a capture to anyone else.

Check the audio (RTP)

SIP sets up the call, RTP carries the voice. When signalling looks right but there is no audio, check whether RTP packets are flowing in both directions:

# RTP between the PBX and the provider's media address (from the SDP)
tcpdump -ni any udp portrange 10000-20000 and host 203.0.113.30 -c 50

# or from the Asterisk CLI during a call
rtp set debug ip 203.0.113.30
rtp set debug off

Packets in only one direction mean a firewall or NAT problem on the side that is not receiving: check that the RTP range is open and that the PBX advertises its public IP. sngrep can also record RTP with sngrep -r, and Wireshark’s Telephony, VoIP Calls menu can play the audio from a pcap.

When you use -r, widen the capture filter. A filter of port 5060 drops every RTP packet before sngrep sees it, so include the RTP range too (10000–20000 is the Asterisk sample default):

sngrep -r -d any port 5060 or udp portrange 10000-20000

Open the call and press F3 in the ladder to show the RTP streams next to the SIP arrows. A stream shown in only one direction points to the same NAT and firewall problems as above.

Use the Asterisk logger instead

When you cannot install packages, Asterisk’s own logger prints every SIP message it sends and receives to the CLI:

asterisk -rvvv
pjsip set logger host 203.0.113.20
# make the call
pjsip set logger off

The logger sees messages after Asterisk has decrypted TLS, which sngrep cannot, but it only shows Asterisk’s view: if a router or SIP ALG changes packets on the way, compare with a capture taken outside the PBX.

In Asterisk 22 the logger can also write what it sees to a pcap file. That gives you a sngrep ladder for TLS calls: the file holds the decrypted messages, stored as plain UDP packets.

pjsip set logger pcap /tmp/pjsip-trace.pcap   # write messages to a pcap file
pjsip set logger verbose off                   # keep them off the console
pjsip set logger host 203.0.113.20             # start logging for this host
# make the call
pjsip set logger off                           # stops logging and closes the file

sngrep -I /tmp/pjsip-trace.pcap

Asterisk does not record its own address in this file, so the PBX appears as a 0.0.0.0 column in the ladder; the far end shows its real address. The file is written by the Asterisk process, so use a path the asterisk user can write to, such as /tmp. Delete it when you are done: it contains the decrypted signalling, including Authorization headers.

Common failures in the ladder

These patterns cover most failed calls between a PBX and a trunk:

What the ladder showsLikely causeCheck
401 or 407, then the request with credentials gets 401, 407 or 403 againWrong username, password or realmThe auth section, and whether the provider wants the account ID or the number as username
INVITE repeated with no reply at allPackets not reaching the far end, or replies not coming backFirewall, destination IP and port, UDP versus TCP, SIP ALG on the router
403 Forbidden to an INVITE while registration worksThe provider refuses the callOutbound caller ID, allowed source IPs, account balance or call restrictions
404 Not Found or 484 Address IncompleteThe number in the Request-URI is not in a format the far end acceptsDial pattern and number format the provider expects (national or international with +)
488 Not Acceptable HereNo codec in common, or SDP the far end rejectsCompare the m=audio codec list in the INVITE with what the provider supports
503 Service UnavailableThe far end is overloaded, out of channels or has no routeProvider status and channel limit; a second route if you have one
CANCEL, then 487 Request TerminatedThe caller hung up before the call was answeredNormal, unless callers say the phone never rang

Troubleshooting SIP with sngrep at a glance

Troubleshoot SIP Calls with sngrep and the Asterisk PJSIP Lo summary card: Install sngrep (apt install sngrep, or from EPEL on AlmaLinux and Rocky), run sngrep -d any port 5060, make a test…
In short: Install sngrep (apt install sngrep, or from EPEL on AlmaLinux and Rocky), run sngrep -d any port 5060, make a test call, select it and press Enter for the ladder.
Troubleshoot SIP Calls with sngrep and the Asterisk PJSIP Lo sections: Install sngrep, Capture and read a call, Filter, save and share a capture and Check the audio (RTP)
Covers: Install sngrep, Capture and read a call, Filter, save and share a capture and Check the audio (RTP).
Troubleshoot SIP Calls with sngrep and the Asterisk PJSIP Lo questions answered: Can sngrep see SIP over TLS? Is it safe to run sngrep on a production PBX?
Answers: Can sngrep see SIP over TLS? Is it safe to run sngrep on a production PBX?

Official documentation: sngrep, tcpdump manual, Asterisk documentation, Wireshark VoIP calls.

Related: SIP trace analyzer · SIP error codes · Fix one-way audio · Disable SIP ALG.

Different symptom? See Common VoIP problems and how to fix them for the 11 problems we see most, with a free tool for each.

Frequently asked questions

Can sngrep see SIP over TLS?

Not the content. With TLS on port 5061 the packets are encrypted, so use the Asterisk pjsip logger, which shows the decrypted messages, or write those messages to a pcap file for sngrep as described in this guide. Do not switch a production trunk to UDP to read it, which sends credentials and call details unencrypted; keep that for an isolated lab system.

Is it safe to run sngrep on a production PBX?

Yes. It only reads packets and does not change the system. On a very busy server, filter by port or host and use -c to limit memory use, or capture to a file with -O.

Why does sngrep show nothing?

Run it as root, choose the right interface (-d any), and check the port: providers often use 5060 but some use 5080 or another port, and TLS on 5061 shows encrypted packets only.

How do I capture a call that happens at random times?

Run sngrep -N -q with -O to a file and rotate it with the mv and SIGUSR1 steps in this guide, because -O on its own writes one file that keeps growing. Alternatively use tcpdump -C and -W, which rotate by themselves. Open the file with sngrep -I when the fault is reported.

How do I get a sngrep ladder for a call over TLS?

On Asterisk 22, run pjsip set logger pcap /tmp/pjsip-trace.pcap and then pjsip set logger on (or host), make the call, run pjsip set logger off, and open the file with sngrep -I. The file holds the decrypted messages as plain UDP packets.

Share this guide

Free website test

Is your website set up right?

Check SSL, security headers, redirects, robots.txt, sitemap, llms.txt and security.txt in one test. It takes about 30 seconds.