Configure your Asterisk PBX

There are about a dozen configuration files in /etc/asterisk/, but for a standard PBX, you are only going to need to use a few of them:

sip.conf – SIP is a protocol that allows VOIP devices to communicate. In this file you specify your VOIP provider as well as which VOIP phones will be connecting to your asterisk PBX.

voicemail.conf – Asterisk comes with a voicemail system. Each voicemail box is defined in this configuration file.

extensions.conf – Also known as the dialplan, it controls the behviour of your PBX. It outlines what happens when anyone calls your PBX. Interactions such as “Press 2 for Bob” are handled in this configuration file.


The default configuration files are massive and basically contains the documentation. It’s helpful to have around, but I suggest you start with a fresh new file. Initially, we are going to add one account, so you can connect to your asterisk server with a VOIP phone.

context=default                 ; Default context for incoming calls
allowguest=no                   ; Allow or reject guest calls (default is yes)
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
bindport=5060                   ; UDP Port to bind to (SIP standard port is 5060)
bindaddr=                ; IP address to bind to ( binds to all)
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls

[authentication] ;; needed?

secret=xxxpassword ;; *change this!*
qualify=yes ;; keep NAT open
mailbox=20  ;; voicemail box

You don’t need to understand every line here. The most important points are that you have created a username and secret (password), which you will add to your VOIP phone.


The default voicemail.conf configuration file has dozens of options, but the default values are fine for now. The only line you need to add is one to define a voicemail box on the system. At the end of the file, there is a [default] context, where you need to define a voicemail box, password, name, and email (if you want voicemail to be sent as email).

20 => 4444,Bob,


Now that you’ve defined how your VOIP phone will connect to the asterisk PBX, you need to program what happens when you (or anyone else) calls your PBX.

For now, we’ll set-up a simple server where 9 will allow you to listen to your voicemail. 1 will start an echo test 2 will record a wav file. 3 will allow you to hear what callers hear when the call.

;; global variables can be defined here


[incoming] ;; calls from the outside world

exten => s,1,Noop('Call from the outside world')
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n,Background(hello-world)
exten => s,n,VoiceMail(20)

[internal-phone1] ;; calls from our VOIP phone

exten => 1,1,Noop(start echo test)
exten => 1,n,Answer
exten => 1,n,Wait(1)
exten => 1,n,Echo
exten => 1,n,Hangup

exten => 2,1,Noop(record a wav file - stop recording with #)
exten => 2,n,Answer
exten => 2,n,Wait(1)
exten => 2,n,Record('/tmp/outgoing-message-%d.wav') ; stop record with #
exten => 2,n,Wait(1)
exten => 2,n,Playback(${RECORDED_FILE})
exten => 2,n,Hangup

exten => 3,1,Noop('Pretend that we are an outside caller.')
exten => 3,n,Goto(pbx-incoming,s,1)

exten => 9,1,Noop('Listen to any voicemail messages')
exten => 9,n,Answer
exten => 9,n,Wait(1)	;; wait or we lose the first syllable
exten => 9,n,VoiceMailMain(s20) ;; s=skip login, listen to msgs in box 20

exten => i,1,Background(vm-goodbye)	;; invalid keypress

exten => t,1,Background(vm-goodbye)	;; timeout

Take a few minutes to study this file. The format that asterisk uses is a bit obtuse, but it’s important to understand what you see here. Two contexts have been defined: incoming which is where incoming calls from the outside world will go and internal-phone1 which defines what we can dial from our internal VOIP phone.

Once we get our VOIP phone setup (which we will do in the next step) then we will be able to dial 1,2,3 or 9. In sip.conf we defined the context for the phone to be internal-phone1, so when we dial from our VOIP phone, the valid extensions are defined in [internal-phone1]. In extensions.conf we define the sequence of commands that are executed for each dialed numbers. For example, if we dial 9, first the phone is answered, then we wait one second, then we go to into the voicemail system for box 20.

The old-fashioned way to write these commands was to number each line. For example, the commands for extension 9 could also be written as:

exten => 9,1,Noop('Listen to any voicemail messages')
exten => 9,2,Answer
exten => 9,3,Wait(1)
exten => 9,4,VoiceMailMain(s20)

This makes the sequence more obvious, but it is tedious and error-prone to maintain. The ‘n’ shortcut (next) helps with this, although you still need to have an initial ‘1′. I typically use a Noop (no operation) command for the initial command, so all the real commands will simply have an ‘n’ as the sequence number. The Noop command is also useful since the comments will show up in the logs and status messages which is helpful when debugging problems.

To start your asterisk server, run this command as root:


It should simply return quickly, but it has started asterisk. To connect to asterisk, as root, run:

asterisk -r
Asterisk 1.4.21, Copyright (C) 1999 - 2008 Digium, Inc. and others.
Created by Mark Spencer <>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core 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 'core show license' for details.
Connected to Asterisk 1.4.21 currently running on pbxer (pid = 21010)
Verbosity is at least 10

To make sure that asterisk is using the current dialplan, type:

dialplan reload

To view the current dialplan type:

dialplan show
[ Context 'internal-phone1' created by 'pbx_config' ]
  '1' =>            1. Noop(start echo test)                      [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. Echo()                                     [pbx_config]
                    5. Hangup()                                   [pbx_config]
  '2' =>            1. Noop(record a wav file - stop recording with #) [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. Record(/tmp/outgoing-message-%d.wav)       [pbx_config]
                    5. Wait(1)                                    [pbx_config]
                    6. Playback(${RECORDED_FILE})                 [pbx_config]
                    7. Hangup()                                   [pbx_config]
  '3' =>            1. Noop(Pretend that we are an outside caller.) [pbx_config]
                    2. Goto(incoming|s|1)                         [pbx_config]
  '9' =>            1. Noop(Listen to any voicemail messages)     [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. VoiceMailMain(s20)                         [pbx_config]
  'i' =>            1. Background(vm-goodbye)                     [pbx_config]
  't' =>            1. Background(vm-goodbye)                     [pbx_config]

[ Context 'pbx-incoming' created by 'pbx_config' ]
  's' =>            1. Noop(Call from the outside world)          [pbx_config]
                    2. Answer()                                   [pbx_config]
                    3. Wait(1)                                    [pbx_config]
                    4. Background(hello-world)                    [pbx_config]
                    5. VoiceMail(20)                              [pbx_config]

If you have any typos in your extensions.conf file, dialplan show is the a good way to spot them, since it shows how asterisk understands the file.

We’ve got the PBX configured, now we need to setup a phone to connect to it.

%d bloggers like this: