Tip: type a SIP code like 488, or a problem like one-way audio. Use ↑ ↓ and Enter.

Troubleshooting

How to Capture and Read SIP Traces With sngrep and Wireshark

On this page
  1. Where to capture
  2. sngrep: live SIP call flows in the terminal
  3. tcpdump: save SIP and RTP for later
  4. Wireshark: calls, flows and audio
  5. The TLS caveat
  6. What to read in a SIP message
  7. Sharing traces safely

Use sngrep on the PBX or SBC for a fast live view of SIP call flows, tcpdump to save SIP and RTP to a pcap file, and Wireshark to analyse that file in detail, including audio quality and playback. Between them they answer most "what actually happened on this call?" questions, provided you capture in the right place and know which headers to read.

Where to capture

Capture where the traffic is visible and unencrypted, as close as possible to the device you suspect. On a Linux PBX or SBC, capture on the server itself. For a desk phone, use a mirrored switch port or the phone's own packet capture, which many business phones offer in their web interface. For NAT problems, capture on both sides of the router at the same time; comparing the two shows exactly what the router changed.

sngrep: live SIP call flows in the terminal

On Debian and Ubuntu, sngrep is in the standard repositories:

sudo apt update
sudo apt install sngrep

On other distributions, check your package manager or build it from the project's GitHub repository (irontec/sngrep). Run sngrep -V to see whether it is already installed. It needs root (or sudo) to capture from network interfaces.

CommandWhat it does
sngrep -d any port 5060Live capture of SIP on port 5060, all interfaces
sngrep -c -d any port 5060Only dialogs that start with INVITE, hiding REGISTER and OPTIONS noise
sngrep -d any -O /tmp/sip.pcap port 5060View live and save everything captured to a pcap
sngrep -r -d any port 5060 or udp portrange 10000-20000Also capture RTP (the filter must include the RTP ports)
sngrep -N -q -d any -O /tmp/sip.pcap port 5060Capture with no interface, for leaving running; stop with Ctrl+C
sngrep -I call.pcapOpen a saved capture

The trailing arguments are a standard BPF filter, the same syntax tcpdump uses, so port 5060 or port 5080 works too.

The main screen lists dialogs with method, From, To, addresses, message count and state. Select one and press Enter to open its call flow: a ladder diagram with one column per IP and port, one arrow per message, and timestamps with deltas. The selected message, including its SDP, appears in full beside the diagram. Repeated identical arrows are retransmissions, the first thing to look for on calls that drop or never connect.

  • F2 saves dialogs (all, or only those selected with the space bar) as pcap or plain text.
  • F3 searches the list; F7 opens the filter form for method, From, To, addresses and payload.
  • F4 shows the extended flow, joining related dialogs such as the inbound and outbound legs of the same call through the PBX.
  • F1 shows the key list for your version. If your terminal or SSH client intercepts function keys, the help screen lists letter alternatives.

tcpdump: save SIP and RTP for later

When you need the audio as well, or want an unattended capture while you wait for an intermittent fault, use tcpdump:

sudo tcpdump -i any -s 0 -w call.pcap udp port 5060 or udp portrange 10000-20000

-i any captures on all interfaces, -s 0 keeps whole packets (the default on modern versions) and -w writes to a file. Match the port range to your RTP range: Asterisk and FreePBX default to 10000 to 20000 (rtp.conf), FreeSWITCH to 16384 to 32768. Include TCP and TLS signalling if you use them:

sudo tcpdump -i any -s 0 -w sip.pcap 'port 5060 or port 5061 or udp portrange 10000-20000'

For long captures, use a ring buffer so the disk cannot fill:

sudo tcpdump -i any -s 0 -C 100 -W 20 -w /var/tmp/sip.pcap 'port 5060 or udp portrange 10000-20000'

-C 100 starts a new file every 100 million bytes and -W 20 keeps only the newest 20, overwriting the oldest. As a sizing guide, one G.711 call adds roughly 1.3 MB per minute (both directions), so RTP dominates on a busy system. Capture signalling only if audio is not the question.

Wireshark: calls, flows and audio

Find the call

Open the pcap and go to Telephony → VoIP Calls. Each call is listed with start and stop times, From, To, packet count and state. Select a call and click Flow Sequence for a ladder diagram of its SIP messages and RTP streams; clicking an arrow jumps to that packet. Telephony → SIP Flows gives the same view for all SIP dialogs, including registrations. Display filters narrow things down:

sip
sip.Method == "INVITE"
sip.Status-Code >= 400
sip.CSeq.method == "REGISTER"
sip.Call-ID == "3848276298220188511@192.168.1.10"
rtpevent

The last filter shows DTMF sent as RTP events (RFC 4733), useful when IVR menus ignore key presses.

RTP streams and stream analysis

