Skip to content

Trace an Asterisk Call Through the Dialplan with sngrep

Trace one Asterisk call with sngrep. Match SIP call flows to dialplan Executing lines, follow call IDs in the log, and capture with sngrep options.

By · Updated · Published

Photo of office, business, accountant
Photo by Firmbee · Pixabay Content License · via Pixabay

How do you trace one Asterisk call end to end?

Watch the SIP side and the dialplan side of the same call at the same time. sngrep shows each SIP dialog as a message flow in the terminal. The Asterisk console shows each dialplan step as a line with extension@context:priority and the application that runs.

The two views come from different tools, so you line them up yourself. A dialplan step shows where a call is in your configuration. A SIP message shows what the endpoints and the server sent to each other. Neither view alone shows the whole call.

The steps below run in this order: capture or open the SIP trace, turn on verbose output, read the Executing lines beside the matching SIP messages, and reset the debug settings when you finish.

What does each tool show about one call?

We compiled this comparison on November 14, 2026, from sngrep's own documentation and from the official Asterisk documentation. The sngrep sources are the irontec/sngrep README, the version 1.9.0 man page and the project wiki. The Asterisk sources are pages on docs.asterisk.org. The comparison was compiled from those pages and was not tested.

ToolCommand or settingWhat it shows about one call
sngrep live capturesngrep port 5060SIP dialogs and their message flow in the terminal
sngrep offlinesngrep -I file.pcapThe same view, read from a saved pcap file
sngrep headlesssngrep -N -O file.pcapCapture only, with no interface
Asterisk SIP logpjsip set logger onSIP messages inside the Asterisk console
Asterisk dialplan tracecore set verbose 5Each step as extension@context:priority and the application it runs
Asterisk call IDAutomaticA C-XXXXXXXX tag on the log lines for the call
Asterisk debug log filelogger add channelA full log file to read after the call
Asterisk live callscore show channelsChannel, Location, State and Application(Data) for each live call

Each row is explained in the sections below. The table shows which view to open, so it does not list every option.

How do you capture the call with sngrep?

Photo of student, typing, keyboard
Photo by StartupStockPhotos · Pixabay Content License · via Pixabay

Install sngrep with your system's package manager. The sngrep installation page lists these commands.

SystemCommand
Debian and recent Ubuntuapt-get install sngrep
Fedora, CentOS, RHEL or AlmaLinuxdnf copr enable irontec/sngrep, then dnf install sngrep
Alpineapk add sngrep
macOSbrew install sngrep
OpenWRTopkg install sngrep

On Fedora and the related systems, enable the repository first, then install the package.

Once sngrep is installed, start it with a device and a filter. The -d option picks the capture device, and the default is any. A trailing BPF filter works like the filters in tcpdump and ngrep, so you can limit the view to one port or one host.

Shell
sngrep port 5060
sngrep -d eth0 -O save.pcap port 5060 and udp

The first line opens the live view and keeps only packets on port 5060. The second line captures on the device eth0, which is an example name, and saves every captured packet to save.pcap with -O. The filter keeps only UDP packets on port 5060.

Use -c to limit the call list to calls. It shows only dialogs that start with an INVITE request, so other dialogs are hidden.

A match expression goes after the options. sngrep matches it against message payloads. The -i option makes the match case-insensitive, and -v inverts it. When one request matches, the later messages in that dialog are captured too, so the whole call stays together.

Shell
sngrep -c
sngrep -i alice

The first line shows only INVITE dialogs. The second line keeps dialogs where a request contains alice, in any letter case. The messages that follow in those dialogs stay in view.

To read a saved file, use -I. It reads packets from a pcap file instead of a network device, and it can take a BPF filter too.

Shell
sngrep -I file.pcap host <sip-host-ip> and port 5060

The -I option opens file.pcap. The filter keeps packets to or from one host on port 5060. Replace <sip-host-ip> with an address from your own capture. Without a BPF filter, all SIP packets in the file are shown.

How do you read the sngrep call flow?

In the call list, press Enter on a dialog to open its call flow. Press Space to select dialogs, and press p to pause. The keys below move you around each screen. They come from sngrep's wiki pages for the call list and the call flow.

