Training: Install Asterisk, Call between 2 accounts

Created by Nicolas Bondier on 2011-03-14

Edited by Pedro Geraldo on 2019-07-05

Table of Contents

Introduction. 1

Requirements. 1

Training session. 1

Install Asterisk. 1

Configure accounts. 1

Presentation. 1

Description of sip.conf. 1

Description extensions.conf. 1

Explanations of the processing. 1

Configuration of sip.conf. 1

Configuration of extensions.conf 1

Configure phones. 1

Validation. 1

Clean the Server. 1

Validation. 1

References. 1

End of document. 1

Introduction

In this training, you will learn how to install an Asterisk server on a Debian distribution and configure two user accounts with two phone or softphone.

Requirements

·         SSH connection training

·         Simple Unix Bash commands

·         Vi editor, basic commands training

Training session

Install Asterisk

Check if the server is not reserved by other employees (search for “locked 213.251.170.99” mention on the training session page).

If the server is not locked, lock it by indicating that you are processing this training with keyword “locked 213.251.170.99”.

Screenshot - 15

Connect to the OVH’s administration interface.

The account information is available here: http://switzernet.com/3/support/101101-files/101101-ovh-training-account.txt

Find the email with the password obtained after the last installation for the server “ks34280.kimsufi.com”. The email is available under Administration->My Settings->Email Summary. Login to the server as a root, via ssh. Then check what version of Linux is installed on the server:

ks24727:~# cat /proc/version

You should have Debian. If not, you should install Debian before proceeding with the current training session. Installation of Debian is described in the training: http://www.unappel.ch/2/support/110222-ovh-debian/i/. Once Debian installation is finished, find the email with the password obtained after the last installation for the server “ks34280.kimsufi.com”. The email is available under Administration->My Settings->Email Summary.

Begin by updating the list of available packages from the aptitude sources:

$ apt update

And upgrade all your installed packages to the most recent version:

$ apt upgrade

Next, if you didn’t reinstall Debian, make sure there is not a previous install of Asterisk on the server, we need a clean install. Just check if /etc/asterisk is present:

$ ls /etc/asterisk

If yes, run the following command:

$ apt purge asterisk

Once these steps are done, install Asterisk using aptitude, which will search and install all packages dependencies needed to perform the installation and permit Asterisk to work.

$ aptitude install asterisk

After the installation is finished, Asterisk will be launched. In case of it is not launched, you can anyway launch it this way:

$ asterisk start

There is a console interface for controlling Asterisk called the CLI prompt. You can connect to the CLI prompt of Asterisk with this command:

$ asterisk -r

In the CLI prompt interface, you can visualize everything about the running Asterisk server and make lot of settings. To display the help screen of the CLI to see all the possible commands, type:

>help

Your Asterisk Server is now installed and running. But there is no SIP account for clients.

Configuring asterisk

The next step is to configure two new accounts but, before we configure them, we must understand what configuration files we need to edit. There are three configuration files that will be used for configuring calls between accounts:

·         users.conf         -> Where we will configure the users or phones that will be able to make and receive calls;

·         sip.conf             -> Where we configure the SIP channel with either global or phone/user specific configurations;

·         extension.conf -> Where we configure the dialplan of calls;

users.conf

To add sip account in asterisk you must edit users.conf.

nano /etc/asterisk/users.conf

Here’s a sample of a user configuration.

[6000]

fullname = Joe User

description = Courtesy Phone In Lobby      ; Used to provide a description of the

                                           ; peer in console output

email = joe@foo.bar

username = joeuser

secret = 1234

host = dynamic

context = yourcontext                     ; this is the context that the user will

                                          ; use to route its calls

dahdichan = 1

hasvoicemail = yes

hassip = yes                              ; this will indicate if the user uses sip

hasiax = no                               ; this will indicate if the user uses iax

hash323 = no                              ; this will indicate if the user uses h232

hasmanager = no

callwaiting = no

There are some options that can be set in the [globals] section so that you only need to configure it once, but only if all users will use the same properties, ex: all users will communicate through SIP, will use the same context and the same codecs.

You can verify if your users have been created by starting the Asterisk CLI and type:

$ asterisk -r

Asterisk CLI>sip show users

<or>

$ asterisk -x ‘sip show users’

Description of sip.conf

This is the file defining all the SIP channel configurations. It is segmented by sections; each one begins with a label which have this syntax:

[general]

type=peer

context=context_for_all_others

