Vous êtes sur la page 1sur 10

Asterisk Advanced

Lab Assignment
Module 4

Building A Basic PBX

– Extensions
– SIP Phones
– Configuration Files
4.1 - Building A Basic PBX With Two Extensions
Module 4 – Lab 1
Time Limit: 50 Minutes
The goal of this lab is to create a very simple PBX with two extensions which are capable of calling
each other. In order to do this you will need to do some more exploring in the Linux command
shell (also referred to as the 'Unix Prompt'). Relax. This is another of the step-by-step labs (but
don't forget – tougher labs are on their way).

In the next several steps you will not only set up Asterisk to include a very basic set of PBX
services, but you will also install and activate both a SIP soft-phone (a 'virtual' phone which runs on
your Linux desktop) and also a Polycom SIP phone. If you've never done any kind of network or
hardware installation, please ask the instructors to give you a hand.

This lab is also the point at which we will introduce the first two of three fictitious users who we
will be using throughout the course: Tom Smith and Joe Jones. Tom and Joe are two typical PBX
users. Tom will be using the Xlite Soft Phone and will be assigned extension 6001. Joe will be
using the Polycom phone and will be assigned extension 6002.

Step 1: Editing Your sip.conf File

Open a terminal window on your Linux system. To open a terminal, click on the “Applications”
menu, select “System Tools” then “Terminal”. The terminal will start a command shell in your
home directory (/root).

Use the change directory command – cd – to change to the Asterisk configuration directory:

# cd /etc/asterisk

Use the Linux directory listing command – ls – to have a look around:

# ls

Linux will display a long list of files, most of which end in “.conf”. These are the infamous Asterisk
configuration files. Over the rest of the course you will become familiar with many of them.

Now, use your favorite editor1 (vi, nano or gedit) to edit the SIP configuration file.

We've taken the liberty of simplifying several of the sample configuration files to prevent confusion
(the samples document virtually every feature, function and option related to the module it serves,
so some – including sip.conf – are necessarily very complex and difficult to read). Please replace
the supplied sip.conf by creating an initial sip.conf file as follows, or obtain it from your instructor:

1 If you're not a seasoned Linux user, we recommend gedit as it works much like the typical windows/mac text editor or a
very lame word processor. If you're an emacs fan, you're on your own.
4-2 Digium Asterisk Advanced Course © 2008 Digium, Inc
; **************************************************************
; ** GLOBAL SETTINGS FOR THE ASTERISK SIP CHANNEL v 1.6

[general]
context=default ; Default context for incoming calls
realm=class.digium.com ; Realm for digest authentication
bindport=5060 ; UDP Port to bind
bindaddr=0.0.0.0 ; IP address to bind to (0.0.0.0 binds to all)
srvlookup=yes ; Enable DNS SRV lookups on outbound calls
disallow=all ; First disallow all codecs
allow=ulaw ; Allow codecs in order of preference
allow=gsm
language=en ; Default language

; **************************************************************
; ** REGISTER STATEMENTS

; **************************************************************
; ** FRIENDS, USERS AND PEERS BELOW THIS LINE...

To add accounts for your two phones, move your cursor into the bottom section of the file (below
the line that says “FRIENDS, USERS AND PEERS BELOW THIS LINE…” ) and add the following:

[ts_xlite] ; (Tom Smith's Xlite Phone).
type = friend
host = dynamic
secret = xlite
context = users

[jj_polycom] ; (Joe Jones' Polycom Phone).
type = friend
host = dynamic
secret = polycom
context = users

NOTE: In place of the initials of the fictitious users, PLEASE use YOUR OWN initials. If everyone in
the class uses the same “ts” and “jj” initials, it will make debugging problems difficult if one of
your fellow students enters your computer's IP address into a phone instead of his.

© 2008 Digium, Inc Digium Asterisk Advanced 4-3


After you edit the file, it should look like this:

; **************************************************************
; **  GLOBAL SETTINGS FOR THE ASTERISK SIP CHANNEL – v 1.4

[general]
context=default          ; Default context for incoming calls
realm=class.digium.com   ; Realm for digest authentication
bindport=5060            ; UDP Port to bind
bindaddr=0.0.0.0         ; IP address to bind to (0.0.0.0 binds to all)
srvlookup=yes            ; Enable DNS SRV lookups on outbound calls
disallow=all             ; First disallow all codecs
allow=ulaw               ; Allow codecs in order of preference
allow=gsm
language=en              ; Default language 

; **************************************************************
; **  REGISTER STATEMENTS

; **************************************************************
; **  FRIENDS, USERS AND PEERS BELOW THIS LINE...

[ts_xlite] ; (Tom Smith).
type = friend
host = dynamic
secret = xlite
context = users

[jj_linksys] ; (Joe Jones).
type = friend
host = dynamic
secret = linksys
context = users

Now save the file and exit the editor.

Step 2: Reloading Asterisk's SIP Configuration

Before Asterisk will recognize the new SIP accounts, you will have to reload the SIP configuration.
To do this, log into Asterisk and execute a SIP reload:

# asterisk –r
CLI> sip reload

Check the configuration using the sip show peers command:

CLI> sip show peers
Name/username              Host            Dyn Nat ACL Port     Status
jj_polycom                (Unspecified)    D          0        Unmonitored
ts_xlite                  (Unspecified)    D          0        Unmonitored
2 sip peers [2 online , 0 offline]

You can further check the status using the sip show users command:

www*CLI> sip show users
Username       Secret      Accountcode      Def.Context      ACL  NAT
jj_polycom     polycom                      users            No   RFC3581
ts_xlite       xlite                        users            No   RFC3581

Now that you have confirmed that the SIP accounts are loaded, you can exit the CLI:
4-4 Digium Asterisk Advanced Course © 2008 Digium, Inc
CLI> exit

The system will load the new SIP configuration from the sip.conf file. IMPORTANT NOTE: if you
make a change to a SIP device which is already registered to Asterisk, the change will NOT take
place until you restart Asterisk or until the device un-registers and the SIP configuration is
reloaded.

Step 3: Creating The Extensions

Now that you have the SIP accounts created and loaded, you need to add extensions which send
calls to the accounts. To do this, you need to edit the extensions.conf file. To do so, make sure
that your command shell is in the /etc/asterisk directory and do the following:

# gedit extensions.conf &

Please remove (or rename) the existing extensions.conf file and create a new extensions.conf file
as follows or obtain it from your instructor:

; **************************************************************
; **  GENERAL SETTINGS FOR EXTENSIONS

[general]
static=yes
writeprotect=no
autofallthrough=yes
clearglobalvars=no
priorityjumping=no

; **************************************************************
; **  GLOBAL VARIABLES

[globals]

; **************************************************************
; **  EXTENSION CONTEXTS BELOW HERE

[users]

To add your new extensions, place your cursor just below the context header [users] and add the
extensions. Your extensions should look like this:

; **************************************************************
; **  EXTENSION CONTEXTS BELOW HERE

[users]

exten => 6001,1,Dial(SIP/ts_xlite,20)
exten => 6002,1,Dial(SIP/jj_polycom,20)

Now save your file and return to the command line. Once again Asterisk requires a reload in order
to notice the change. To reload the extension configuration, log back into Asterisk and execute an
extensions reload:

# asterisk –vvvr

© 2008 Digium, Inc Digium Asterisk Advanced 4-5


cli> dialplan reload

To check the resulting configuration, use the dialplan show command:

cli> dialplan show users

Asterisk should respond with:

[ Context 'users' created by 'pbx_config' ]
  '6001' =>          1. Dial(SIP/ts_xlite|20)               [pbx_config]
  '6002' =>          1. Dial(SIP/jj_polycom|20)             [pbx_config]
­= 2 extensions (2 priorities) in 1 context. =­
CLI>

You can now exit the CLI with the exit command:

cli> exit

Step 4: Configuring X-Lite

Now that Asterisk has a valid configuration for both phones, you need to configure the phones to
talk to Asterisk. In order to do that, you need to know the IP address of your Asterisk computer.
To get the IP address on a Linux machine, use the ifconfig command:

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:E0:4C:7C:64:27
          inet addr:66.28.144.174  Bcast:66.28.144.255  Mask:255.255.255.0
          inet6 addr: fe80::2e0:4cff:fe7c:6427/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:24697687 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6680623 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1921062384 (1.7 GiB)  TX bytes:564265849 (538.1 MiB)
          Interrupt:201 Base address:0xa000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:5395539 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5395539 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1364198988 (1.2 GiB)  TX bytes:1364198988 (1.2 GiB)

Note the highlighted value – that’s the computer’s IP address. (Yours will, of course, be different.)
Write down your system’s IP address here:

My Computer's IP Address: ________________________________________

Now, you need to open up the X-Lite soft phone and configure it to connect with your Asterisk. X-
Lite should already be installed on your computer's desktop. Simply open the Xten X-Lite folder
and double-click the X-Lite icon to start the program.

X-Lite will take you through an audio tuning wizard to set up your handset (or headset). Be sure
that your handset is plugged in and that you have adjusted the audio configuration on Linux to
enable the microphone and speakers.

LINUX AUDIO ODDITY: With a new Linux installation you will have to un-mute the audio devices you
wish to use! To do this, right-click on the audio icon in the upper-right-hand corner of the screen
and select “Sound Settings”. When the sound mixer application opens, un-mute and adjust your
audio controls as necessary. Note that different audio configurations will have dramatically
different sound control panels, and you may need to experiment.

4-6 Digium Asterisk Advanced Course © 2008 Digium, Inc


Once the Audio Tuning Wizard is complete, X-Lite will display the phone application and check
local network conditions. It should automatically open the configuration menu and allow you to
configure your SIP account. If not, click on the menu button as shown below:
Click here to open the
configuration for X-Lite.

Use the following settings:

Enabled: Yes (click to set)


Display Name: Tom Smith
Username: ts_xlite
Authorization User: ts_xlite
Password: xlite
Domain/Realm: class.digium.com
SIP Proxy [your IP]
Outbound Proxy [your IP]

Now click the menu button on the phone again to close the menu. X-Lite will save the settings and
attempt to register with your Asterisk. If it encounters problems (login failure, etc.) it will pop the
configuration window open again, allowing you to make changes.

FIRST COME FIRST SERVE: When an application that uses the TCP/IP network services on your
computer starts up, it may attempt to ope a particular TCP/IP port to listen for incoming
connections. If that port is already in use, the operating system will deny the application access.
In the case of X-Lite, this is a factor as both Asterisk and X-Lite attempt to use the SIP port (5060).

If Asterisk starts first, this is not a problem: X-Lite simply takes the next port (5061). However, if
you start Asterisk AFTER X-Lite, things just won't work: X-Lite will have opened 5060 and Asterisk
will not be able to load the SIP channel. To prevent this from ever happening, navigate to the
Network Settings option under System Settings and change the Listen SIP Port to something
different, like 5070. That way if you accidentally start X-Lite first, it won't steal the critical SIP
port.

If you have brought a laptop to class, it may be much easier to run X-Lite on your laptop rather
than on your Linux system. Or, if you have brought a WiFi SIP phone with you, you may wish to
configure it in place of the X-Lite phone.

Step 5: Configuring the Polycom Soundpoint Phone

Once you have the Polycom phone unpacked and installed on your desktop, plug in the power and
give it roughly three minutes to complete its initial boot cycle. Once the phone is active you will
need to use the on-screen menu system to retrieve its IP address.

© 2008 Digium, Inc Digium Asterisk Advanced 4-7


Press the menu button to access
the on-screen menu system.

Press 2 to access the “Status” menu. Press 2 again to access the “Network” menu. Press 1 to
access the “TCP/IP Parameters” list. The phone’s IP address is listed as “IP” and is the first item
in the list of network values. Write down your phone’s IP address below:

My Phone’s IP Address: _________________________________________________

Now, we need to access the phone with the browser. To do so, open your browser (you can launch
it from the “Internet” options of the “Application” menu or by the globe icon on the task bar).

Browse to your phone’s administration page by typing the following in the browser’s address
window: http://192.168.101.XXX [Replace XXX with the last octet of the phone's IP address].

To change the settings for the phone, click the “Lines” link in the menu. If the phone has security
enabled it will challenge you for a user name and password. Use the defaults:

Username: Polycom
Password: 456

The system will then display the full configuration menu. Now we will need to set up the phone’s
account and make a few other minor tweaks.

TWO LINES? The Polycom Phone is considered a two-line phone. In reality, SIP phones don't
conform to the traditional concept of “Lines”. The phone actually supports two “call appearances”
using the two buttons and LED pairs on the right-hand side of the display. The appearances can be
connected to two different servers or to two different accounts on the same server. In this case,
we will set both appearances to use the same account on the same server (your Asterisk).

4-8 Digium Asterisk Advanced Course © 2008 Digium, Inc


Configure your phone as shown above. Set the “Auth Password” field to “polycom” (without the
quotes). Once you have the values for the “Identification” section set, scroll down to the “Server
1” section.

Replace the “XXX” with the last octet of your Asterisk server's IP address, NOT THE PHONE'S
ADDRESS!!!

Scroll down to the settings for Line 2 (skip the “Server 2” section for Line 1). Repeat the process
above with the same values. Both Line 1 and Line 2 should be configured identically. When you
have this done, save your changes by clicking either of the “Submit” buttons located on the page.

OTHER POLYCOM SETTINGS: You may also want to go to the General options page and set the time
synchronization server (time-b.nist.gov is a valid SNTP server name) and the GMT offset. If
daylight savings time is active in your area, feel free to set that as well.

© 2008 Digium, Inc Digium Asterisk Advanced 4-9


The phone will store the changes and execute a reboot. It will display the page above. The reboot
process usually takes between 1 and 2 minutes to complete. When complete, the phone will
attempt to register with your Asterisk.

Step 6: Making Calls

Test your installation. You should be able to call 6001 and ring the X-Lite phone (from the
Polycom), or 6002 and ring the Polycom phone (from X-Lite). Note that if you dial from the X-Lite
to extension 6001 a second appearance will ring on your X-Lite phone. The same will occur on the
Polycom if you dial 6002.

Summary:

You learned the following:

1. How to edit configuration files.


2. How to add basic SIP accounts for phones.
3. How to add basic extensions for phones.
4. How to reload Asterisk after changes have been made.
5. How to configure your X-Lite soft phone.
6. How to configure your Polycom SIP desk phone.

4-10 Digium Asterisk Advanced Course © 2008 Digium, Inc

Vous aimerez peut-être aussi