SIP security

SIP security

SIP security is a vast and somewhat challenging field.
  • Authentication: Can users steal other users identity?
  • Integrity: Is the SIP message received the same as the one sent?
  • Confidentiality: Is someone else listening on your SIP call setup?
  • Privacy
  • Non-repudiation: Making sure we can trace callers
In addition, the RTP media stream, the actual conversation audio, may need to be confidential.

Client security

  • Replay

Server security

  • Denial of service attacks

IETF RFCs

  • RFC 3329 Security Mechanism Agreement for the Session Initiation Protocol (SIP)
  • RFC Draft SIP digest authentication relay attack

Books



Tools

http://www.dumaisnet.ca/index.php?article=asterisk_app_filter This is a simple tool that allows to ban hosts (using iptables) if they send too much SIP traffic which could possibly indicate a brute force attack.

SIP RFCs

SIP RFCs

  • RFC 2848 - The PINT Service Protocol: xtensions to SIP and SDP for IP Access to Telephone Call Service
  • RFC 2976 - The SIP INFO Method
  • RFC 3050 - Common Gateway Interface for SIP
  • RFC 3087 - Control of Service Context using SIP Request-URI
  • RFC 3261 Official Main SIP RFC
  • RFC 3261 - SIP: Session Initiation Protocol (Main SIP RFC)
  • RFC 3262 - Reliability of Provisional Responses in the Session Initiation Protocol (SIP)
  • RFC 3263 - Session Initiation Protocol (SIP): Locating SIP Servers
  • RFC 3264 - An Offer/Answer Model with the Session Description Protocol (SDP)
  • RFC 3265 - Session Initiation Protocol (SIP)-Specific Event Notification
  • RFC 3311 - The Session Initiation Protocol (SIP) UPDATE Method
  • RFC 3312 - Integration of Resource Management and Session Initiation Protocol (SIP)
  • RFC 3313 - Private Session Initiation Protocol (SIP) Extensions for Media Authorization
  • RFC 3319 - Dynamic Host Configuration Protocol (DHCPv6) Options for Session Initiation Protocol (SIP) Servers
  • RFC 3323 - A Privacy Mechanism for the Session Initiation Protocol (SIP)
  • RFC 3324 - Short Term Requirements for Network Asserted Identity
  • RFC 3325 - Private Extensions to the Session Initiation Protocol (SIP) for Asserted Identity within Trusted Networks
  • RFC 3326 - The Reason Header Field for the Session Initiation Protocol (SIP)
  • RFC 3327 - Session Initiation Protocol (SIP) Extension Header Field for Registering Non-Adjacent Contacts
  • RFC 3329 - Security Mechanism Agreement for the Session Initiation Protocol (SIP)
  • RFC 3361 - Dynamic Host Configuration Protocol (DHCP-for-IPv4) Option for Session Initiation Protocol (SIP) Servers
  • RFC 3388 - Grouping of Media Lines in the Session Description Protocol (SDP)
  • RFC 3420 - Internet Media Type message/sipfrag
  • RFC 3428 - Session Initiation Protocol (SIP) Extension for Instant Messaging
  • RFC 3485 - The Session Initiation Protocol (SIP) and Session Description Protocol (SDP) Static Dictionary for Signaling Compression (SigComp)
  • RFC 3486 - Compressing the Session Initiation Protocol (SIP)
  • RFC 3487 - Requirements for Resource Priority Mechanisms for the Session Initiation Protocol (SIP)
  • RFC 3515 - The Session Initiation Protocol (SIP) Refer Method
  • RFC 3524 - Mapping of Media Streams to Resource Reservation Flows
  • RFC 3966 - The tel URI for Telephone Numbers
  • RFC 4694 - Number Portability Parameters for the ""tel"" URI

IP PBX

PBX is a system that connects telephone extensions of a company to outside public telephone network as well as to mobile networks. An IP (Internet Protocol) PBX (Private branch exchange) is a PBX that provides audio, video, and instant messaging communication through the TCP/IP protocol stack for its internal network and interconnects its internal network with the Public Switched Telephone Network (PSTN) for telephony communication.
VoIP (Voice over Internet Protocol) gateways can be combined with traditional PBX functionality enabling businesses to use their managed intranet to help reduce long distance expenses, enjoy the benefits of a single network for voice and data and advanced CTI features or be used on a pure IP system which in most cases give greater cost savings, greater mobility, and increased redundancy.
An IP-PBX can exist as a hardware object, or virtually, as a software system.

Function


Because a part of PBX functionality is provided in software, it is relatively inexpensive and makes it easy to add additional functionality, such as conferencing, XML-RPC control of live calls,Interactive voice response (IVR), TTS/ASR (text to speech/automatic speech recognition), Public switched telephone network (PSTN) interconnection ability supporting both analog and digital circuits, Voice over IP protocols including SIP, Inter-Asterisk eXchange, H.323, Jingle (extension of XMPP protocol introduced by Google Talk) and others.

SIP (Session Initiation Protocol) enabled PBX are used to make multimedia communication (voice and video calls) over IP network. It uses enhanced encryption techniques and proxy servers to form sessions of calls over internet.

Features


(Features depend on system in place, some features require licenses or other software/hardware)

  • Unlimited Extensions
  • Unlimited Auto Attendants
  • Unlimited Voicemail Boxes
  • Cell Phone Integration
  • Integrated/Overhead Paging (PA System)
  • Remote Phones
  • Advanced User Interface (including Find me/Follow Me, Unified Messaging, Call recordings, Voicemail .wav).
  • Extension Groups
  • Auto Provisioning
  • Extension Range Flexibility
  • Caller ID Customization
  • DID Direct Inward Dialing
  • Find Me/Follow Me
  • Time of Day Routing
  • Extension Call Recording
  • On the Fly Recording
  • Call Return
  • Voicemail Callback
  • Voicemail to Email
  • SMS Voicemail notification
  • Voicemail Web Access
  • Voicemail Bypass
  • Intuitive VoIP Ready
  • Voicemail Blast Groups
  • VoIP Ready
  • Inbound Call Description
  • VoIP Compression
  • Outlook Integration
  • Announcement Interface
  • Call-out
  • Call Pickup
  • System Diagnositcs
  • Multivendor Phone Options
  • Analog Phone Support
  • BYO Phones
  • Call Parking
  • Call Barge
  • Dial by Name Directory
  • Powerful Reporting
  • CRM Integration
  • Remote Linked Servers
  • Operator Console
  • Custom Routing Rules
  • Conference Rooms
  • Outbound Dial Map
  • Speed Dial Numbers
  • Channel Bank Support
  • Multiple Music on Hold
  • Analog and Digital T1 Ready
  • PSTN or Digital Failover
  • NIS Routing
  • Advanced Routing (IVR)
  • Fast Pass
  • Caller Position Notification
  • Call Whisper
  • Auto call forwarding
  • Unified messaging
  • Call Screening
  • ANI Routing
  • DNIS Routing
  • Enhanced Mobility
  • Custom VoIP Provider
  • Professional Development
  • Fax Support
  • Fax to Email
  • Fax PDF Support
  • ACD Features
  • Click to Dial
  • Softphone
  • Call Transfer
  • Call Conference
  • Live Monitoring



Configuration File Common Options

Each protocol has its own specific options, but they share a number of options common across files. Let’s
go over a few common tasks and the options that control them that you’ll likely run into when editing
configuration files.

Users, Peers, and Friends
Asterisk uses some peculiar classifications for its VoIP connections.They are classified by the type= setting
which is either set to user, friend or peer.These are often accompanied by little to no explanation, which is a
 shame because they’re actually quite simple.
A user is a connection that will be used to make telephone calls to the local server; a peer is a connection
that will be used to make telephone calls from the local server; and a friend is a connection that will be used
to make telephone calls both to, and from, the local server.
These classifications are most commonly used in IAX2 and SIP connections. However, using them in SIP
connections is actually starting to become redundant due to how SIP connections are normally set up.We
will cover that later in the chapter.

Allowing and Disallowing Codecs
Asterisk supports numerous codecs for audio. Codecs can save bandwidth and allow for more simultaneous
phone calls on a data link. For a big list of the codecs Asterisk supports, refer to the table in Chapter 1.
Codecs are configured via the allow and disallow directives. Disallow can be used to explicitly deny use of
specific codecs, or it can be used in conjunction with allow to grant the use of only specific codecs.
Confused yet? Let’s look at a common situation: Say your shiny new Asterisk server has a connection to
your telephone provider via the IAX2 protocol. However, whenever a phone call is made through the
provider, the GSM codec is used, rather than the ulaw codec that is used when you call between extensions in the office.This needs to be fixed. So opening up the iax.conf configuration file you add the following line to the section controlling the connection:
                     disallow=gsm
Then issue a reload command to Asterisk. Problem solved, right? Not necessarily. While yes, this will
disallow use of the GSM codec, the behavior that results might not be the one expected.The added line tells
Asterisk not to use GSM; however, it still has the option of picking from all the other codecs it supports.The
correct way to ensure ulaw is used as the codec would be to add the following lines to iax.conf.
                   disallow=all
                   allow=ulaw
Now, if you’re scratching your head at the disallow=all statement, don’t worry. While, yes, that directive
essentially tells Asterisk to disallow every codec from being used, it is followed by the allow=ulaw
statement, which tells Asterisk that ulaw is okay to use. Essentially, those two lines are the same as typing
out disallow statements for every codec Asterisk supports except the one you want to use. When receiving
a phone call, Asterisk will check each allow and disallow statement to see which codecs it can and cannot
 use. It will first see the disallow=all statement, stopping the use of all codecs, but then it will allow the ulaw
codec once it reads the allow=ulaw statement. This can be expanded to work with multiple codecs as well.
If you wanted to allow both ulaw and alaw,ulaw European equivalent, the same steps would be followed,
except this time there would be two allow lines, allowing both ulaw and alaw.


Configuring Your Connections

Connections are what make Asterisk useful. If there are no connections to Asterisk, you wouldn’t be able to
 connect a phone or use a link to the outside, which really limits the things you can do with it. Asterisk, when
first installed, actually has a connection to a demonstration server hosted by Digium.This connection shows
how calls can be transferred via VoIP to a completely different server as easily as dialing a number, and
gives you a taste of what can be accomplished.This connection, however, is a nice demonstration, but
doesn’t really have any use besides showing off what can be done with Asterisk. If you want to actually
accomplish tasks, you will need to set up your own connections with the outside world.

Connections, Connections, Connections!
Numerous files control the various protocols for Asterisk. Some protocols are commonly used in today’s VoIP setups, while some are quite vestigial and are likely not to be used unless you have specialty hardware. Let’s take a look at the various protocols supported by Asterisk (see Table 3.5).
Each protocol is controlled by a different file. Multiple connections can be set up in a single file, or the files
can be broken down and linked via include statements. What you opt to do is a choice of personal
preference. Each file has certain specific configuration options that are used only for the protocol the file
governs, and they also have options that are common across all files. Let’s go over some of the conventions:

Configuration File Conventions
All Asterisk configuration files have certain conventions that run throughout them. We went through some of them when we were talking about extensions.conf. However, some differences exist in the terminology and layout when comparing extensions.conf to another file.
Much like how extensions.conf is broken down into contexts, most configuration files are broken down into sections. Context and sections have the same syntax— namely, that the headers are surrounded by brackets, as shown in the following example.

Each configuration file often has a [general] section as well, which functions more or less the same way as
the [general] section in extensions.conf: settings in that section are applied to each section unless they are
overridden within the specific section.


Configuring extensions.ael

The alternative to extensions.conf is extensions.ael. extensions.ael is extensions.conf written in a scripting
language called Asterisk Extensions Language (AEL). AEL is language maintained by Digium solely for
writing dial plans in Asterisk. While it is functionally equivalent to extensions.conf,AEL is syntactically much
more powerful and allows for greater flexibility in simple scripting and logical operations. If you’re familiar
with scripting in other languages, AEL can often be easier to pick up than the regular  extensions.conf syntax  extensions.ael can be used as a replacement for extensions.conf or have both used side by side.
extensions.ael is not in widespread use in today’s installations. However, due to its greater functionality, it
would not be surprising to see extensions.conf depreciated in future versions of Asterisk in favor of
extensions.ael.

Using AEL to Write Your Extensions

Everything that can be written in extensions.conf can be rewritten in extensions.ael. Let’s take our simple example from Example 3.1 and rewrite it into AEL.

Execution-wise this does the same exact thing Example 3.1 did. Asterisk answers the call, starts playing the
mainmenu sound file while waiting for the caller to enter digits.The caller can then either enter 100 and be
connected to the channel SIP/10 or 200 and be connected to the channel SIP/20.The caller is then hung up
on when the menu stops playing. Notice how, despite being mixed up a bit, there are still contexts,
extensions, and variables. In this case, however, the exten => EXTENSION, PRIORITY,
COMMAND (ARGS) syntax is completely scrapped. In extensions. ael, the exten => is removed, along
with any use of priorities. extension.ael followsmore of a line-by-line execution pattern the way
extensions.conf executes when the n priority is used. While this simplifies things so you don’t have to worry
about making sure every extension has the right priority, it provides a lack of flexibility in execution order
and Goto() statements. Let’s see what happens when we rewrite the code in Example 3.2.


Because we can’t specify the exact step to jump into in the s context, we need to create a label in the s
extension to tell the Goto() statement where to enter.The restart: label in the s context is the where the t
and i extensions jump to when they are done executing.This label needs to be explicitly specified within the s
context because there are no steps numbered within the context. Macros also function much in the same way
 they do in extensions.conf.They are set up as if contexts, but have extra variables that can be passed to
them. In AEL, variables passed to the macro are not referred to as ${ARG1} through ${ARGX}. In AEL
you can assign them local variables names, which cuts down on the confusion factor when trying to
remember which values are assigned to a certain variable. Another difference in AEL is that the Macro()
command is not used when calling a macro. Instead, the macro’s name has an ampersand added in front of
it. Let’s add the std-exten macro to our AEL example to see how it fits in.


AEL is a very powerful language that allows for a much cleaner dial plan. It is still in heavy development, and may change in future Asterisk revisions, so it may not be quite ready for production yet. However, it is a very good idea to learn the mechanics of it because Asterisk may move toward it in the future.

Writing Macros

include-ing (other contexts within the current one is a handy way to save lines of code and duplication of code. Another easy way to increase efficiency and decrease code duplication is through Asterisk’s macro abilities. Macros can be described as special contexts that accept arguments.They allow for more flexibility than contexts, and allow common tasks to be automated and not repeated. In our previous examples, if someone dialed an extension, it rang a channel. It would continue ringing the channel until someone picked up, or the call terminated. What happens if we want to have that extension drop to voice mail playing the user’s “I’m not here” message after 20 seconds of ringing, or playing the user’s “I’m currently on the phone” message if the phone line is busy?
Yikes.That got complicated quickly. Can you imagine having to set that up for multiple extensions? A single typo in the various extensions could suddenly have people’s voice mails intended for one person wind up in someone else’s voice-mail box. Plus, the various extensions would get out of hand very quickly; your extensions.conf could start topping over thousands of lines of code. Let’s insert a Macro to tame this beast.The macro, macro-stdexten, is included in Asterisk by default for this exact reason.
Using the macro allowed us to write a single piece of code that would duplicate the function of the code in
the previous example. It’s also modular, allowing for the easy addition of extra extensions and extra voice-
mail boxes.The stdexten macro takes two arguments:The first being the channel to ring, and the second
being the voicemail box to send the call to if the channel is busy or does not answer.The macro rings the
channel for 20 seconds and then sends it to voice mail telling voice mail to use the unavailable message. If
the channel is busy, it immediately sends the caller to voice mail, telling voice mail to use the busy message if
the user has one. If there is some other condition on the call, like if the phone cannot be found on the
network, the macro sends it to voice mail with the unavailable message. The Macro() command takes at least one argument, the macro name.You can also pass multiple arguments to the macro by calling the
Macro() command with additional arguments. In our example, macro- stdexten takes two arguments: the
channel to ring, and the voice-mail box to call. Upon calling the macro, the macro is executed like a normal
context, with the exception of extra variables ${ARGX}, where X is 1 through the number of variables you
passed to the macro. This takes care of incoming calls, but what about phones on the inside dialing out
Setting these up is as simple as setting up another context. Each time you set up a connection, you need to
specify which context calls coming from that connection will go into. Setting up a context in which calls can
use your outside line and then assigning all internal phones into that context will allow the phones to send
calls via the outside lines. Continuing our example, let’s set up a context for internal calls:

[internal]
exten => _1617NXXXXXX,1,Dial(Zap/1/${EXTEN})
exten => _1310454XXXX,1,Dial(IAX2@/mass:Sk5S@cali.conglomocorp.com/${EXTEN})
exten => _1NXXNXXXXXX,1,Dial(IAX2/conglomocorplogin@IAXProvider/${EXTEN})
exten => _011X.,1,Dial(SIP/SIPProvider/${EXTEN})
exten => 100,1,Macro(stdexten,10,SIP/10)
exten => 200,1,Macro(stdexten,20,SIP/20)

Let’s go over what each line accomplishes. Each one shows a different way of composing a dial command.The first line tells Asterisk that if a user dials a telephone number in the 617 area code, it will match the _1617NXXXXXX wildcard and the phone call will be sent out via the fist Zaptel device.The next line matches anything within the 310-454 prefix and will connect to a server called “cali.conglomocorp.com” with the username “mass” and the password “Sk5S” and send the phone call through them.This is an explicit connection created in extensions.conf. If a user dials a U.S. telephone number that isn’t in 617 or 310-454, it will match the _1NXXNXXXXXXX wildcard, and will be sent via the IAXProvider connection, which would be created in iax.conf. Finally, if a user dials an international number beginning with 011, it will match the _011X. wildcard and be sent via the SIPProvider connection, which would be created in sip.conf. Also, the user can dial either of the two extensions on the system and be connected to them directly.These extensions would already be connected in sip.conf.
It is important to note that if we placed the _1NXXNXXXXXXX wildcard above the _1617NXXXXXX wildcard or the _1310454XXXX wildcard, anything below the _1NXXNXXXXXX wildcard would never be used since the _1NXXNXXXXXXX wildcard would match everything. Asterisk reads lines from the top down and will match the first line it sees. Remembering this can save you a lot of headaches, and depending on your setup, possibly some money.


Including Other Contexts within the Current One

It’s important to note that when creating another context, the settings and extensions from one context do not propagate to another. Setting up these extensions over and over again can be tedious and will lead to a duplication of code and effort. Thankfully, Asterisk permits other contexts to be joined together via the include => directive.This allows other contexts to be include-ed into the current context and act as one giant context. Let’s go back to our example.The t and i context are duplicated in both the [default] and [supportmenu] contexts.With a couple of small changes, we can make a separate context with just the t and i extensions and include => them into both contexts.
Okay, pop quiz time. Did you notice the difference between this example and the previous one? Don’t
worry if you didn’t, it’s pretty subtle. Because we are including the same t and i context between two files,
the same code will be executed between both. Namely, they will be going to step 1 of the s extension in
 both contexts. Previously in the [default] context, the t and i extension went to step 2 of the s extension,
bypassing the Answer() command. What does this change? Not a single thing. Technically, you’re adding an
extra step every time a caller times out or enters an invalid extension, which may affect performance if this
happens repeatedly in a very high-traffic environment, but, in the grand scheme of things this extra step will
not be perceptible. Answer() only answers the call if the call is in an unanswered state. It ignores being
called if the call is already in answered.


Contexts, Extensions, and Variables! Oh My!

extensions.conf can be broken down into three major parts: contexts, extensions, and variables. Each has their own unique and important function and needs to work together for a good dial plan to function.

Contexts
To put it simply, contexts are the fences that keep your extensions from getting tangled up in a big mess. A context is a simple way for grouping extension commands based on what the user has dialed.To begin a context, put the name of a context by itself in square brackets. Each context then contains a list of commands. In extensions.conf there are two special contexts called [general] and [globals] in which
certain settings can be set. general has a few special settings that define how extensions.conf behaves. First off is the static setting.This, can be set to either yes or no, but for some reason, only yes has been implemented.This will eventually control Asterisk from rewriting the extensions. conf every time an extension is added or deleted.The next setting is writeprotect. This can also be set to either yes or no, and this controls the ability of someone at the CLI to rewrite your dial plan via the save dialplan command.This may seem handy, but doing so will delete all comments in the file. Each extension follows a similar syntax. exten
=> EXTENSION,PRIORITY,COMMAND(ARGS). exten => precedes every extension.This is a
directive that tells Asterisk to define an extension, as opposed to a context.The next three parts of an
extension are EXTENSION, PRIORITY, and COMMAND(). Let’s cover these three portions.

Extensions
Extensions can be broken down into three types: a constant extension, a wildcard extension, and a special extension. A constant extension is an extension that when coded to a literal constant is the dial plan. A wildcard extension is a context that uses wildcards to match multiple possibilities for the extension.Wildcards can be either internal Asterisk wildcards or RegEx-like patterns (see Table 3.2).

So with Wildcard extensions, it is simple to reroute numerous extensions with one line of code. Let’s say a
department in your building, the ever-important widget department, have moved to another division and
wanted to leave a message at their old extensions informing callers that they had moved.They previously
occupied Extensions 300 through 329 on your PBX. Rather than rewrite 30 lines; you can add
a single extension of

           exten => 3[0-2]X,1,Playback(WidgetDeptHasMoved)

This will have any caller dialing the department’s former extensions greeted by a message informing them of
the move. Playback is a command that plays back a sound file stored on the system; we’ll cover it and its
counterparts later. In addition to wildcard and literal extensions, there are also special extensions that

correspond to special events in the dial plan (see Table 3.3).


Extensions do not necessarily need to be numbers either.They can be made with any type of text. While extensions like “fuzzybunnydept” cannot be dialed by a caller if included in your context, it can be used internally by your dial plan.We’ll see how this can come in handy later in the chapter.

Priorities
PRIORITY controls the flow in which commands are executed. For each extension, this is either controlled by an increasing number or a special n syntax.The n syntax tells Asterisk to execute the extension one line after the other:

[incomingcall]
exten => s,1,Answer()
exten => s,n,Playback(mainmenu)
exten => s,n,Hangup()

In this example, any call being routed to the “incomingcall” extension in Asterisk would have its call answered, a menu would then play, and then the call would be terminated. After Asterisk finishes executing one line, the next line would be executed. Numbering the steps provides greater flexibility with the dial plan since it is possible to control the flow logically rather than line by line. For example, the extension shown earlier could be rewritten with a numbered sequence

[incomingcall]
exten => s,2,Playback(mainmenu)
exten => s,1,Answer()
exten => s,3,Hangup()

Asterisk still answers, plays the menu, and hangs up because it executes by line number rather than by the order in which the lines appear. It executes step 1, followed by steps 2, and then 3.These steps could be scattered throughout the context and intertwined with hundreds of extensions. As long as they are numbered correctly, Asterisk will execute them in order for that context.

Dial Plan Commands
The commands are the heart of any dial plan.They are what actually cause Asterisk to answer the call, ring the phone, transfer the call, play the menu, and do numerous other things. See Table 3.4 for a look at some of the more common ones.


Variables
Variables in extensions.conf are nothing special.They act like variables in any other language.Variables are set via the Set() command and are read via the variable name encased in ${}:

[example]
exten => s,1,Set(TEST=1)
exten => s,2,NoOp(${TEST})

Variables are common in simple dial-plan applications and Asterisk uses certain variables for internal functions, but their use is somewhat uncommon in regular dial plan usage.

Tying It All Together
All of these pieces of dial plans make little to no sense when thinking about them in the abstract, so you may be scratching your head right now. Let’s take a look at how all of these would be used in an everyday environment, by looking at a simple extensions.conf:
When a call enters the [default] context, it is answered by Asterisk. Asterisk then starts playing the
 mainmenu sound file while waiting for the caller to enter digits. At this point, the caller can either enter 100
and be connected to the channel SIP/10 or 20 and be connected to the channel SIP/20. If the menu finishes
playing and the user has not entered any digits, the call will be hung up on.

Using Special Extensions
Now, hanging up on your caller if they wait to listen to the whole menu seems kind of rude, doesn’t it? So
let’s take the file we had before and use some special extensions to have the menu replay if the user hasn’t
entered an extension and inform them if the extension they entered is invalid.


That’s much nicer. Now the behavior of the dial plan is the same, up until the main menu ends. At that point,
the menu repeats. Also, now if the caller dials an incorrect extension, the dial plan will play a menu that
informs them the extension they entered is not valid.

Creating Submenus
Normally, most small to medium-sized companies only require a single menu, but let’s say your boss wants
to have a support menu that allows customers to direct their questions to the appropriate support group.We
can accomplish this by creating a second context that contains the appropriate menu and extensions. Let’s
build on the previous example again and add a second menu that allows callers to be connected to the
Blivet,Widget, or Frob support lines.
In this example, we’ve added a third option to the main menu. If a caller dials 3, they are connected to the [supportmenu] context with a Goto() statement. Goto() can be called many different ways.You can jump between priorities in the same extension by just specifying Goto(priority) or you can jump between extensions in the same context by specifying Goto(priority,extension). Lastly, you can switch contexts by specifying Goto(context, extension, priority).

Configuring Your Dial Plan

The dial plan is the logic behind how phone calls are routed through your Asterisk installation. Asterisk runs
every incoming call, every outgoing call, and every call in between extensions through the dial plan logic in
order to determine where it should go and whether or not it should be completed.The dial plan is contained
in extensions.conf,and therefore it can be said that extensions.conf is easily the most important configuration  file in Asterisk. Removing extensions.conf is similar to removing a traffic light at a complicated intersection; cars will want to enter and cars will want to leave, but there will be no way to direct them. extensions.conf is a bit more complicated than a typical configuration file. On top of the usual sections and settings, there is a logical flow similar to a program. Essentially, extensions.conf is one giant script.The sooner you keep this in mind, the easier it will be for you to write a good dial plan.

Configuring Asterisk

Figuring Out the Files
If you enter into your Asterisk configuration directory, /etc/asterisk, you’ll see 62 files by default. If you’re
taking over a previous installation administered by someone else, you may see more than that. Looking at
the file names, you’ll see they have cryptic labels like rtp.conf, or file names that seem to be the same thing,
like asterisk.adsi and adsi.conf. When trying to configure your system, finding the right file to edit can be like
unearthing the proverbial needle in a haystack. (See Table3.1 for information on what each file controls.)
To say Asterisk has a lot of settings would be an understatement of mammoth proportions. While this is a
lus when you want to tweak Asterisk to fit your needs exactly, it is a bit overwhelming. However, don’t fret.
Certain configuration files can be ignored if you don’t have certain hardware, and other files can be ignored
 if you do not need to enable certain features of Asterisk.

freePBX with TrixBox

freePBX is accessed by clicking the Asterisk link of the main menu, and then clicking the freePBX link.
freePBX will greet you with a welcome screen and a list of menu options on the top. From here you can
access the setup options, system tools, call activity reports, Flash Operator Panel, and the Asterisk
 recording interface. Clicking Setup will take you to the setup main page.The main page has a list of options
on the left, which will allow you to administer user accounts, extensions, and general Asterisk settings;
configure dial plans; and set up and control inbound and outbound trunks. See Figure 2.15.

PHPConfig
PHPConfig is a great way to edit configuration files without having to deal with a shell terminal. It allows you
 to edit files just like they were in a text editor, but without having to learn how to use a Linux shell. It
provides the best of both worlds. PHPConfig can be accessed by clicking the Asterisk link on the
maintenance home page and then clicking the Config Edit link. Afterward, PHPConfig lists all the files in the
Asterisk configuration directory. Clicking the name of one of these files brings the file up in an edit
window.To the left of the edit window, PHPConfig lists all the sections it reads from that file, allowing you to
quickly jump to and edit the section you wish to work on. When finished editing, click the Update button
below the edit window. PHPConfig will then write the file to disk.The changes are not immediately reflected
in Asterisk though.To reload all the configs, you will need to click the Re-Read Configs link at the top of the
page.This tells Asterisk to perform a “reload” command that will reload all the configuration files. If there are
no errors, PHPConfig will then display “reset succeeded.” See Figure 2.16.
Installing Asterisk from Scratch
Before there were live CDs and distributions, there was source code. Asterisk’s availability of source code
 is one of its biggest features, allowing anyone to “poke under the hood,” see the internal workings, and
rewrite portions if needed. Compiling Asterisk from its sources gives you the greatest amount of control as
to what files are installed, and where they are installed. Unneeded options can be removed entirely, allowing
a leaner Asterisk install. However, as always, there is a downside. Compiling anything from source is
intimidating if you aren’t used to doing it. However, it’s terribly once you figure it out.

The Four Horsemen
When compiling Asterisk from source, there are four major pieces to the puzzle: LibPRI, Zaptel, Asterisk-
Addons, and Asterisk. Asterisk is, you guessed it, the PBX itself.This package contains the code for
compiling the PBX and all its modules.You aren’t going to get far compiling Asterisk without this package.
LibPRI is a library for handling the PRI signaling standard.The PRI standard was created by the Bell System
back in the 1970s and is now an ITU standard. LibPRI is a C implementation of the standard.This package
may be required depending on the hardware installed on the system. Asterisk-Addons is a package that
contains certain optional “bells and whistles,” such as an MP3 player so Asterisk can handle sound files
encoded in MP3, and modules for logging calls to a MySQL database. While these modules are completely
optional, they are good to have, especially the MP3 player, and the resources they take up are minimal.
Installing them is recommended. Zaptel is the package that contains the driver and libraries for Asterisk to
talk to Zapata telephony hardware, which are the telephone interface cards discussed earlier. This is a handy
package to install, even if there is no Zaptel hardware on the system, since the conferencing software
requires it for timing purposes.

Asterisk Dependencies
Before you start compiling Asterisk, you must make sure you have all the requirements satisfied. First off is
the compiler. If you don’t have a compiler like GNU C Compiler (gcc) installed, you aren’t going to get very
 far compiling the source code. Next, make sure you have the libraries required to compile, otherwise you
will likely have some kind of odd error at compile time. Asterisk has three dependencies: ncurses
(www.gnu.org/software/ncurses/), a library for text-based “graphical” displays; OpenSSL
(www.openssl.org/), an open-source library of the TLS and SSL protocols; and zlib (www.zlib.net/), a data
compression library. Asterisk requires both the library itself and the associated include files.These are
included automatically if you compile from source. However, if you install the libraries from a binary
repository, you will need to include the development packages as well. For instance, you would need to get
both zlib and zlib-devel.

Getting the Code
Links to all of the Asterisk code are available at http://www.asterisk.org. Clicking the Downloads tab will
take you to a page with links to grab all the necessary files.The links to get Asterisk provide options for
downloading either Asterisk 1.2 or Asterisk 1.4 directly, or visiting the source archive. Grabbing Asterisk
directly only downloads the Asterisk package, so you’ll want to download the LibPRI, Zaptel, and
Asterisk- Addons separately.The latest versions of each package should end in -current. Since there are
multiple source archives, it is best to put all of them in a common subdirectory wherever the system’s source
code directory is located (for example: /usr/local/src/asterisk/). See Figure 2.17.

Gentlemen, Start Your Compilers!
Compiling is simpler than one might think. Often, all that’s required is three commands: ./configure, make,
and make install. Once you have these three commands memorized, you’ll do fine.

Compiling LibPRI
The first step is to compile LibPRI.This is required if you have a PRI interface hooked into the system, but optional if you do not. First, expand the archive.
     tar xvzf libpri-1.4-current.tar.gz
This will expand the source archive into a directory. At the time of this writing, itis libpri-1.4.0/. After the file
is done expanding, change to the LibPRI directory. cd libpri-1.4.0/
LibPRI doesn’t have a configuration command yet, so the only two steps are to compile it via the make
command, wait until it finishes, and then run make install. It is important to run the make install command as
a root user, otherwise the library will not be installed correctly due to permission errors. Once everything is
done, you can exit the LibPRI directory. cd ../


Installing Asterisk TrixBox

Four Linux distributions focus on Asterisk: PoundKey, a Linux distribution supported by Digium; Evolution
PBX, a distribution made for small businesses with commercial support; Elastix, a distribution supported by
a commercial company; and trixbox. trixbox was released in 2005 as “Asterisk@Home,” a simple and easy
way to install Asterisk on a computer. Self contained within a bootable CD, Asterisk@Home focused on
ease of use and ease of install, allowing someone with little to no Linux experience to start playing with
Asterisk. In 2006, Asterisk@Home was acquired by Fonality, a California-based VoIP services firm, who
renamed the new version of Asterisk@Home to “trixbox.”Today, trixbox is one of the leading Asterisk
Linux distributions. With over 30,000 downloads a month, it takes its place among the “heavy
hitters” of Asterisk distributions. The trixbox CD contains numerous add-ons to Asterisk: freePBX, a Web-
based configuration manager; HUDLite, a cross-platform operator panel; and SugarCRM, a complete
Customer Relationship Manager suite. All of these are configured to run out of the box with trixbox,
allowing a complete suite of tools for managing and maintaining your Asterisk installation.

Getting trixbox
trixbox is available at www.trixbox.org.The most up-to-date version at the time of this writing is trixbox 2.0
which contains Asterisk 1.2.13.The download size clocks in at a hefty 550MB, so you may want to put on
a pot of coffee before you start downloading. Like the live CD’s discussed earlier, the downloaded image
can be burned with the “image burn” function of any standard CD recording program.
Booting trixbox
After burning the trixbox CD, use it to boot the machine you will be installing to. Again, as mentioned in the
 earlier “Booting SLAST” section, the computer may need some kind of setting changed to boot from a CD.
Once the CD is booted, the trixbox boot screen is displayed, as shown in Figure 2.8.

After about five seconds, the CentOS installer will start loading up, as shown in Figure 2.9.
After all the system’s hardware is detected, the installer will start prompting you for questions regarding
keyboard layouts and time zones. Answer these as appropriate to your system. Once done with that, it will
prompt you for a root password. Once enough information is gathered, the installer will start formatting your
hard drive and the installation will begin, as shown in Figure 2.10.

The trixbox installer will copy files, reboot, and begin to install specific packages on the system (see Figure
2.11). After installation, trixbox will reboot one last time and display a login prompt. Log in with the
username root and the password you specified in the setup process and you will be presented with a root
shell. After logging in, the URL of the Web management interface will be displayed, as shown in Figure 2.12.


Configuring trixbox
trixbox, like SLAST, should configure its network automatically if there is a DHCP server on the network. If
it didn’t, or if the DHCP address is not the address you want for the server, you can run the netconfig utility
to manage network settings, as shown in Figure 2.13.
netconfig will prompt you for the IP address, netmask, gateway, and nameserver of your network. Enter
these as appropriate for the system. After confirming these settings, the utility will exit. Reboot the system,
and the new network settings will take effect.

trixbox’s Web Interface
One of trixbox’s nicer features is a Web interface that allows you to manage the system through a Web
browser. It uses PHPConfig Asterisk config editor, which allows you to edit the files directly, in addition to
using freePBX, which is a standardized interface for managing certain Asterisk features.
By entering the system’s IP address into your Web browser, you’ll be greeted with trixbox’s home
page.You’ll see links for the system’s Asterisk Recording Interface which manage the ability to record audio
conversations on Asterisk, scripts to manage Asterisk’s recordings, voice mail, and call monitoring
recordings; the MeetMe management system, a system to manage MeetMe conferences; Flash Operator
Panel, a phone operator panel for Asterisk written in Flash; and SugarCRM customer relationship
management software. In the upper right, you’ll see a link to switch into “Maintenance” mode. Clicking the
link will prompt you for a username and password. Log in with the username maint and the password
password.

The trixbox management system is very full featured, and a book could be written on these two systems
alone, so let’s just take a (very) quick tour of the two major configuration editors on the system:The
PHPConfig Asterisk config editor and the freePBX system. Figure 2.14 shows the trixbox system default
page.

Installing Asterisk SLAST

So, you’ve purchased your server, installed an operating system, and you’re ready to plunge head first into
Asterisk. Determining the “right way” to install Asterisk depends on your situation. If you just want to try
Asterisk out and are worried about messing up an existing system, the Live CD would likely be your best
route. If you are not too familiar with Linux installation, but are looking to set up a dedicated Asterisk
system, you may want to look at a CD distribution of Asterisk. If you are an experienced Linux
administrator and want to configure Asterisk to fit into a custom environment, you’ll likely just want to
compile it from scratch. Finally, if you are either a Mac OS X or Microsoft Windows user, and you just
want to use your existing operating system for an Asterisk install, you’ll likely just want to use the packages
for your operating system. Asterisk’s ability to be customized isn’t just limited to the final setup; it starts at
the installation phase of the system.You can easily make it fit almost any environment.

Using an Asterisk Live CD
Live CDs are bootable CDs that contain a complete operating system. After booting, your machine will run
the operating system from the CD without installing it to the hard drive. If something goes wrong, you can
turn off the computer, eject the CD, reboot, and boot back to the operating system installed on your hard
drive. Although this installation method is not recommended for most production environments, it is a perfect
 way for a novice user to try out the features of an operating system without altering the boot machine in any
way. In this section, we’ll take a look at one of the more popular live Asterisk CDs: SLAST.
    SLAST
       SLAST (SLax ASTerisk) is an Asterisk-ready version of the Slackware-based SLAX
       Live CD. Maintained by the Infonomicon Computer Club, SLAST was designed to
       help educate people about the advantages of Asterisk and allow them to set up a
       simple Asterisk server in the easiest way possible.
    Getting SLAST
      SLAST is available at http://slast.org.The ISO image is available from their download
      page.The download size comes in at just a bit over 100MB, so any broadband
      connection should make quick work of the download. Once the ISO is downloaded,
      the disk image can be burned to a CD using the “image burn” feature of most popular
      CD recording programs.
    Booting SLAST
      Booting SLAST is as simple as inserting the CD into an Intel-based machine, and
      rebooting. Depending on how your machine is configured, you may need to press a
      key during startup to instruct the machine to boot from a CD. Once the CD is
      booted, the SLAST screen is displayed, as shown in Figure 2.4.
      Once SLAST loads the system into memory, the login screen is displayed.The
      login screen has a quick “cheat sheet” of sorts showing file locations of Asterisk configuration
      files, Asterisk sounds, Asterisk modules and the SLAST documentation.
      The root password is also displayed. Log in with the username root and the password
      toor, and you will be presented with a root shell, as shown in Figure 2.5.


Configuring the Network
While a network connection isn’t specifically required for Asterisk, unless the target system has hardware to
connect it directly to a phone, some kind of network connection will likely be necessary if you want to
connect to something besides the local computer. SLAST, as with most live distributions, does a pretty
good job at detecting any and all hardware on the target system. If everything is plugged in and turned on,
SLAST should have no issues setting up the hardware. However, SLAST, like other Live CDs, may have
trouble detecting networks settings. If you’re running a DHCP server, Asterisk should automatically
configure your settings. However, if manual intervention is required to configure these settings, you may need
to rely on ifconfig, the InterFace Configurator. Running ifconfig without any arguments will display any
configured network interfaces on the system. Ethernet interfaces will be shown labeled by their abbreviations
 ethX, where X is a number starting at 0 for the first interface. Next to the name will be fields for the IP
address labeled as “inet addr,” the broadcast address labeled as “Bcast,” the network mask labeled as
“Mask,” along with various statistics regarding the interface. See Figure 2.6.


The configure_network script allows the system’s network interface to be configured with minimal user
interaction.The user can run the script by entering configure_network at the prompt and pressing Enter.The
script will execute, prompting you for information regarding your desired network configuration, as shown in
Figure 2.7.