How to setup Asterisk for a small home system

Overview

This document should provide a starting point for setting up a small home Voice Over IP (VoIP) solution based around the Asterisk Open Source PBX. The content covered is probably applicable to Windows, but I carried out my installation/configuration/setup etc on Linux (Ubuntu Hoary/Breezy)

Required Hardware

I thankfully came across a X100P clone card (from Mark). This card allows my phone line to plug into my PC; and then link up with the Asterisk software. It also allows Asterisk to make outgoing phone calls over the PSTN/POTS line.

In addition to the above, Kat also purchased a CISCO 7960 IP Phone.

Installation of Zaptel

After installing the X100P card, it's necessary to do something like the following :

export CVSROOT=:pserver:anoncvs@cvs.digium.com:/usr/cvsroot
cvs update zaptel
cd zaptel
make
make install

You'll probably need the kernel source code installed.

And that's about it.... well mostly.. /etc/zaptel.conf will need to contain the following

loadzone=uk
defaultzone=uk
fxsks=1

Then run /etc/init.d/zaptel start

Zaptel utilities

There are the following programs which are somewhat useful -

  • ztcfg -vv - this should print out that you have 1 channel configured.
  • ztmonitor 1 -v

Asterisk Installation

Installation is pretty straight forward, or at least was until I upgraded to the Ubuntu Breezy, which seems to lack the chan_zap module (so Asterisk is unable to talk to Zaptel based interfaces)

Because I'm now running Breezy, I ended up having to compile Asterisk from source, which was actually quite easy... :

wget http://ftp.digium.com/pub/asterisk/asterisk-1.0.9.tar.gz
tar -zxf asterisk-1.0.9.tar.gz
cd asterisk-1.0.9
vi Makefile - change ASTVARRUN to be /var/run/asterisk, (default: /var/run).
make
make install

Zaptel / Asterisk integration (zapata.conf)

Edit /etc/asterisk/zapata.conf and it should contain something like :

[channels]
context=telewest_pstn
switchtype=national
signalling=fxs_ks
rxwink=300 ; Atlas seems to use long (250ms) winks
channel => 1
adsi=yes
usecallerid=yes
cidsignalling=bell
callerid=asreceived
hidecallerid=no
callwaiting=yes
usecallingpres=yes
callwaitingcallerid=yes
threewaycalling=yes
transfer=yes
cancallforward=yes
callreturn=yes
echocancel=yes
echocancelwhenbridged=yes
rxgain=00.0
txgain=00.0
group=1
callgroup=1
pickupgroup=1
echotraining=yes
immediate=yes
musiconhold=default

The important bits are as follows :

context=telewest_pstn
switchtype=national
signalling=fxs_ks
rxwink=300 ; Atlas seems to use long (250ms) winks
channel => 1

Where, context determines which section of the extensions.conf calls originating from the Zap device fall into; channel says which zap channel Asterisk is to use for this (you could obviously have multiple Zap compatible cards installed, in which case they may have different purposes/numbers etc); signalling matches that stored in zaptel.conf

Basic configuration of extensions.conf

Asterisk uses the file extensions.conf to store it's dial plan. I'll not explain it in much detail here, as there are far better sources of information on it (E.g. voip-info.org

As an example, here's a section from mine :

[default]
; 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)

As a brief explanation - if I dial 103, I will hear one of the inbuilt asterisk demo sounds (many monkeys squealing). tt-monkeys is a file stored in /usr/lib/asterisk/sounds (With a .gsm ending).

If on the other hand, I dial '1000', then I will be put through to the 'dg' phone as defined in sip.conf (i.e. Dial($CHANNEL/$what,$params)). In the event that the 'dg' phone is not answered, then I will be put through to Voicemail (defined in voicemail.conf) mailbox 1000 (s determines the message given to the caller).

In order for our PSTN line to make a SIP phone ring we can do something like the following :

[telewest_pstn]
exten => s,1,Dial(SIP/dg,25,t,r)
exten => s,2,Voicemail(s1000)
exten => s,3,Hangup

The 's' extension is a special 'match-all' extension which should (I believe) be run for all extensions within the context.

So, we're able to receive calls from the PSTN; now we just need to allow outgoing calls, which is a case of having an extension within a relevant context looking like :

[default]
; if the number starts with a 9, sent 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})

As a quick explanation, if a number starts with 9 (_9) the we sent it to the Zap channel 1; as we need to not pass the 9 to the PSTN line, we use the ${EXTEN:1} regexp type syntax.

The second dialling line, matchs 6 digits, then we send it via the Zap interface also.

Configaration / Adding a SIP based phone

This uses the sip.conf file, an entry would look similar to :

[dg]
type=friend
username=dg
fromuser=dg
callerid=DG at Work
nat=yes
canreinvite=no
dtmfmode=info
secret=my-secret-password
host=dynamic
context=default
disallow=all
allow=gsm
allow=ulaw
allow=alaw

The [dg] bit specifies the name used in extensions.conf Dial commands (i.e. Dial(SIP/dg...)).

The username/password fields need to be programmed into the SIP phone.

As the context=default is set for the phone, calls originating from the SIP phone itself are routed into the context called 'default' as specified in extensions.conf. In this way it would be easy to allow/disallow a phone the ability to use various resources (e.g. to dial overseas etc.)

Addition of FreeWorldDialUp (FWD) to the system (IAX)

FreeWorldDialup operate a VoIP only based service, which is free to join. Upon signing up, it's necessary to enable IAX for your account, and then add something like the following into iax.conf :

[iaxfwd]
type=user
context=fromiaxfwd
auth=rsa
inkeys=freeworlddialup

And then in extensions.conf use something like :

[default]
....
; freeworlddialup stuff (FWD)
exten => _393.,1,SetCallerId,"David Goodwin"
exten => _393.,2,Dial(IAX2/XXIDXX:XXPWDXX@iax2.fwdnet.net/${EXTEN:3},60,r)
exten => _393.,3,Congestion

(Replace XXIDXX with your username, and XXPWDXX with your password)

Now dialling 393 followed by a particular number will result in you dialling a FreeWorldDialup number.

Voicemail

voicemail.conf is used to specify the settings for this; it's relatively straight forward, and an example entry would look like :

[default]

1000 => 6521,David and Katherine,voicemail@codepoets.co.uk

Where voicemail@codepoets.co.uk is an email alias that sends mail to myself and Katherine.

Call logging (email/recording)

If you're a bit of a BOFH, like myself, then it's necessary to record all phone calls made by everyone. The following can be used to do this.

exten => s,1,SetVar(CALLFILENAME=/var/spool/asterisk/monitor/${TIMESTAMP})
exten => s,2,Monitor(wav,${TIMESTAMP},m)

And email notification can be done using :

exten => s,3,System(/bin/echo -e "'Incoming call from :${CALLERID} \\r Received: ${DATETIME}'" | /usr/bin/mail -s "'Phone call'" david@palepurple.co.uk)

Technorati Tags:

Comments

Telewest

Just to update this a little :

  • I couldn't get Caller ID to work on Telewest
  • I've now moved over to a pure IP based system, where the PSTN system is not connected to Asterisk
  • The above will work with Asterisk 1.2.6

Transfer and Conference Call in the Asterisk

People,

I'd like how to do an simple configuration of the Conference Call and Transfer in the Asterisk.

What *.conf's I need to configurefor for this? What the parâmeters?

Thanks!

Hmm - this is interesting

I've been trying for something like 2-3 weeks to get an Asterisk box working how I would want it to work... I'm on telewest also, but I was hoping to set it up kind of like a home answering machine.

I was using AsteriskNow (which was Asterisk @ Home), and I even tried TrixBox... I think I'll go back to proper basics and try Asterisk next. - Your extensions.conf seems like it might offer me some insight into what I was doing wrong - so thanks for that!

thanks

Mike

ASTERISK ON UBUNTU

I was trying to have my cisco 7960 work using asterisk, i have installed x100p card & ubuntu 8 (the latest)

I installed ubuntu already & updated it for new patches & all
Installed the x100p card
now how do i install asterisk? will the procedure you did work for ubuntu 8
i connected my cisco phone via a switch/router which is connected to my 2wire modem.

can asterisk upgrade by cisco from skinny to SIP. I already have the newest SIP firmware, should I use TFTP or asterisk can do it for me
sorry i am a new linux user, just dump bill's xp n vista

please advise

btw, congrats on your new exercise routine, keep it up. fiber fiber fiber!!!!

thanks & have a nice day
OH BTW, do can I just cut n paste the commands on my ubuntu root or I need to type em line by line?

try...

"apt-get install asterisk" will get you some of the way.

Asterisk can't upgrade your CISCO phone, you'll need to do that via TFTP.

You can paste 'stuff', either by right clicking and selecting 'paste' (after doing the same but with copy), or learning the keyboard shortcuts (normally ctrl+c/ctrl+v, except in a terminal when it's ctrl+shift+c/ctrl+shift+v) or by highlighting stuff with the mouse and middle clicking to paste.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
We don't take kindly to automated nonsensible adverts around here.