2.3 Calling "Hello World" with a SIP Phone
Having tested our extension 1001 from the console, we take the next logical step and try the call from a SIP telephone. If you don't have a hardware SIP phone, you can use a software SIP phone that you install on a client computer. Many of these are freely available on the Internet.
2.3.1 Configuring the SIP Phone and sip.conf
Before you can use a SIP phone with Asterisk, you need to create an account for it in your Asterisk configuration. We will move the sample sip.conf file to our backup directory, /var/tmp/asterisk-etc-backup/, in the same way we previously moved extensions.conf, with the command mv sip.conf /var/tmp/asterisk-etc-backup/ :
debian:/etc/asterisk# mv sip.conf /var/tmp/asterisk-etc-backup/ debian:/etc/asterisk#
Now we create a new /etc/asterisk/sip.conf and enter the following:
[general] port=5060 bindaddr=0.0.0.0  type=friend secret=1234 host=dynamic
Your SIP telephone must now be configured with the following account information:
- User: 2000
- Password: 1234
- SIP registrar: IP address of your Asterisk server
- SIP proxy: IP address of your Asterisk server
2.3.2 Starting Asterisk and the Phone
Now we start Asterisk in verbose level 5 with asterisk -vvvvvc :
debian:/etc/asterisk# asterisk -vvvvvc Asterisk 1.4.21, Copyright (C) 1999 - 2008 Digium, Inc. and others. [...]
Next, we start the SIP phone and wait for the registration message in the Asterisk console:
*CLI> -- Registered SIP '2000' at 126.96.36.199 port 5060 expires 120 -– Unregistered SIP '2000'
When you call extension 1001 from the SIP phone, you will hear the hello-world.gsm file played back to you.
188.8.131.52 Calling the Phone from the Asterisk Console
Because we can call an extension with console dial and we have successfully attached a SIP phone to the system, it should be possible to call that SIP phone from the console. To do this, we need to add an extension to /etc/asterisk/extensions.conf:
[default] exten => 1001,1,Answer() exten => 1001,2,Playback(hello-world) exten => 1001,3,Hangup() exten => 2000,1,Dial(SIP/2000)
To apply these changes, you must either restart Asterisk or reload the dialplan. To restart Asterisk, enter stop now in the Asterisk console and asterisk -vvvvvc in the Linux shell. To reload the dialplan from within the running Asterisk, enter dialplan reload in the Asterisk console. Now you can dial the SIP phone with console dial 2000 :
*CLI> console dial 2000
The dialplan application Dial() sets up a connection to a telephone. It uses a parameter consisting of two parts: the first, SIP , describes the technology used for establishing the connection (the SIP VoIP protocol in our example). The second part defines the target device using that technology (in this case, 2000 ). When using Dial() , no Answer() or Hangup() is required. Because we do not know in advance whether the called station will even accept the call, Dial() has additional intelligence for opening and closing the channel.
In our example, the extension 2000 corresponds with the SIP target 2000, but this is, strictly speaking, coincidental. You could also write the extension like this:
exten => 55,1,Dial(SIP/2000)
Reload the dialplan, and now you can call the same SIP telephone with console dial 55 .
184.108.40.206 Comments in the Configuration
Because the number sign (#) corresponds to a dual-tone multi-frequency (DTMF) tone, it cannot be used as the comment character. Instead, Asterisk configuration files use the semicolon (;) for indicating comments, as follows:
[default] ; Extension 1001 is used for testing ; of all phones. ; exten => 1001,1,Answer() ; answering... exten => 1001,2,Playback(hello-world) exten => 1001,3,Hangup() ; hanging up... ; Extension 2000 calls SIP telephone ; 2000. ; exten => 2000,1,Dial(SIP/2000)