Skip to content

sngrep SIP Registration Troubleshooting: Reading a 401

Reading a 401 in sngrep REGISTER traces: why the first 401 is normal, what 401, 407, 403 and 423 mean, and which Asterisk checks to run.

By · Updated · Published

A laptop computer sitting on top of a wooden desk
Photo by 2H Media · Unsplash License · via Unsplash

Why does sngrep show a 401 on my first REGISTER?

The first 401 is normal, not a fault. RFC 3261 defines 401 Unauthorized as a response meaning the request requires user authentication, and it is issued by user agent servers and registrars. The response must carry a WWW-Authenticate header field, which holds the challenge. The RFC 3261 specification sets out the full rules.

After a 401, the client should re-send the request with proper credentials in an Authorization header. The retry belongs to the same registration when it keeps the same Call-ID and raises the CSeq by one. If the registrar accepts the retry, it answers 200 OK.

What does our REGISTER troubleshooting reference cover?

Our REGISTER troubleshooting reference was compiled on November 14, 2026, from primary sources: the sngrep 1.9.0 man page, the sngrep README and wiki from the irontec/sngrep project, RFC 3261, and the Asterisk PJSIP documentation. Nothing was captured or tested. Every row comes from a page in those sources.

The reference covers three things: the sngrep options that matter for REGISTER, what each REGISTER response means, and the Asterisk checks to run. The sections below follow that order, and each code block is explained after it.

How do I capture REGISTER traffic with sngrep?

Leave the -c option and the sip.calls setting off. The sngrep man page says -c displays only dialogs starting with an INVITE request, so REGISTER dialogs are hidden. The sngrep configuration wiki says sip.calls ignores dialogs not starting with INVITE, and it is off by default.

Choose the capture device with -d. It accepts the keyword any, which is the default, a device name such as eth0, or a comma-separated list such as eth1,eth3. The command below captures SIP on port 5060 over UDP and saves it to a pcap file.

Shell
# Capture SIP on port 5060 over UDP and save it to a pcap file
sngrep -d any -O register.pcap port 5060 and udp

Line by line: sngrep starts the tool. The -d any pair picks the capture device; any is the default, so the pair is optional. The -O register.pcap pair saves captured packets to register.pcap. The last words, port 5060 and udp, form a trailing BPF filter, which selects the packets sngrep parses, in the same way tcpdump does. The sngrep README uses the same form in its example.

To read the file later, pass it with -I:

Shell
# Open the saved capture later
sngrep -I register.pcap

-I tells sngrep to read packets from a pcap file instead of network devices. Select a dialog and press Enter to open its call flow. A match expression, given as an argument, filters on message text; -i makes it case-insensitive and -v inverts it.

To record traffic without the interface on screen, combine -N with -q and -O:

Shell
# Capture without the interface, do not print dialogs, and save to a file
sngrep -N -q -O register.pcap port 5060 and udp

-N captures without displaying the interface. -q stops sngrep printing dialogs in that mode. Use this form when you want to record traffic now and read it later with -I.

Settings can also live in a config file. sngrep reads /etc/sngreprc or /usr/local/etc/sngreprc, then $HOME/.sngreprc. Each line has the form set option value.

Output
# ~/.sngreprc
set capture.device eth0
set sip.calls off

The capture.device line sets the default capture interface, the same as the -d argument. The sip.calls line keeps the INVITE-only filter off, which is its default. Writing it out makes the setting visible in the file.

What do 401, 407, 403 and 423 mean for a registration?

Each response calls for a different fix, so read the code before you change a password. The table gives the RFC 3261 meaning of each response and what to check.

ResponseMeaning (RFC 3261)What to check
401 UnauthorizedThe request requires user authentication. Issued by user agent servers and registrars; the challenge is in WWW-Authenticate.Expected once. If it returns after the credentialed retry, the credentials are wrong.
407 Proxy Authentication RequiredLike 401, but the client must first authenticate with the proxy. The challenge is in Proxy-Authenticate.Retry with Proxy-Authorization. Proxies must not send 401, so a proxy challenge arrives as a 407.
403 ForbiddenThe server understood the request but refuses it. Authorization will not help.The request should not be repeated; authorization will not help.
423 Interval Too BriefThe requested expiration time is too short. Min-Expires gives the minimum refresh interval.Raise the expiry to at least the Min-Expires value.

A 200 OK from the registrar lists the Contact fields for all current bindings, so it shows what the server now holds. An Expires header or a Contact expires parameter suggests the interval, and the per-contact parameter takes precedence. An expiry of 0 removes the binding.

What should I check when REGISTER problems persist?

Photo of todo-lists, tasks, tasks list
Photo by viarami · Pixabay Content License · via Pixabay

Work through this table from the top. Each row points to one option or one response code from the sections above.

