Debug SIP protocol in Asterisk

Let's suppose, you want to see which SIP messages come from user user001 and which responses are sent back.
For this perform next actions:

1. Acquire root access.

2. Turn on SIP debug for user user001:

# asterisk -rx "sip set debug peer user001" 

To capture this way Asterisk should know IP address of a user.
Thus, user should be either registered, or user's IP address should be configured in user's settings.

In case if you know IP address of a user, but don't know, under which peer it's registered/configured, you can capture dump, using IP address:

# asterisk -rx "sip set debug ip 192.168.1.1" 

In case if you need to debug all SIP messages (and not from/to specific peer/IP address), execute following:

# asterisk -rx "sip set debug on" 

3. You can watch results either in Asterisk console or in log file.

Asterisk console is convenient to use to quickly check if any messages come from client.
However console doesn't allow to perform text search.

Log file is convenient to use, if you wish to perform search inside of big amount of messages.
Also file is more convenient to use, if you use SIP debugging together with Asterisk debugging

4. To prevent from disk space overflow turn off debugging once you've finished:

# asterisk -rx "sip set debug off" 

Русский перевод