canreinvite=no

qualify=yes

allowoverlap=no

 

udpbindaddr=0.0.0.0

tcpenable=no

tlsenable=no

transport=udp

 

rtignoreregexpire=yes

rtptimeout=180

 

srvlookup=yes

maxexpiry=360

minexpiry=60

defaultexpiry=120

 

disallow=all                    ; First disallow all codecs

allow=ulaw                      ; Allow codecs in order of preference

allow=ilbc                      ; see https://wiki.asterisk.org/wiki/display/AST/RTP+Packetization

allow=alaw

allow=g729

allow=g723

allow=gsm

allow=speex

allow=slin

allow=g726

 

[authentication]

 

You can find parameters for ‘sip.conf’ in these documents:

-          Tιlιphonie sur IP from Laurent Ouakil (on page 342-343).

-          Asterisk, the future of Telephony from O’Reilly publication (pages 350 to 380).

Description extensions.conf

Once the user is defined and numbers, we must set the procedure that will be launched when this number will be joined.

This is called the dial plan and it is set-up in the ‘extensions.conf’ configuration file.

The file is also constructed with labels.

The first one, [general] is used for general settings, the second [global] is used for global variables. These two labels must be always present.

Next labels are the contexts labels referring to the context field of sip.conf and are the procedures to follow.

Explanations of the processing

Let’s imagine a phone that number1 is calling number2 and number3 is calling number2:

Asterisk search in sip.conf if number1 is present. If yes, it will refer to the rules in extensions.conf corresponding to number1’s context. If not, it will go to the context of [general].

Configuration of sip.conf

Now, you will configure two new accounts on your Asterisk server. First, open a new ssh connection on the Asterisk server,go the main folder of Asterisk configuration files and watch what is inside:

$ cd /etc/asterisk/

$ ls

Move all configuration files of ‘/etc/asterisk/’ in a new folder ‘/etc/asterisk/asterisk_save/’, we will use our own configuration files.

$ mkdir /etc/asterisk_save/

