Installing and Configuring Asterisk
The following article is for installing and configuring Asterisk. There are now different flavors of using Asterisk, the two I will touch upon in this writing is Asterisk (the command line version) and Trixbox (f.k.a Asterisk@Home).
BACKGROUND
Asterisk is a PBX (Phone Box Exchange) system used to connect multiple phone to multiple lines (or a combination there of) for having many features that a traditional PBX would give you, but Open Source (in this case free). You can use PSTN lines, IAX, or SIP routing lines, as well as hard phones (traditional telephones or VoIP handsets) or soft phones. It is used for VoIP (Voice over Internet Protocol).
INSTALLATION
We will first cover installation with the traditional Asterisk software:
First have a box with Linux loaded on it.
System Requirements:
First download Asterisk from CVS:
# cd /usr/src
# export CVSROOT=:pserver:anoncvs@cvs.digium.com:/usr/cvsroot
# cvs login
(password is same as username)
# cvs checkout zaptel asterisk
# cd zaptel
# make clean ; make install
# cd ../libpri
# make clean ; make install
# cd ../asterisk
# make clean ; make install
# make samples
If all of this worked without any errors, you have successfully installed Asterisk.
You can now run
# asterisk –vvvvvvvc
If that doesn’t work, try
# /usr/sbin/asterisk -vvvvvvc
This will run asterisk console in super-verbose mode, if there are any errors, you will see them scrolling across the screen too.
You can type “stop now” to kill Asterisk.
Installing Cards:
Open up your computer and install the card into a PCI slot. These cards require a certain voltage, so make sure your computer can power the card appropriately. When in doubt, lookup the model number of your card, and the model number of your computer. Sometimes, you will need an extra plug from the powersupply to power some of the larger TDM cards.
After you have your card installed, you must configure the card. The following is how to configure a card (this checks for any type of card):
# modprobe zaptel
# modprobe wcfxo
# modprobe wcfxs
NOTE: The first one to be probed, will become channel 1, etc.
Next, you have to edit the zaptel.conf file to let it know where the cards are at. Here is an example of a basic zaptel.conf configuration:
Fxsks=1
Fxoks=2
Fxoks=3
Loadzone=us
Defaultzone=us
Without getting too deep as to why, fxsks is actually for the fxo card, the fxoks stuff is for the fxs cards. The zones just need to be equal to your country code. The number after the fx??? Needs to be equal to what you got when you modprobed earlier.
Now, save your changes and prepare to edit another file called Zapata.conf.
Under Zapata.conf, you would change it (in this scenario) as so:
• busydetect=1 #busy detect on or off
• busycount=7 #how many rings it would take for it to know it’s busy
• relaxdtmf=yes #if dtmf should not be forced
• callwaiting=yes #self-explanatory
• callwaitingcallerid=yes #self-explanatory
• threewaycalling=yes #self-explanatory
• transfer=yes #self-explanatory
• cancallforward=yes #self-explanatory
• usecallerid=yes #self-explanatory
• echocancel=yes #tries to kill/adjust echoing that’s prevalent with VoIP
• echocancelwhenbridged=yes #Self-explanatory
• rxgain=0.0 #volume
• txgain=0.0 #volume
• group=1 #groups for trunking
• pickupgroup=1-4 #groups for phones to pickup calls ringing on other phones
• immediate=no #as soon as the phone is picked up, it dials a specified number [think Red Bat Phone from Original Batman program]
• context=bell #bell is a “group of settings” in your extensions.conf file
• signalling=fxs_ks #signalling method, just have it match your zaptel.conf
• callerid=asreceived #pass callerid on to asterisk’s extension logic
• channel=1 #assign the settings to this channel
• context=home #home is a “group of settings” in your extensions.conf file
• group=2
• signalling=fxo_ks #signalling method, just have it match your zaptel.conf
• mailbox=2468 #mailbox number
• callerid=”Phone 1″ <2468> #callerid of phone on this channel
• channel=2 #assign the settings to this channel
• signalling=fxo_ks #signalling method, just have it match your zaptel.conf
• mailbox=3579 #mailbox number
• callerid=”Phone 2″ <3579> #callerid of phone on this channel
• channel=3 #assign the settings to this channel
Run the following (after stopping Asterisk) to finish configuring the Zaptel cards:
# ztcfg –vv
Now edit the extensions.conf file to configure numbers for the cards:
[default] #This is the default plan for what happens when someone dials extension 103, or 1000
; exten => $extensionNumber,$priority,$command
exten => 103,1,BackGround(tt-monkeys)
; definitions for extension 1000….
exten => 1000,1,Dial(SIP/dg,20,t,r)
exten => 1000,2,Voicemail(s1000)
[telewest_pstn] #This is a sample dial plan called “telewest_pstn” that determines what happens when you use your PSTN like to make a SIP phone ring.
exten => s,1,Dial(SIP/dg,25,t,r)
exten => s,2,Voicemail(s1000)
exten => s,3,Hangup
[default] #This is another part of the default dial plan for dialing out.
; if the number starts with a 9, send it via the PSTN landline.
exten => _9.,1,Dial(Zap/1/${EXTEN:1})
; or if it’s a 6 digit number (i.e local call)
exten => _XXXXXX,1,Dial(Zap/1/%{EXTEN})
Make sure to save your changes.
Sip.conf
From http://www.voip-info.org, the resource for Asterisk, and VoIP related items.
The sip.conf file is a “configuration file for Asterisk SIP channels, for both inbound and outbound calls.”
Here is an example from www.voip-info.org:
[general]
context = (own_context in extensions.conf where receive the call )
realm = real.com (If you’d like to separate by realms)
bindbort=5060 (the port to bind to)
srvlookup=yes (lookup the server?)
disallow=all (secure it by not allowing everybody)
allow=ulaw (protocol)
allow=gsm (encoding/compression – check with provider)
language=en (self explanatory)
trustrpid = yes
sendrpid = yes
register => fromuser@fromdomain:secret@host (from your other asterisk box or VoIP provider)
register => XXXX@YYYY.com:AAAA@IP (from your other asterisk box or VoIP provider)
[my_provider]
type=peer (type of SIP extension)
fromuser=XXXX (user name)
fromdomain=YYYY.com (domain name)
canreinvite=no (usually set to no)
secret=AAAAA (password)
insecure=very (usually set to this)
host= IP (IP address of what this extension should use to authenticate)
disallow=all (secure it by not allowing everybody)
allow=gsm (encoding/compression – check with provider)
allow=ulaw (encoding/compression – check with provider)
allow=alaw (encoding/compression – check with provider)
qualify=yes (usually set to yes)
nat=no (if you’re behind a SOHO firewall, set this to yes)
Outbound call in extensions.conf
exten => _X.,1,Dial(SIP/${EXTEN}@my_provider) (how outbound calls are handled by Asterisk: This specific one means that when a phone number is dialed the first thing that happens is for it to go to a variable extension being called (which is usually declared beforehand) through a SIP line.
When creating or making changes to this file, reload Asterisk by logging into the console and typing the following:
Reload
This will tell Asterisk to re-scan the *.conf files and absorb the changes accordingly.
Trixbox:
Trixbox is a good program that contains all of the essentials of Asterisk, but it much easier to setup. You just pop in the install CD, ad it will install Asterisk, and a lot of other add-ons for you (along with wiping out your hard drive).
Instead of re-inventing the wheel. Sureteq has a good link for how to install and configure Trixbox. It’s for version 1.2, but it will work for version 2.0 just as well.
http://www.sureteq.com/asterisk/trixboxv1.2.htm
Firewalls:
Ideally, when setting up VoIP you will want to do the following with your VoIP PBX system.
1. Separate it from your regular network, whether this be through VLAN’ing, Subnetting or AirGaping, make sure its separate so that it doesn’t mess with your traffic.
2. Change the default passwords on your PBX for EVERYTHING!!!
3. Run the updates to update everything on the server BEFORE configuring it
4. Confirm that your Firewall/Router has QoS (preferably for VoIP on it).
5. Open up the following ports if applicable:
a. 22 TCP for SSH (Quick Remote Administration)
b. 5060 TCP for SIP Registration
c. 10000-20000 UDP for RTP (for audio, video and data)
d. 4569 UDP for IAX2 -> If you’re using IAX, this is probably the one you want.
e. 5036 UDP for IAX
6. Add your modules (especially the backup/restore module)
7. Set a backup schedule for the PBX
An earlier version of Trixbox is Asterisk@home, and was just as easy to manage. Something to keep in mind is that within versions of Trixbox 2.0 and later, it is not too hard to restore your configuration. Upgrades between versions, and between Trixbox and Asterisk will require you to have a card copy of all of your information and will have to be manually entered once the upgrade is complete.