VoIP Cookbook: Asterisk as SIP Client

From OnnoWiki
Jump to navigation Jump to search

Asterisk can register itself to another SIP server and becomes a client. For this, the command used in sip.conf under [general] for registration to the SIP server is:

register => user[:secret[:authuser]]@host[:port][/extension]

If you have problems with your computer network, such as an unstable connectivity, frequent connectivity breakdowns, and losing established registration to your SIP server, you can add parameter “registerattempts” and “registertimeout” before the generic definition of register. Setting registerattempts=0 will force Asterisk to keep registering until successful (default value is 10 attempts). The value of registertimeout determines the length of time in seconds between attempts for registering (the default value is 20 seconds).

Example:

register => 2345: password@mysipprovider.com/1234 

The above command will register “2345” to mysipprovider.com and will be identified as extension 1234 in Asterisk which we operate. In the example above the parameters used are:

user – the user id for the SIP server (example: 2345) 
authuser - user authorization (optional) to the SIP server 
secret - the user password 
host - server name (example: mysipprovider.com) 
port – the SIP port in Server. The default is 5060. 
extension - the local extension number in Asterisk (example: 1234). 

The extension number is used to contact local extension of the Asterisk SIP server which we signed up. If there is no extension, Asterisk will automatically enter extension "s".

To see if Asterisk has successfully registered itself with the SIP Server, we can use Asterisk Interface Command Line, which can be accessed through the asterisk command “-r” in the shell.

# asterisk -r

Registration status can be viewed through the command:

sip show registry 

It seems that this command will be omitted in Asterisk version 1.4, and will be changed into

sip registry list 

To see the phone/extension listed in Asterisk which we operate, we can use the following command

sip show peers

In Asterisk 1.6, the command seems to be replaced by

sip peers list 

To make a call to a SIP server outside of Asterisk, we need to define sip.conf like the following example:

[mysipprovider-out] 
type=peer 
secret=password 
username=2345 
host=sipserver.mysipprovider.com 
fromuser=2345 
fromdomain=fwd.pulver.com 
nat=yes 
context=from-mysipprovider
; is further defined in extensions.conf 

In extensions.conf, we need to add a command like:

exten => _9.,1,Dial(SIP/${EXTEN:1}@mysipprovider-out,30,r) 

Please note that the variable ${EXTEN:1} here will take all the characters/ letters from the incoming extension except for the first character, which in this case, is the number 9.

Meanwhile, SIP extension configuration - generalions.conf – for receiving calls coming from the SIP server can also be developed using the following command:

[from-mysipprovider] 
exten => 1234.1, Answer 
; 1234 is the extension contact. The default extension contact is "s" 
exten => 1234.2,Dial(SIP/111,25,Ttr) 
; Incoming calls are redirected to a SIP telephone number 111 
exten => 1234.3,Hangup 

See Also