/etc/asterisk
directory:debian:/usr/src# cd /etc/asterisk debian:/etc/asterisk# ls adsi.conf cdr_tds.conf indications.conf privacy.conf adtranvofr.conf codecs.conf logger.conf queues.conf agents.conf dnsmgr.conf manager.conf res_odbc.conf alarmreceiver.conf dundi.conf meetme.conf rpt.conf alsa.conf enum.conf mgcp.conf rtp.conf asterisk.adsi extconfig.conf misdn.conf sip.conf asterisk.conf extensions.ael modem.conf sip_notify.conf cdr.conf extensions.conf modules.conf skinny.conf cdr_custom.conf features.conf musiconhold.conf telcordia-1.adsi cdr_manager.conf festival.conf osp.conf voicemail.conf cdr_odbc.conf iax.conf oss.conf vpb.conf cdr_pgsql.conf iaxprov.conf phone.conf zapata.conf debian:/etc/asterisk#
make samples
to /etc/asterisk/backup/
(so that we might retrieve
them for later use; it is generally a good practice to copy original
files to a backup directory when you are making changes):debian:/etc/asterisk# mkdir backup debian:/etc/asterisk# mv sip.conf backup/ debian:/etc/asterisk# mv extensions.conf backup/ debian:/etc/asterisk#
[general] port = 5060 bindaddr = 0.0.0.0 context = others [2000] type=friend context=my-phones secret=1234 host=dynamic [2001] type=friend context=my-phones secret=1234 host=dynamic
/etc/asterisk/extensions.conf
:[others] [my-phones] exten => 2000,1,Dial(SIP/2000) exten => 2001,1,Dial(SIP/2001)
asterisk
-c
:debian:/etc/asterisk# asterisk -c Asterisk 1.4.2, Copyright (C) 1999 - 2005 Digium. Written by Mark Spencer <markster@digium.com> ========================================================================= [ Booting...Nov 20 18:59:28 NOTICE[14937]: cdr.c:1185 do_reload: CDR simple logging enabled. ......................................................................... ............................................... ] Asterisk Ready. *CLI>
stop now
:*CLI> stop now debian:/etc/asterisk#
/etc/asterisk/sip.conf
. SIP
extension 2000 must be configured this way:debian:/etc/asterisk# ifconfig | grep Bcast | sed s/Bcast.*// inet addr:23.3.19.73
23.3.19.73
.-vvvvvc
after
the command (the 5 v's mean “verbosity level 5”). This will
let us see when the SIP phone registers with the PBX:debian:/etc/asterisk# asterisk -vvvvvc [...] Asterisk Ready. *CLI>
*CLI> -- Registered SIP '2000' at 87.143.3.144 port 5060 expires 120 -- Unregistered SIP '2000' *CLI> -- Registered SIP '2001' at 87.143.3.145 port 5060 expires 120 -- Unregistered SIP '2001'
sip show peers
in the Asterisk CLI. This will
give you a list of all the configured and registered SIP phones.
With sip show peer 2000
you will get much more
detailed information about SIP extension 2000.stop
now
in the Asterisk CLI./etc/asterisk/voicemail.conf
before we can use it.
As a first step (which you should make a routine) we copy the default
files into our previously created backup directory:debian:/# cd /etc/asterisk debian:/etc/asterisk# mv voicemail.conf backup/
/etc/asterisk/voicemail.conf
and type the following
into it:[general] format = wav [default] 2000 => 4711,Joe Bloggs,joeb@megacorp.biz 2001 => 0815,Darlene Doe,dard@megacorp.biz
/etc/asterisk/extensions.conf
to tie these
mailboxes to our phones and make them accessible. Make sure to add the
",20"
at the end of the Dial()
command:[others] [my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u) exten => 2001,1,Dial(SIP/2001,20) exten => 2001,2,VoiceMail(2001,u) exten => 2999,1,VoiceMailMain(${CALLERID(num)},s)
asterisk
-vvvvvc
reload
is sufficient.Dial()
command), the call is sent to voicemail. If extension 2000 is busy, the
call goes directly to voicemail. You can check for messages at extension
2000 by dialling 2999, which will send you to the voicemail retrieval
menu./etc/asterisk/sip.conf
. This will help us
understand what Asterisk is doing and why.[general] port = 5060 bindaddr = 0.0.0.0 context = others
bindaddr = 0.0.0.0
value tells Asterisk to listen for
connections on all the IP addresses configured on
the system. Most systems will have only a single IP address. If you have
multiple physical or virtual interfaces configured, or even multiple
instances of Asterisk running, and you want to decide which IP addresses
Asterisk will accept connections on, you can specify those addresses
with the bindaddr
value.[2001] type=friend context=my-phones secret=1234 host=dynamic
[2001]
section defines parameters for the 2001
SIP extension. We use a number by convention; though most people expect
extensions to have numbers, SIP extensions can also be defined with an
alphanumeric identifier -- for example, [Reception-1]
. The
parameter type=friend
simply means that this SIP
extension can both accept and make calls.[7]context
. We
are calling the context my-phones
in
/etc/asterisk/extensions.conf
; When we look at that
file in the next section, the application of contexts should become
clearer.secret
value sets a password for the
SIP extension. We use this to prevent an unauthorized device from
registering as extension 2001. It's best to use numbers here, since it's
also easier to enter numbers with most telephone sets. The term
host=dynamic
tells Asterisk that it doesn't matter if the
IP address of the SIP extension 2001 changes./etc/asterisk/extensions.conf
-- known
as the “dialplan” -- is the heart of every Asterisk
configuration (see also Chapter 3, Programming in the dialplan). In
a sense, you can equate them with a switchboard used in early
telephone systems. The dialplan determines which phones can make calls
to other phones, and how.[others]The first section of the configuration is the context
[others]
.
As we are not using it in this example, it can be
empty.[my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u)Asterisk always uses a context when handling a call from one phone to another. The context name is limited only by your imagination, but must be consistent across configuration files. This means that if you refer to a context
my-phones
in /etc/asterisk/sip.conf
,
you must use the same name in the relevant part of
/etc/asterisk/extensions.conf
. This context is critical to
the operation of the phone! It determines what extension numbers can
be dialled and which actions will be allowed.exten => Number,Priority,Application
1
first. The third parameter ("Application
") defines what
Asterisk actually does with the call./etc/asterisk/sip.conf
. In our example, this
context is [my-phones]
. Asterisk uses this context to
decide which set of entries in
/etc/asterisk/extensions.conf
it should use.[my-phones]
in
/etc/asterisk/extensions.conf
, Asterisk
executes the entries matching the dialled number, 2000, in order
of priority. Our example has two matching lines.1
is
executed first, no matter the physical order of the entries. Here,
the entry with priority 1
has the command
Dial(SIP/2000,20)
. The
Dial()
application is run with the parameters given; it looks for the
entry for 2000 in
/etc/asterisk/sip.conf
and
rings it for 20 seconds (hence the ",20
" after
SIP/2000
).Dial()
completes and the priority is increased
by 1.exten
=> 2000,2,VoiceMail(2000,u)
-- is now executed. Asterisk
runs the VoiceMail()
application with the
parameters "2000"
and "u"
.
The "2000"
is for the mailbox number as configured in
/etc/asterisk/voicemail.conf
; the
"u
" tells Asterisk to use the standard "unavailable"
message. By now you've probably figured out that we picked a
number for simplicity's sake; we could just as easily have used
5555
or joebloggs
.exten => 2999,1,VoiceMailMain(${CALLERID(num)},s)
VoiceMailMain()
with the
function ${CALLERID(num)}
as a
parameter. The ${CALLERID(num)}
function returns the number of the calling party. In this way,
VoiceMailMain()
always knows to retrieve messages
for the phone from which it was called. If the parameter is not
supplied, it will ask the caller for the mailbox number. The
",s
" parameter tells VoiceMailMain()
not to ask the caller for a password./etc/asterisk/voicemail.conf
in much the same way
as the dialplan
(/etc/asterisk/extensions.conf
):[general] format = wav [default] 2000 => 4711,Joe Bloggs,joeb@megacorp.biz 2001 => 0815,Darlene Doe,dard@megacorp.biz
[general]
section is where define global
parameters, such as the file format used for saving the voice
messages, are defined. Actual mailboxes are defined in a context
called [default]
; here you see the lines defining the
mailboxes for extension 2000
and 2001
,
complete with passwords (4711
and 0815
).
After the password, there is a field for the name of the mailbox owner
and that person's e-mail address. Messages are attached as WAV-format
files to an e-mail and sent to the intended recipient./etc/asterisk/sip.conf
:[general] port = 5060 bindaddr = 0.0.0.0 context = others register => 5587572:UHDZJD@my-voip-provider.com/5587572 ; ^ ^ ^ ^ ; | | | | ; User Password Provider User [2000] type=friend context=my-phones secret=1234 host=dynamic [2001] type=friend context=my-phones secret=1234 host=dynamic [ext-sip-account] type=friend context=from-voip-provider username=5587572 fromuser=5587572 secret=UHDZJD host=my-voip-provider.com fromdomain=my-voip-provider.com qualify=yes insecure=very nat=yes
5587572
in our example) and password
(UHDZJD
in our example) when you open your
account. Once the SIP account is configured, we still need to add an
entry to /etc/asterisk/extensions.conf
to allow
outgoing calls:[others] [my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u) exten => 2001,1,Dial(SIP/2001,20) exten => 2001,2,VoiceMail(2001,u) exten => 2999,1,VoiceMailMain(${CALLERID(num)},s) exten => _0[1-9].,1,Dial(SIP/${EXTEN}@ext-sip-account)
asterisk -vvvvvc
so that we
get the CLI. Wait a few seconds for the SIP phones to register. Now
simply dial a number. /etc/asterisk/extensions.conf
so that you
don't need to dial the full number for local calls in areas where it
is not normally required.)/etc/asterisk/extensions.conf
:[others] [my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u) exten => 2001,1,Dial(SIP/2001,20) exten => 2001,2,VoiceMail(2001,u) exten => 2999,1,VoiceMailMain(${CALLERID(num)},s) exten => _0[1-9].,1,Dial(SIP/${EXTEN}@ext-sip-account) [from-voip-provider] exten => 18885556266,1,Dial(SIP/2000)
18885556266
is
the PSTN number (also called a DID; more on that later) given to your
account by your SIP provider.[others] [my-phones] exten => 2000,1,Dial(SIP/2000,20) exten => 2000,2,VoiceMail(2000,u) exten => 2001,1,Dial(SIP/2001,20) exten => 2001,2,VoiceMail(2001,u) exten => 2999,1,VoiceMailMain(${CALLERID(num)},s) exten => _0[1-9].,1,Dial(SIP/${EXTEN}@ext-sip-account) [from-voip-provider] exten => 18885556266,1,Dial(SIP/2000,20) exten => 18885556266,2,VoiceMail(2000,u)
[1] Our “Hello World” is even more fun if you have more than one computer connected by a local area network. You can use one computer as the Asterisk server and the others for the softphones.
[2] Here are URLs for a few of the more popular distributions:
[3] The current Debian "stable".
[4] You will need to call up a console window (such as xterm or konsole) if you are using a window manager.
[5] If you haven't yet chosen a favorite editor, we recommend
nano
. In Debian Linux this is installed (as the
root user) with the command apt-get -y install
nano
. You then edit files by invoking nano
filename
. Nano provides a menu of its most important
commands at the bottom of the screen.
[6] The simple passwords depicted here are, of course, only for testing and demonstration purposes. For actual production installations, you should use much stronger passwords.
[7] The entry type=
has three possible values (we'll
address these in more detail in a later chapter):
friend
: can make and accept calls.peer
: can only make calls.user
: can only accept calls.[8] Not too much at once! For now, all you need to know is that
the ${EXTEN}
variable always contains the number
dialled by the caller for the specific instance (see Chapter 3, Programming in the dialplan).