ScreenKeyWhat it does
Call listEnterShows the selected dialog's message flow
Call listSpaceSelects a dialog
Call listF2 or sSaves dialogs to a pcap file
Call listF3, / or TabOpens a display filter
Call listF4 or xShows a dialog with its related one
Call listF6 or rShows raw text
Call listF7 or fOpens advanced filters
Call listpPauses
Call flowEnterShows the current message raw
Call flowF2 or dToggles SDP info in the arrows
Call flowF3 or tToggles the preview panel
Call flowF4 or xShows the dialog and its extended one
Call flowF7 or cChanges the color mode
Call flowDShows only messages with SDP
Call flowEsc or qGoes back

Use F4 or x in the call flow to see the extended flow, which covers both legs of a call. The extended flow needs an X-CID or X-Call-ID header that names the related Call-ID. If no second leg appears, check those headers first.

Press Enter on a message in the call flow to see its raw text. The raw text includes the SIP headers, so you can compare them with the messages the Asterisk console prints.

How do you see the dialplan steps in the Asterisk console?

Two commands in the Asterisk CLI give you the console view. The core set verbose command sets the level of verbose messages on the console. The Asterisk debug examples use level 5, so this guide uses 5 too.

Output
*CLI> core set verbose 5
*CLI> pjsip set logger on

The first line raises the verbose level so each dialplan step prints as it runs. The second line turns on the PJSIP logger, which prints SIP messages in the console. The PJSIP logger needs Asterisk 12 or higher.

Each dialplan step appears as a line like this:

Output
-- Executing [100@from-internal:1] Playback("SIP/6001-00000005", "demo-congrats") in new stack

Read the line from left to right. The two dashes and the word Executing mark a dialplan step. The text in brackets is extension@context:priority. Here the extension is 100, the context is from-internal, and the priority is 1, which is the step number inside that extension. Playback is the application that runs. Its arguments sit in parentheses: the channel SIP/6001-00000005 and the file demo-congrats. The line ends with the words in new stack.

The core show channels command lists live channels. Its output has four columns: Channel, Location, State and Application(Data). Run the command during a call to see which application each live channel is in.

To match the console to sngrep, follow these steps.

  1. Start sngrep with a filter for the call's SIP port, for example sngrep port 5060.
  2. Open the call in the call list and note the time of its first INVITE.
  3. In the Asterisk console, watch the Executing lines that appear at the same time.
  4. Compare the SIP messages in the call flow with the Executing lines, to see which application ran when each message arrived.

How do you follow one call through the Asterisk log?

Asterisk tags log lines with call identifiers. The tag has the form C-XXXXXXXX, where XXXXXXXX is an 8-digit hexadecimal value. No setup is needed for this. The same ID appears in core show channel output, so you can find it there too.

The setting lives in logger.conf:

INI config
[general]
use_callids = yes

The [general] line starts the section for the main logging settings. The use_callids line writes call IDs into log messages. The default is yes, so this line matters only if someone set it to no and you want it back.

To follow one call, use these steps.

  1. Find a line for the call in the console, such as an Executing line, and copy its C- tag.
  2. Search the log file for that tag.
  3. Read the matching lines in order. They are the steps that one call ran.
Shell
grep "C-00000000" /var/log/asterisk/debug_log_123456

The grep command prints each line that contains the text in quotes. C-00000000 is an example ID, so use the tag from your own call. The path is the debug log file from the next section, so that log must be running before the call.

How do you keep a full debug log for one call?

For a full record, add a log channel from the CLI. The channel lasts until Asterisk restarts, the logger module reloads or the log files rotate, so add it again after any of those.

Output
*CLI> logger add channel debug_log_123456 notice,warning,error,debug,verbose,dtmf
*CLI> core set verbose 5
*CLI> core set debug 5

The first line adds a log channel named debug_log_123456. It writes notice, warning, error, debug, verbose and dtmf messages to /var/log/asterisk/debug_log_123456. The second line raises the verbose level to 5. The third line raises the debug level to 5. You can add a module name at the end of core set debug to show debug messages from one module only.

When the test ends, reset both levels.

Output
*CLI> core set verbose 0
*CLI> core set debug 0

The first line sets verbose back to 0. The second line sets debug back to 0. The Asterisk docs recommend that you do not turn on debug mode on a production system unless you are debugging a specific issue, so reset debug as soon as the test is over.