Telephony → RTP → RTP Streams lists every stream with source and destination, SSRC, payload type, packet count, lost packets, maximum delta and jitter. Select a stream and click Analyze to open RTP Stream Analysis, which shows each packet's delta, jitter and any sequence errors. What to check:

  • Stream count. A normal call has one stream in each direction. Only one stream means one-way audio; see fixing one-way audio.
  • Lost packets. Even small amounts are audible, especially in bursts.
  • Max delta. With 20 ms packetisation, packets should arrive about 20 ms apart. Gaps of hundreds of milliseconds mean stalls or bursts.
  • Jitter. Low single-digit milliseconds is typical on a healthy LAN. Sustained values in the tens of milliseconds push the receiver's jitter buffer and add delay.

Measurements reflect the network up to the capture point, so capture at the receiving end. Turn loss, jitter and delay into a quality estimate with the MOS calculator, and see jitter, latency and packet loss explained.

Play the audio

In VoIP Calls or RTP Streams, select the call or streams and click Play Streams to open the RTP Player. G.711 plays in every build; support for G.722, G.729, Opus and other codecs depends on your Wireshark version and how it was built.

When RTP or SIP is not decoded

Wireshark recognises RTP from the SDP in captured SIP messages. If the capture started mid-call or the signalling was encrypted, RTP appears as plain UDP. Enable the heuristic under Analyze → Enabled Protocols (search for rtp_udp), or right-click a packet and use Decode As.

SIP on 5060 is decoded automatically and Wireshark often spots it on other ports too. If SIP on, say, 5080 still shows as UDP, open Analyze → Decode As, add a row for UDP port 5080 and set it to SIP. Use the TCP port field for SIP over TCP.

The TLS caveat

SIP over TLS (usually port 5061) is encrypted, so neither tool can read it from a network capture. Wireshark needs the session keys, such as a key log file from the client, which phones and PBXs rarely provide. An RSA private key only works for old cipher suites without forward secrecy, never TLS 1.3, and sngrep's -k option has the same limit. Practical options:

  • Use the PBX's own logging, which records messages after decryption. On Asterisk, pjsip set logger on shows TLS-carried SIP in clear text.
  • Reproduce the fault on a test device using UDP or TCP, if your security policy allows it.
  • With SRTP, RTP headers are not encrypted, so Wireshark can still measure loss and jitter once it identifies the streams. It cannot play the audio.

What to read in a SIP message

This INVITE comes from a PBX behind NAT that has no external address configured (some headers omitted):

INVITE sip:0215550123@provider.example SIP/2.0
Via: SIP/2.0/UDP 192.168.1.10:5060;rport;branch=z9hG4bK-524287-1
From: <sip:1000123@provider.example>;tag=a73kszlfl
To: <sip:0215550123@provider.example>
Call-ID: 3848276298220188511@192.168.1.10
CSeq: 102 INVITE
Contact: <sip:1000123@192.168.1.10:5060>
Content-Type: application/sdp

v=0
o=- 4021 4021 IN IP4 192.168.1.10
s=-
c=IN IP4 192.168.1.10
t=0 0
m=audio 14562 RTP/AVP 8 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=sendrecv

The provider's responses would carry this Via back with received= and rport= filled in with the public address and port it actually saw, which confirms NAT. The private Contact and c= line predict a 32-second drop and one-way audio respectively.

FieldWhat it tells youTypical problem
Request or status lineMethod and target, or the response codeWrong number format or domain
ViaPath for responses; received and rport show the real sourcePrivate address with a public received means NAT
ContactWhere ACK, BYE and re-INVITE are sentPrivate IP causes calls dropping after 30 seconds
Call-IDSame for every message in a dialogUse it to filter and to quote to your provider
CSeqNumber plus method; rises with each new requestSame CSeq and branch again means a retransmission
SDP c=Address that should receive audioPrivate address means one-way or no audio
SDP m=audioMedia port and offered payload typesPort outside the firewall range; no common codec
SDP a=sendrecvMedia direction; sendonly or inactive signal holdUnexpected hold direction gives silence

Note that the ACK for a 200 OK reuses the INVITE's CSeq number with the method ACK, and a client that answers an authentication challenge sends a new request with a higher CSeq. Response codes are explained in the SIP response code reference.

Sharing traces safely

Traces contain personal and security-sensitive data: phone numbers, IP addresses, caller names and, in RTP, the conversation itself. Authorization headers carry digest responses that, together with the realm and nonce, can be used to guess weak passwords offline. Before a trace leaves your organisation:

  • Export only the relevant call. In Wireshark, filter on the Call-ID (or use Prepare Filter in VoIP Calls), then File → Export Specified Packets with "All packets: Displayed" selected.
  • Leave out RTP unless the recipient needs to analyse audio.
  • Redact text traces. Remove Authorization and Proxy-Authorization headers, and mask numbers consistently (the same placeholder for the same number everywhere) so the flow still makes sense. sngrep's text export is easier to redact than a pcap.
  • Use a trusted channel, such as your provider's support portal, not a public forum. In South Africa phone numbers and call content are personal information under POPIA, and similar rules such as the GDPR apply elsewhere.

Try the SIP Response Codes

Every SIP status code from 100 to 608, with plain-English meanings, causes, fixes and example traces.

Keep reading