Asterisk installation and basic configuration

André Guimarães 2011-07-15

Switzernet

 

This document describes how to install Asterisk 1.4.21 on Debian Lenny.

 

Installation

 

Access the server where you going to install asterisk. Log in as root.

 

All commands should be executed as root. To show this all commands are preceded by a hash (#).

 

Execute as root the following command (the result should be similar to the lines that follow it):

 

# apt-get update

Hit ftp://mirror.ovh.net lenny Release.gpg

Get: 1 ftp://mirror.ovh.net lenny/main Translation-en_GB

Hit http://security.debian.org lenny/updates Release.gpg

Ign http://security.debian.org lenny/updates/main Translation-en_GB

Ign http://security.debian.org lenny/updates/contrib Translation-en_GB

Ign ftp://mirror.ovh.net lenny/main Translation-en_GB

Ign http://security.debian.org lenny/updates/non-free Translation-en_GB

Hit http://security.debian.org lenny/updates Release

Get: 2 ftp://mirror.ovh.net lenny/contrib Translation-en_GB

Ign ftp://mirror.ovh.net lenny/contrib Translation-en_GB

Get: 3 ftp://mirror.ovh.net lenny/non-free Translation-en_GB

Ign http://security.debian.org lenny/updates/main Packages/DiffIndex

Ign ftp://mirror.ovh.net lenny/non-free Translation-en_GB

Ign http://security.debian.org lenny/updates/contrib Packages/DiffIndex

Ign http://security.debian.org lenny/updates/non-free Packages/DiffIndex

Hit ftp://mirror.ovh.net lenny Release

Ign http://security.debian.org lenny/updates/main Sources/DiffIndex

Ign http://security.debian.org lenny/updates/contrib Sources/DiffIndex

Ign http://security.debian.org lenny/updates/non-free Sources/DiffIndex

Hit http://security.debian.org lenny/updates/main Packages

Hit http://security.debian.org lenny/updates/contrib Packages

Hit http://security.debian.org lenny/updates/non-free Packages

Hit http://security.debian.org lenny/updates/main Sources

Hit http://security.debian.org lenny/updates/contrib Sources

Hit http://security.debian.org lenny/updates/non-free Sources

Get: 4 ftp://mirror.ovh.net lenny/main Packages/DiffIndex

Ign ftp://mirror.ovh.net lenny/main Packages/DiffIndex

Get: 5 ftp://mirror.ovh.net lenny/contrib Packages/DiffIndex

Ign ftp://mirror.ovh.net lenny/contrib Packages/DiffIndex

Get: 6 ftp://mirror.ovh.net lenny/non-free Packages/DiffIndex

Ign ftp://mirror.ovh.net lenny/non-free Packages/DiffIndex

Get: 7 ftp://mirror.ovh.net lenny/main Sources/DiffIndex

Ign ftp://mirror.ovh.net lenny/main Sources/DiffIndex

Get: 8 ftp://mirror.ovh.net lenny/contrib Sources/DiffIndex

Ign ftp://mirror.ovh.net lenny/contrib Sources/DiffIndex

Get: 9 ftp://mirror.ovh.net lenny/non-free Sources/DiffIndex

Ign ftp://mirror.ovh.net lenny/non-free Sources/DiffIndex

Hit ftp://mirror.ovh.net lenny/main Packages

Hit ftp://mirror.ovh.net lenny/contrib Packages

Hit ftp://mirror.ovh.net lenny/non-free Packages

Hit ftp://mirror.ovh.net lenny/main Sources

Hit ftp://mirror.ovh.net lenny/contrib Sources

Hit ftp://mirror.ovh.net lenny/non-free Sources

Reading package lists... Done

 

Install the asterisk package on the repository:

 

# apt-get install asterisk

 

After the installation, backup the default configuration files as follows.

 

# mkdir /etc/asterisk/samples

# cp /etc/asterisk/*.* /etc/asterisk/samples

 

Replace the content of the file /etc/asterisk/extensions.conf by the content in this sample file extensions.conf.

 

Do the same for the file /etc/asterisk/sip.conf.

 

To edit these files you can use nano:

 

# nano /etc/asterisk/extensions.conf

# nano /etc/asterisk/sip.conf

 

In the file /etc/asterisk/extensions.conf create as many lines as needed for each phone and alternative address.

 

In the following example line, hardphone1 is the login of the phone and 100 is its alternative address.

 

exten => 100,1,Goto(hardphone1,1)

 

This next line routes an incoming call to hardphone1 to this phone and hangups in 30 seconds if no one answers.

 

exten => hardphone1,1,Dial(SIP/hardphone1,30)

 

 

 

Now execute the following to reload the configurations that were changed:

 

# asterisk -rx "sip reload"

# asterisk -rx "dialplan reload"

 

The above lines should be executed everytime sip.conf or extensions.conf are changed.

Registering phones

 

Example registration with X-Lite:

 

 

Example registration with a Linksys SPA921:

 

Testing

 

After registering the phones you can see if the registrations were successful by typing:

 

# rasterisk -x "sip show peers"

Name/username              Host            Dyn Nat ACL Port     Status

softphone1/softphone1      212.147.8.99     D   N      62887    Unmonitored

hardphone1/hardphone1      (Unspecified)    D   N      0        Unmonitored

2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 1 online, 1 offline]

 

In the above example softphone1 registered successfully (it has an IP in the Host  column and a port different than 0 in the Port column), while hardphone1 is not registered (it appears Unspecified in the Host column).

 

You can increment the verbosity of asterisk to be able to see the calls flowing in your asterisk. In the following example you can see a successful call from hardphone1 to softphone1.

 

# asterisk -rx "set verbose 3"

# rasterisk

    -- Executing [hardphone1@routing:1] Dial("SIP/hardphone1-007f1490", "SIP/softphone1|30") in new stack

    -- Called softphone1

    -- SIP/softphone1-007f57d0 is ringing

    -- SIP/softphone1-007f57d0 answered SIP/hardphone1-007f1490

    -- Packet2Packet bridging SIP/hardphone1-007f1490 and SIP/softphone1-007f57d0

  == Spawn extension (routing, 101, 1) exited non-zero on 'SIP/hardphone1-007f1490'

 

You can also use ngrep to see if packages are coming and going to the phones. You can see a trace with ngrep for the call above here.

 

To install ngrep run the command:

 

# apt-get install ngrep