How do you capture calls on a busy server without the interface?

Headless capture runs sngrep without its screen. Use -N to turn off the interface, so sngrep only captures, and -O to save the packets to a file. The -q option hides dialog output in this mode.

Shell
sngrep -N -q -O file.pcap -l <N> -R port 5060

The -N option runs sngrep without the interface, just capturing. The -q option hides the dialog output. The -O option saves the captured packets to file.pcap. The -l option sets a capture limit of N dialogs. Replace <N> with the number you want. The limit must be above 1, and it cannot be disabled. The -R option rotates calls when the limit is reached. The filter port 5060 limits the capture to that port.

To add the RTP payload to the capture, add -r. Keep debug off on a busy production server unless you are chasing a specific issue. When the capture is done, open the file with sngrep -I file.pcap, and add a filter if you need one.

What do you do when the trace does not match?

Most gaps come from a filter, a setting or a missing header. Check these first.

SymptomWhat to check
sngrep shows no callsCheck the device with -d and the BPF filter. With -c, only dialogs that start with an INVITE request appear.
A dialog you expected is missingRemove -c, and check whether a match expression is limiting the list.
F4 shows no related dialogThe extended flow needs an X-CID or X-Call-ID header that names the related Call-ID.
Log lines have no C- tagCheck use_callids in logger.conf. The default is yes.
The console is flooded with debug outputRun core set debug 0 and core set verbose 0.
The debug log channel is goneIt ends when Asterisk restarts, the logger module reloads or the log files rotate. Add it again.
SIP messages do not appear in the consolepjsip set logger on needs Asterisk 12 or higher. The PJSIP troubleshooting guide suggests core set verbose 4, core set debug 4 and pjsip set logger on for a failing scenario.

If a pcap file does not open, check the file name after -I. Any filter goes after the file name.

Advanced examples: how do you combine these steps?

These three examples combine the options from this guide. Each one uses only commands and options described above.

The first example captures a busy server and reads the file later.

Shell
sngrep -N -q -O busy.pcap -l <N> -R port 5060
sngrep -I busy.pcap host <sip-host-ip> and port 5060

The first line captures headless on port 5060, saves to busy.pcap and rotates calls when the dialog limit is reached. The second line reads the saved file later and keeps packets to or from <sip-host-ip> on port 5060. Replace that placeholder with an address from your own capture.

The second example shows only the INVITE dialogs that contain one name.

Shell
sngrep -i -c alice

The -c option keeps only INVITE dialogs. The -i option makes the match for alice case-insensitive. Use it when you want the calls where that name appears in the messages.

The third example sets up the console and the log before a test call.

Output
*CLI> logger add channel debug_log_123456 notice,warning,error,debug,verbose,dtmf
*CLI> core set verbose 5
*CLI> core set debug 5
*CLI> pjsip set logger on

Start sngrep in a second terminal with sngrep port 5060, place the test call, and copy the C- tag of its Executing lines from the console. Search the log for that tag, as shown earlier, and compare those lines with the call flow. When you are done, reset the levels.

Output
*CLI> core set verbose 0
*CLI> core set debug 0

Both levels return to 0, so the console and the log stop collecting extra detail.

More guides in Open-Source PBX and SIP Servers.

Frequently asked questions

How do you read a saved pcap file in sngrep?
Run sngrep -I followed by the file name, for example sngrep -I file.pcap. Add a BPF filter after the file name if you need one. sngrep then reads the saved packets instead of a network device.
What does a -- Executing line in the Asterisk console mean?
It is one dialplan step. The text in brackets gives the extension, context and priority. The next part names the application that runs and its arguments.
How do you install sngrep on Debian, Ubuntu, Fedora, Alpine or macOS?
Use apt-get install sngrep on Debian and recent Ubuntu, and dnf copr enable irontec/sngrep then dnf install sngrep on Fedora. Use apk add sngrep on Alpine and brew install sngrep on macOS.

Sources

  1. sngrep is a terminal tool that displays SIP call message flows; it does live capture and c (github.com)
  2. In sngrep 1.9.0, -c only displays dialogs that start with an INVITE request. (github.com)
  3. sngrep installs with apt-get install sngrep on recent Debian/Ubuntu, dnf copr enable iront (github.com)