$ mv /etc/asterisk/* /etc/asterisk_save/

$ mv /etc/asterisk_save /etc/asterisk/

Now download the prepared configuration files and decompress them:

$ cd /etc/asterisk/ #to be sure you are still in etc/asterisk/

$ wget http://www.unappel.ch/2/public/110314-conf-for-asterisk-training1/confAsterisk.tar

$ tar –xvf confAsterisk.tar

You now have custom configuration files to fill in your /etc/asterisk/ directory. They are already commented to help you in your configurations.

First open the /etc/asterisk/sip.conf file to setup users accounts.

$ vi /etc/asterisk/sip.conf

In this file, [general] is set-up. You only must configure user accounts.

Replace [number1] by the six last numbers of your Switzernet number phone (this is for the validation) and [number2] by a number at this format “yymmdd” corresponding of the date of the day when you pass the training.

You can find how to fill the other parameters in the documentation given before. For context, choose a world that means that the call will be routed. For example: “routing”. Be inventive. The two accounts must have the same context.

Notice that there is 3 type of account. You must choose the good one and to know why.

Set the 3 missing fields for each account:

type=

context=

host=

Configuration of extensions.conf

Once your accounts are configured, we must set rules in ‘extensions.conf’.

$ vi /etc/asterisk/extensions.conf

The file is partially filled. You can read the corresponding comments of every line already completed.

The missing setups are the settings of your new context. First, you must replace the [newcontext] field by the name you gave to context= in sip.conf.

sip.conf

extensions.conf

context=yournewcontext

[yournewcontext]

Therefore, you must set up the extensions which are the rules followed by Asterisk when this context is called.

The syntax of an extension can be found here:

- Tιlιphonie sur IP, page 331.

For each account, create a new extension in [yournewcontext]

The rules you have to set up for each one are:

- If number1 is entered on the phone, the first thing to do is: Dial number1.

- If number2 is entered on the phone, the first thing to do is: Dial number2.

To help, the page of the Tιlιphonie sur IP document where you can find corresponding examples is the 335, example2.

Once your files are edited go to the CLI prompt of Asterisk and to tell to Asterisk to reload his memory and take into consideration the new configurations files. This reload have to be done each time you change something in the configurations files if you want Asterisk to update the new settings:

>module reload

Check if your users have been saved:

CLI> sip show users

Here is an exemple :

Screenshot - 11

Configuration of users.conf

To add sip account in asterisk you must edit users.conf and extension.conf to add new users and their credentials.

΄nano /etc/asterisk/users.conf΄

Here’s a sample of a user configuration.

You can verify if your users has been created by starting the Asterisk CLI and type:

΄sip show users΄

This command listed the active users.

Configure phones

You should now have two accounts well configured with the corresponding extensions when a call is passed.

Let’s configure the phones.

As I expect you don’t have two SIP phones, we will use a softphone (x-lite) and a normal SIP phone.

Fill the field in the applications/phone with these examples. Even if we didn’t define any secret (=password), in the accounts in sip.conf, we must fill the “password” field with a random password.

(If the softphone/SIP phone doesn’t send a password, it will automatically be registered as “guest” by Asterisk. We didn’t set any “guest” account with a context to follow).

Configure the phones with your own configuration according to your configuration files. Do not configure with the same account names/passwords/servers shown in these examples.

Here is the configuration of x-lite for windows 7/vista

for Windows XP.

Configuration of your SIP phone (example for spa921). If you don’t have this model, configure it according to our support page: http://switzernet.com/public/070723-config_UA/

When you save the configuration, you can see if your device is registering to the Asterisk Server, to do that, enter the following command in the CLI prompt

>sip show peers

Example of result:

Screenshot - 14

You can also see details on the new peer with this command:

> sip show peer username

With username is the name of the peer.

If you don’t see your SIP peers here, so they are not registered. Try to reboot them and wait ~1 minute to see if they register.

If not, this is because the sip.conf file or your SIP peers are not configured correctly.

Try to resolve your problems by verify your configurations files with this training, and your device according to the support documentation.

In case of you unable to pass calls. Verify configuration of peers, sip.conf, extension.conf. Note that it can take few minutes to register a peer.

Validation

- Make a screenshot of the result of the command:

> sip show peers

The title of this screenshot is “List of peers”.

- On the Asterisk Server, we will catch sip packets from and to the caller phone and filter the result to see only the kind of packet. Make the following ngrep:

ngrep -pql -W byline host ipofthecallerphone and port 5060| grep -B1 -i 'SIP/2.0[ \.]'

Where ipofthecallerphone is the ip address of the phone one witch you are calling. You can view this IP address in the “sip show peers” command see above. Here you can see the example with the phone 333 calling the 111.

(The “| grep …” is used to choose only the line we are interested in. Here the line must contain the char “SIP/2.0” or “SIP/2.0.” where the message type is indicated)

Pass a call from the phone to your softphone and decline the call on the called device.

In the window running the ngrep, you should see something like the picture below. Make a print screen and copy it in your validation document. Surround in red the message fields as done in this document.

The title of this print screen is “Calling, ngrep”.

- Make a drawing like this one, to explain exchanges between the Asterisk Server and the caller phone according to the screenshot you just done.

Paste this drawing in your validation document.

The title of this drawing is “Calling, timeline”.

 

- Make a print screen of your “sip.conf” configuration file and paste it in your validation document with title “sip.conf”.

- Make a print screen of your “extensions.conf” configuration file and paste it in your validation document with title “extensions.conf”.

Clean the Server

Once you have ended the training and finished your validation document, uninstall Asterisk for the next people who will do this training session.

$ aptitude purge asterisk

You can know log off from the server.

Validation

Follow the training session. Make the test described during the training; use the current date and your name while processing with the test. Make the 5 print screens corresponding as asked in the training:

- List of peers

- ngrep of a call

- Timeline of a call

- sip.conf

- extensions.conf

Prepare a rapport. Your rapport should have a title, header (author name, date), short description of what you have done and the five print screens. Pay attention to styles in the MS Word document.

Name your rapport in the following format: yymmdd-lastname-asterisk-install.doc where yymmdd is the current date, last name is your last name.

Upload the rapport on the training session web site, according to the guidelines.

References

Training sessions: http://www.unappel.ch/2/support/100722-training-employees/i/

SIP: http://fr.wikipedia.org/wiki/Session_Initiation_Protocol

Asterisk, the furure of telephony: http://downloads.oreilly.com/books/9780596510480.pdf

Tιlphonie sur IP: http://actudz.files.wordpress.com/2011/02/telephonieip.pdf

VOIP: http://fr.wikipedia.org/wiki/Voip

ngrep: http://linux.die.net/man/8/ngrep

grep: http://pwet.fr/man/linux/commandes/grep

End of document

*   *   *

© 4z.com