Configure Asterisk for a Home PBX

Posted in VoIP on January 19, 2010

0


We have a PBX for home use because we want our telephones to have features that are not common or simply not available from any phone provider.  Some of these features include termination failover, custom incoming Caller ID, and call recording.  In this guide we will show you how to configure Asterisk for use as a home PBX.  If you are building a PBX for a small or home office you will likely use many of the same techniques.

If you do not yet own an Asterisk PBX, there are several ways you may get one.  You can build one out of an old PC you have lying around, or if you'd prefer a low-cost, low-power Asterisk server that is also a 4-port router, read our other article about How to Install Asterisk on an Asus WL-520GU Router.

Once you have Asterisk installed on your hardware of choice, read on to find out how we configured ours.

Configure peers


The first thing you will likely want to do is configure peers - that is, IP phones, ATAs, and VoIP providers.  We'll start with the [general] context of sip.conf:
[general]
context=incoming       ; 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).  Bindport is the local UDP port that Asterisk will listen on.
bindaddr=0.0.0.0       ; IP address to bind to (0.0.0.0 binds to all).
srvlookup=yes          ; Enable DNS SRV lookups on outbound calls.
disallow=all           ; First disallow all codecs.
allow=ulaw             ; Allow codecs in order of preference.  We only use ulaw.
alwaysauthreject=yes   ; Reject calls with 401 instead of letting the caller know whether there was a matching user or peer for their request.
canreinvite=no         ; Whether or not peers may talk directly to each other without Asterisk in the middle.  Yes requres port forwarding.
nat=yes                ; Whether our devices are behind NAT or not.
session-timers=refuse
Let's take a short break from configuring Asterisk for a moment and we will describe how our devices are set up.  This is largely personal preference and is what works quite well for us.

Our VoIP devices register to our VoIP provider, not our Asterisk server.  There are two reasons for this.  The first is because we want to use our VoIP provider's voicemail so that it will work even if our internet is not working.  So it is necessary for our VoIP devices to register to our VoIP provider in order for message waiting indicator to work.  The other advantage to this technique is that our VoIP provider may be configured to route incoming calls first to our Asterisk server, and then directly to our device if Asterisk is not working for some reason.  There is no need for our VoIP devices to register to our Asterisk server.  Because we have full control of our LAN, they have a static IP.  Outgoing calls are routed to the Asterisk server via the device's dial plan.  When using a setup such as this it is useful to change the SIP Port of your devices to something unique.  It is also useful for your RTP Port ranges to be unique.

This is also a good time to mention 911.  VoIP 911 services typically find your location by looking at a database of customers' Caller ID numbers.  So, in order for this to work properly, your outgoing Caller ID must be correct.  We do not route 911 through our Asterisk server because there is no reason to - our phone places calls to 911 directly through our VoIP provider.  We have requested our VoIP provider to set the outgoing Caller ID number for all of our devices at the same address to the proper Caller ID number for 911.  This way we do not need to pay 911 fees for every single DID.  However, we have several DIDs, and some devices at the same address should have a special Caller ID for regular (non-911) calls.  This may be done with Asterisk.  Keep reading!

One caveat to this technique is if the 911 operator needs to call you back, they will call you back at the Caller ID number.  If that's not okay with you, you should pay 911 fees for each DID you own.

Now, here is one way to configure a VoIP device with a static IP.  You should have something like the following for each device.  It may appear in sip.conf below the [general] context.
; The first line will be the name of this peer.  You may route calls to this device at SIP/pap2t
[pap2t]
defaultuser=mango    ; This is the user ID that is configured on the device.
type=friend          ; This device may both place and receive calls.
callerid=5555551234  ; Outgoing Caller ID of the device.
context=devices      ; This is the context in extensions.conf that this device will use for outgoing calls.
host=192.168.1.8     ; This is the IP address of the device.
port=5068            ; This is the SIP Port the device is listening on.
You will also need to define peers for your VoIP provider(s).  Most VoIP providers will provide configuration samples that you may use.

Asterisk Dialplan


The next thing that you must configure is the dialplan.  The dialplan determines the behaviour of all incoming and outgoing calls.  Because it is large, we shall link to it.  Here's an Asterisk Dialplan for a Home PBX.

You're done!


At this point, you have a working Asterisk server, and if you've been following along, you've built it out of a $25 router that uses just a few watts of power.  Congratulations and enjoy!
 

Write a comment