PHP, Linux and the like…

September 4, 2007

Basic Asterisk Configuration

Filed under: Asterisk, Fedora Core, Telephony — Paul Skinner @ 1:29 am

I really like the stats package included with WordPress, it provides an excellent source of ideas for what I should write about next. Many of you reach me through a post titled Asterisk and Fedora Core 7 looking for more specifics on how to configure Asterisk. If you need to install Asterisk on FC7, read the Asterisk and Fedora Core 7 post first.

Alright, so you’ve got Asterisk installed but its not configured or has the default Asterisk sample configuration files.

The Asterisk configuration files are found in /etc/asterisk. If you are using Asterisk without telephony hardware, you really need to be concerned with 2 or 3 files. Of importance are the following files

  1. sip.conf: this file contains everything to do with the SIP protocol, settings and authentication for Asterisk.
  2. extensions.conf: At the most basic level, this file contains the call-plan; what happens on in-bound calls and how outgoing calls are to be treated.

You’re also going to need something to test Asterisk with. Either a soft-phone such as X-Lite or a handset device such as a Polycom 430, or a ATA device, such as the LinkSys PAP-2.

For the sake of this sample, we’re going to configure Asterisk to handle the SIP registration of 3 IP devices.

  1. X-Lite Softphone [extension 203]
  2. a Polycom 301 [extension 200]
  3. a Linksys PAP-2 (Vonage un-locked) [extensions 201 and 202]

sip.conf is easy enough to get going; some advanced features found on some handsets may require additional settings but to keep things simple lets start with the softphone alone.

Backup your existing /etc/asterisk/sip.conf and go with something like this

[general]
port=5060
bindaddr=0.0.0.0
context=home
tos=0x18
nat=yes
externip=YOUR PUBLIC IP
disallow=all
allow=g729
allow=gsm
allow=ulaw

[203]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid=CIA FBI ATF <1-555-555-5555>
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

Feel free to have some fun with the “callerid” parameter, you can have some great fun with your friends and family.

Make a backup of /etc/asterisk/extensions.conf and replace it with this

[general]

static=yes
writeprotect=no

[home]
exten => 55,1,Playback(demo-echotest) ; Let them know what's going on
exten => 55,2,Echo ; Do the echo test
exten => 55,3,Playback(demo-echodone) ; Let them know it's over

This bare bones configuration sets up extension 55 in the “home” context to be an echo server.

Get Asterisk to re-read the sip.conf and extensions.conf files (if already running, to start Asterisk, just run “asterisk” as root).

[root@athlon asterisk]# asterisk -r
Asterisk 1.2.20, Copyright (C) 1999 - 2007 Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'show license' for details.
=========================================================================
Connected to Asterisk 1.2.20 currently running on athlon (pid = 3193)
Verbosity is at least 42
athlon*CLI> sip reload
 Reloading SIP
  == Parsing '/etc/asterisk/sip.conf': Found
  == Parsing '/etc/asterisk/sip_notify.conf': Found
athlon*CLI> extensions reload
  == Parsing '/etc/asterisk/extensions.conf': Found
    -- Registered extension context 'home'
    -- Added extension '55' priority 1 to home
    -- Added extension '55' priority 2 to home
    -- Added extension '55' priority 3 to home
athlon*CLI>

Configure the X-Lite phone by adding a SIP account with the following details:

X-Lite Account Details

Save the settings and X-Lite should register with Asterisk. If watching the Asterisk CLI, you should see the following

Connected to Asterisk 1.2.20 currently running on athlon (pid = 3193)
Verbosity is at least 42
    -- Remote UNIX connection
    -- Registered SIP '203' at 10.10.50.198 port 14126 expires 3600
    -- Saved useragent "X-Lite release 1011s stamp 41150" for peer 203
athlon*CLI>

X-Lite SIP account 203 registered

At this point you should be able to dial the echo server. Go ahead and dial “55″ and hit the green send button. You’ll connect with the “Echo Test”, basically just echoes whatever you say to it. It’s simple but a great way to get the basics right without having to deal with the large “sample” configuration files.

If your call to the echo server worked, the rest of the setup is basically the same as before, editing both the sip.conf and extensions.conf files.

Moving on, lets add the other extensions to the mix. We’ll have our own little PBX by the end of this!

Add the rest of the SIP devices to the sip.conf file

[general]
port=5060
bindaddr=0.0.0.0
context=home
tos=0x18
nat=yes
externip=YOUR PUBLIC IP
disallow=all
allow=g729
allow=gsm
allow=ulaw

[200]
type=peer
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid= CITY MORGUE
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

[201]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid= CITY MORGUE
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

[202]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid= CITY MORGUE
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

[203]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid=CIA FBI ATF
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

Now lets add the sip registrations to the extensions.conf file so that calls can be placed amongst the devices.

[general]

static=yes
writeprotect=no

[home]
exten => 55,1,Playback(demo-echotest) ; Let them know what's going on
exten => 55,2,Echo ; Do the echo test
exten => 55,3,Playback(demo-echodone) ; Let them know it's over
exten => 200,1,Dial(SIP/200,20)
exten => 201,1,Dial(SIP/201,60)
exten => 202,1,Dial(SIP/202,60)
exten => 203,1,Dial(SIP/203,60)

Reload sip.conf and extensions.conf and you should now be able to place calls between the registered devices and each device should be able to dial the echo server.

This is a very basic Asterisk configuration that should allow you to further explore other Asterisk options. In the next parts of this post, we’ll explore adding “trunking” with a VoIP provider, ZapTel hardware and voice mail with email notification (In no particular order).

5 Comments »

  1. Thanks for giving this useful information…

    Comment by Arunkumar — October 19, 2007 @ 8:14 am

  2. Thanks for the information. I can now make calls between my computers. But how do I make outgoing calls using VoIP provider.

    Comment by Milind lokde — March 10, 2009 @ 2:55 pm

  3. Hi Milind.

    Take this entry from extension.conf from one of the Asterisk configurations I maintain using babytel as a VoIP provider:

    exten => _NXXXXXX,1,Set(CALLERID(name)=HRSG 6131234567)
    exten => _NXXXXXX,2,Set(CALLERID(number)=6131234567)
    exten => _NXXXXXX,3,Dial(SIP/613${EXTEN}@sip.babytel.ca,300,r)

    This example handles 7 digit dialing, prefixing the outgoing call on ,3 with 613.

    You’ll need to have an entry in “sip.conf” to handle the registration and configuration of the provider. In this case it’s like

    [general]
    register => 16131234567:secret:16131234567@sip.babytel.ca:5065/0

    and

    [sip.babytel.ca]
    context=mycontext
    type=peer
    disallow=all
    allow=g729
    allow=gsm
    allow=ulaw
    secret=secret
    username=16131234567
    host=sip.babytel.ca
    port=5065
    fromuser=16131234567
    fromdomain=sip.babytel.ca
    insecure=very
    nat=no
    canreinvite=no

    Hope this helps.

    Comment by Paul Skinner — March 10, 2009 @ 3:37 pm

  4. Hi, i have well installed OpenIMS Core and X_Lite but can’t get connected. if you can tell me what configuration should i make.
    Note, both OpenIMS Core and X_Lite are installed on the same desktop Ubuntu 8.04 (Hardy)

    Comment by josefbr — July 7, 2009 @ 3:05 am

  5. Its really nice one for startup.

    Comment by kalpesh jain — October 2, 2009 @ 7:42 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.