Troubleshooting
How to Capture and Read SIP Traces With sngrep and Wireshark
On this page
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.
| Command | What it does |
|---|---|
sngrep -d any port 5060 | Live capture of SIP on port 5060, all interfaces |
sngrep -c -d any port 5060 | Only dialogs that start with INVITE, hiding REGISTER and OPTIONS noise |
sngrep -d any -O /tmp/sip.pcap port 5060 | View live and save everything captured to a pcap |
sngrep -r -d any port 5060 or udp portrange 10000-20000 | Also capture RTP (the filter must include the RTP ports) |
sngrep -N -q -d any -O /tmp/sip.pcap port 5060 | Capture with no interface, for leaving running; stop with Ctrl+C |
sngrep -I call.pcap | Open 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 onshows 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.
| Field | What it tells you | Typical problem |
|---|---|---|
| Request or status line | Method and target, or the response code | Wrong number format or domain |
| Via | Path for responses; received and rport show the real source | Private address with a public received means NAT |
| Contact | Where ACK, BYE and re-INVITE are sent | Private IP causes calls dropping after 30 seconds |
| Call-ID | Same for every message in a dialog | Use it to filter and to quote to your provider |
| CSeq | Number plus method; rises with each new request | Same CSeq and branch again means a retransmission |
SDP c= | Address that should receive audio | Private address means one-way or no audio |
SDP m=audio | Media port and offered payload types | Port outside the firewall range; no common codec |
SDP a=sendrecv | Media direction; sendonly or inactive signal hold | Unexpected 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
How to Fix One-Way Audio on VoIP Calls
One side can't hear the other? A step-by-step guide to fixing one-way and no-audio VoIP calls caused by NAT, SIP ALG, firewalls and wrong SDP addresses.
SIP ALG: What It Is and Why to Disable It
What SIP ALG does, why it breaks VoIP calls and registrations, how to tell if it's causing problems, and how to turn it off on common routers and firewalls.
SIP Registration Failed? Troubleshooting Checklist
Fix failed SIP registrations step by step: read 401, 403, 404, 408, 423 and 503 replies, then check DNS, ports, NAT, fail2ban bans and Asterisk PJSIP.
Calls Dropping After 30 Seconds
Why VoIP calls drop after about 32 seconds: lost ACKs, NAT, wrong Contact headers and SIP ALG, how to prove it in a trace, and fixes for Asterisk and routers.