Basic Asterisk configuration

Posted on May 25, 2010

First of the series Asterisk that is oriented on the configuration of Asterisk and the integration with other products such as Microsoft Office Communication Server or Skype we’ll start with the basic configuration of Asterisk and the required files to get it started.

I’m using a Debian testing (squeeze), so the basic installation is really too much for me, too many modules are loaded (with debian’s default installation I had 204 modules). I prefer setting up minimal systems and add modules as necessary. Our first step will be to trim down the installation to a minimal setup.

[ad#Google Adsense] Once cleaned up I finished with 32 modules, including some extra features such as Skype, CDR MySQL or simultaneous calls limiting

server-sip1*CLI> module show
Module                         Description                              Use Count
res_skypeforasterisk.so        Skype For Asterisk Engine                0
res_adsi.so                    ADSI Resource                            0
res_config_mysql.so            MySQL RealTime Configuration Driver      0
res_crypto.so                  Cryptographic Digital Signatures         0
res_musiconhold.so             Music On Hold Resource                   0
pbx_config.so                  Text Extension Configuration             0
func_callerid.so               Caller ID related dialplan functions     0
func_groupcount.so             Channel group dialplan functions         0
func_global.so                 Variable dialplan functions              0
cdr_addon_mysql.so             MySQL CDR Backend                        0
chan_iax2.so                   Inter Asterisk eXchange (Ver 2)          0
chan_local.so                  Local Proxy Channel (Note: used internal 0
chan_oss.so                    OSS Console Channel Driver               0
chan_sip.so                    Session Initiation Protocol (SIP)        0
codec_alaw.so                  A-law Coder/Decoder                      0
codec_g722.so                  ITU G.722-64kbps G722 Transcoder         0
codec_gsm.so                   GSM Coder/Decoder                        0
codec_ulaw.so                  mu-Law Coder/Decoder                     0
format_gsm.so                  Raw GSM data                             0
format_h263.so                 Raw H.263 data                           0
format_pcm.so                  Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G. 0
format_wav_gsm.so              Microsoft WAV format (Proprietary GSM)   0
format_wav.so                  Microsoft WAV format (8000Hz Signed Line 0
app_dial.so                    Dialing Application                      0
app_echo.so                    Simple Echo Application                  0
app_macro.so                   Extension Macros                         0
app_milliwatt.so               Digital Milliwatt (mu-law) Test Applicat 0
app_setcallerid.so             Set CallerID Presentation Application    0
app_transfer.so                Transfers a caller to another extension  0
app_verbose.so                 Send verbose output                      0
app_voicemail.so               Comedian Mail (Voicemail System)         0
chan_skype.so                  Skype For Asterisk Channel Driver        0
32 modules loaded

Before going further I would suggest that you run modules show before disabling autoload and save the output. This can be useful if can’t get a function working.

I based myself on voip-info.org page on Asterisk Slimming. I first disabled modules autoloading in /etc/asterisk/modules.conf

[modules]
autoload=no

Asterisk will not load in this state, too many modules are disabled (such as the core ones, sip – iax …) so lets create our modules list:

[modules]
autoload=no

; Resources —
load => res_adsi.so ; ADSI Resource
load => res_config_mysql.so ; MySQL Configuration
load => res_crypto.so ; Cryptographic Digital Signatures
load => res_features.so ; Call Parking Resource
load => res_musiconhold.so ; Music On Hold Resource

; PBX —
load => pbx_config.so ; Text Extension Configuration Requires N/A

; Functions —
load => func_callerid.so ; Gets or sets Caller*ID data on the channel. - Requires ?
load => func_global.so ; Variable dialplan functions

; Channels —
load => chan_iax2.so ; IAX (Ver 2) - Requires res_crypto.so, res_features.so
load => chan_local.so ; Show status of local channels- Requires N/A
load => chan_oss.so ; OSS Console Channel Driver - Requires N/A
load => chan_sip.so ; Session Initiation Protocol (SIP) - Requires res_features.so

; Codecs —
load => codec_alaw.so ; A-law Coder/Decoder - Requires N/A
load => codec_g722.so ; ITU G.722-64kbps G722 Transcoder
load => codec_gsm.so ; GSM/PCM16 (signed linear) Codec Translat - Requires N/A
load => codec_ulaw.so ; Mu-law Coder/Decoder - Requires N/A

; Formats —
load => format_gsm.so ; Raw GSM data - Requires N/A
load => format_h263.so ; Raw h263 data - Requires N/A
load => format_pcm.so ; Raw uLaw 8khz Audio support (PCM) - Requires N/A
load => format_wav_gsm.so ; Microsoft WAV format (Proprietary GSM) - Requires N/A
load => format_wav.so ; Microsoft WAV format (8000hz Signed Linear) - Requires N/A

; Applications —
load => app_dial.so ; Dialing Application - Requires res_features.so, res_musiconhold.so
load => app_echo.so ; Echo audio read from channel back to the channel - Requires N/A
load => app_macro.so ; Macro Handling Application - Requires N/A
load => app_milliwatt.so ; Generate a Constant 1000Hz tone at 0dbm (mu-law) - Requires N/A
load => app_setcallerid.so ; Set Caller*ID on a call to a new value. - Requires N/A
load => app_setcdruserfield.so ; Append to the CDR user field - Requires N/A
load => app_transfer.so ; Transfer caller to remote extension - Requires N/A
load => app_verbose.so ; Send arbitrary text to verbose output - Requires N/A
load => app_voicemail.so ; Comedian Mail (Voicemail System) - Requires res_adsi.so

[global]

At this point the system should be starting with a minimal set of modules (we’ll add modules as required by various functions). The good news with that is that you’re going to really reduce the number of configuration files required. By default the asterisk folder contains 81 files and we can bring them down to 14 files, here they are:

adsi.conf
asterisk.conf
extconfig.conf
extensions.conf
features.conf
iax.conf
iaxprov.conf
logger.conf
manager.conf
modules.conf
musiconhold.conf
rtp.conf
sip.conf
voicemail.conf
[ad#Google Adsense]

With all this setup we can start configuring the real telephony bit. Let’s start with sip.conf, this file is here to manage the peers. We’ll setup a basic system with 2 phones, no SIP trunk (we’ll talk about these trunks in further posts).

[general]
dtmfmode=auto
relaxdtmf=yes
port=5060
bindaddr=0.0.0.0
tcpenable = no
externip = 192.168.0.1
context=from-sip-external
tos_sip=cs3                    ; Sets TOS for SIP packets.
tos_audio=ef                   ; Sets TOS for RTP audio packets.
tos_video=af41                 ; Sets TOS for RTP video packets.
nat=no
srvlookup=yes
disallow=all
allow=gsm
allow=ulaw
allow=alaw

[foo]
type=friend
host=dynamic
context=home
secret=foo
dtmfmode=rfc2833
nat=yes
callerid=Foo <10>
disallow=all
allow=ulaw
allow=alaw

[bar]
type=friend
host=dynamic
context=home
secret=bar
dtmfmode=rfc2833
nat=yes
callerid=Bar <11>
disallow=all
allow=ulaw
allow=alaw

Some explanations, first we configure the basic “connectivity options”

port=5060
bindaddr=0.0.0.0
tcpenable = no
externip = 1.1.1.1
nat=no
context=from-sip-external

Here we configure our server to listen on all addresses, on port 5060 UDP only, all incoming calls that do not match any peers configured will be sent in the from-sip-external context and we specify NAT information.
Next, that’s the networking guy speaking, I manage QoS on my internal network and I want to make sure voice and video traffic are correctly handled so I set the DSCP values on my packets

tos_sip=cs3                    ; Sets TOS for SIP packets.
tos_audio=ef                   ; Sets TOS for RTP audio packets.
tos_video=af41                 ; Sets TOS for RTP video packets.

Finally we configure the codecs globally, just in case we forget to add them on a peer.

disallow=all
allow=gsm
allow=ulaw
allow=alaw

Now we have all the global stuff in place, lets configure our peers

[foo]
type=friend
host=dynamic
context=home
secret=foo
nat=yes
callerid=Foo <10>
disallow=all
allow=ulaw
allow=alaw

This part is pretty explicit. We’re creating a user “foo” with a password “foo”, our user will be in the “home” context have a dynamic IP address and most probably be behind NAT. Finally we force the codecs this users will be using.

Ok now we have our devices configured, but they cannot call each other … Hmm … Why is that? Well we didn’t configure any extensions on the devices so they don’t know how to reach each other. Lets correct that and configure our dial plan.

Here is how our extensions.conf file should look like:

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

[home]
exten => _10,1,Dial(SIP/foo)
exten => _11,1,Dial(SIP/bar)

We first have to define the context “home”, this is where we are associating our peers. Then under this context we define the number / device pairing.
In this example if I call the number “10” it will be sent to the “foo” device.

Here we are, our system is configured for basic call handling. In further articles we’ll see how to configure other features such as Skype, CDR MySQL, Simultaneous calls limitations … and we’ll discuss the security for VoIP. Stay tuned …


3 Replies to "Basic Asterisk configuration"


Got something to say?

Some html is OK