SymptomWhat to check
No REGISTER lines appearRemove -c from the command and make sure sip.calls is not set to on.
The capture shows nothing you expectCheck the device given to -d, such as any or eth0.
401 after the credentialed retryThe credentials are likely wrong, or Asterisk did not match the request to an endpoint (see below). Compare the Authorization header with the account you expect.
423 Interval Too BriefRaise the expiry to the Min-Expires value in the response.
Packets you cannot readPass the RSA private key file with -k so sngrep can decrypt the packets.

If none of these rows match, return to the call flow and check the Call-ID and CSeq of each message.

How do I confirm the retry belongs to the same registration?

Call flow: the client sends REGISTER, the registrar answers 401 Unauthorized, the client resends REGISTER with an Authorization header and CSeq one higher, and the registrar answers 200 OK.
REGISTER, 401 and 200 OK call flow

Walk the trace as a call-flow diagram, in this order:

  1. The client sends REGISTER with a Call-ID and a CSeq value.
  2. The registrar answers 401 Unauthorized with a WWW-Authenticate header.
  3. The client sends REGISTER again with an Authorization header, the same Call-ID, and CSeq one higher.
  4. The registrar answers 200 OK and lists the Contact fields for all current bindings.

RFC 3261 says a UA should use the same Call-ID for all registrations during a single boot cycle. It also says a UA must increment CSeq by one for each REGISTER request with the same Call-ID. If the Call-ID changes, or CSeq does not rise by one, the retry does not follow that pattern.

Why does Asterisk send 401 when the password is right?

Flow chart of the Asterisk CLI steps: pjsip set logger on, then core set verbose 4, then core set debug 4, then pjsip show endpoints.
Asterisk CLI checks, in order

Asterisk answers 401 Unauthorized even when it cannot match the request to a configured endpoint. The Asterisk PJSIP troubleshooting guide says this prevents an information leak. A 401 alone therefore does not prove that the password was checked. Confirm that the request matches an endpoint before you change any password.

The guide suggests these steps at the Asterisk CLI:

Output
*CLI> pjsip set logger on
*CLI> core set verbose 4
*CLI> core set debug 4
*CLI> pjsip show endpoints

The first line turns on the PJSIP logger. The second and third lines set verbose and debug output to level 4. The last line lists the configured endpoints, so you can see whether the request has one to match. To see a single endpoint in detail, run pjsip show endpoint followed by the endpoint name.

To check registration state, use pjsip show registrations. It lists all outbound registrations from Asterisk, meaning the registrations Asterisk makes to a provider.

Can sngrep decrypt encrypted SIP packets?

The -k option takes an RSA private key file to decrypt captured packets. Pass the key file with -k when the packets you capture are encrypted and you hold the matching key.

What do the advanced examples look like?

The two examples below combine options from this guide. Each uses only documented options and settings.

The first example records REGISTER traffic with no interface on screen and rotates the capture at a dialog limit:

Shell
# Record SIP without the interface and rotate at a dialog limit
sngrep -N -q -O register.pcap -l LIMIT -R port 5060 and udp

Replace LIMIT with the number of dialogs you choose. The -l option sets the capture limit to that many dialogs, and -R rotates calls when the limit is reached. Keep -c out of the command so REGISTER dialogs stay in the capture. Read the saved file afterwards with -I, as shown earlier.

The second example is an outbound registration in Asterisk, which you can compare with the trace:

INI config
; Outbound registration: Asterisk registers to a provider
[provider-registration]
type = registration
server_uri = sip:sip.example.com
client_uri = sip:alice@sip.example.com
contact_user = alice
outbound_auth = provider-auth
retry_interval = 60

The host sip.example.com is a placeholder name, and alice is an example user name. The section header names the registration. The type line marks it as a registration section. The server_uri line gives the URI where the registrar is located. The client_uri line gives the URI Asterisk uses for itself, and contact_user sets the user part of the Contact. The outbound_auth line names the authentication section for the registration. The retry_interval line sets the wait between attempts; by default, outbound registrations have a retry_interval of 60 seconds. The same section can also set forbidden_retry_interval and max_retries. Compare the URIs in this block with the REGISTER lines in your sngrep trace.

More guides in Open-Source PBX and SIP Servers.

Frequently asked questions

Why do my REGISTER messages not show up in sngrep?
The -c option and the sip.calls setting both show only dialogs that start with INVITE, so REGISTER dialogs are hidden. Turn both off and capture again.
Which Asterisk PJSIP commands show registration state?
Use pjsip show endpoints, or pjsip show endpoint with an endpoint name, to see configured endpoints. Use pjsip show registrations to list Asterisk's own outbound registrations.

Sources

  1. RFC 3261 defines 401 Unauthorized as: the request requires user authentication; it is issu (www.rfc-editor.org)
  2. sngrep -c displays only dialogs starting with an INVITE request, so REGISTER dialogs are h (github.com)
  3. The sngrep configuration setting sip.calls (default off) ignores dialogs not starting with (github.com)
  4. sngrep is a tool for displaying SIP call message flows from the terminal. (github.com)
  5. Asterisk's PJSIP troubleshooting guide suggests running pjsip set logger on, core set verb (docs.asterisk.org)