A simple phone server

My Wife and I both work from home and take conference calls from time to time, one of the things we both prefer when sitting on a call with multiple people is a desk phone with a physical mute button. Messing around with cell phones / soft phones is a pain and using our cordless home phone doesn't give us the handsfree quality we like.

So to combat this we need a small VOIP phone server that permits multiple outbound calls via a sip trunk provider.

Now, there's a lot of SIP providers out there, I certainly haven't tried them all, however, I've tried a few. Some have been great, others not so much, the provider I'm going to use in this example is Flowroute; I've used them consistently over the last 8 years, they've had very few (if any - I can't remember any) outages, extremely cheap and the quality is decent to boot.

Before you can go too far with this how-to, you'll need to setup an account with them and get a sip username and password setup.

I'm using a standard Ubuntu 16.04 Server install, running in a small VM (2 VCPU, 1gb RAM), this VM also has a working MTA (postfix) running on it, this is for voicemail to email (I leave my wife voiemails from time to time)

Install Asterisk using apt-get:

sudo apt-get -y install asterisk

Once you have that installed, let's move sip.conf and extensions.conf out of the way.

sudo mv /etc/asterisk/sip.conf ~/
sudo mv /etc/asterisk/extensions.conf ~/

Now, we're going to setup 6 basic extensions (our phones support 2 lines each) and an outbound SIP connection, so clear the contents of /etc/asterisk/sip.conf and replace with with the following:

[general]
port = 5060 ; Port to bind to
bindaddr = 0.0.0.0 ; Address to bind to
context = users ;default Default for incoming calls
udpbindaddr=0.0.0.0
tcpenable=yes
tcpbindaddr=0.0.0.0
callcounter=yes
transport=udp, tcp
localnet=LOCALNETWORK/LOCALSUBNET
externrefresh=15
musiconhold=default
videosupport=no
register => SIPUSERNAME:SIPPASSWORD@sip.flowroute.com

[3000]
type=friend
host=dynamic
username=3000
secret=3000
dtmfmode=rfc2833 ; Choices are inband, rfc2833, or info
mailbox=3000 ; Mailbox for message waiting indicator
context=users
callerid="Extension 3000"

[3001]
type=friend
host=dynamic
username=3001
secret=3001
dtmfmode=rfc2833 ; Choices are inband, rfc2833, or info
mailbox=3001 ; Mailbox for message waiting indicator
context=users
callerid="Extension 3001"

[3002]
type=friend
host=dynamic
username=3002
secret=3002
dtmfmode=rfc2833 ; Choices are inband, rfc2833, or info
mailbox=3002 ; Mailbox for message waiting indicator
context=users
callerid="Extension 3002"

[3003]
type=friend
host=dynamic
username=3003
secret=3003
dtmfmode=rfc2833 ; Choices are inband, rfc2833, or info
mailbox=3003 ; Mailbox for message waiting indicator
context=users
callerid="Extension 3003"

[3004]
type=friend
host=dynamic
username=3004
secret=3004
dtmfmode=rfc2833 ; Choices are inband, rfc2833, or info
mailbox=3004 ; Mailbox for message waiting indicator
context=users
callerid="Extension 3004"

[3005]
type=friend
host=dynamic
username=3005
secret=3005
dtmfmode=rfc2833 ; Choices are inband, rfc2833, or info
mailbox=3005 ; Mailbox for message waiting indicator
context=users
callerid="Extension 3005"


[flowroute] ;keep this lowercase, do not change format
type=friend
qualify=yes
secret=SIPPASSWORD
username=SIPUSERNAME
host=sip.flowroute.com
dtmfmode=rfc2833
context=users
canreinvite=no
allow=ulaw
allow=g729
insecure=port,invite
fromdomain=sip.flowroute.com

Now, obviously the passwords to connect to each extention are not exactly secure, bear in mind, there's no external access to asterisk, so I'm not really worried.

Now, there's a few things here that need to be adjusted:

localnet=LOCALNETWORK/LOCALSUBNET - Ultimately this is the first address on your network and your subnet mask, in my case it's 192.168.0.0/255.255.252.0

Your SIPUSERNAME and SIPPASSWORD should be available to you in the Flow Route console, you'll find it under Profile->Interconnection->Registration

Next up, we'll need a basic config for Voicemail add these lines to the bottom of /etc/asterisk/voicemail.conf

[vmsetup]
3000 => 1234,Dan,dan@thekingshotts.com,dan@thekingshotts.com,attach=yes
3001 => 1234,Dan,dan@thekingshotts.com,dan@thekingshotts.com,attach=yes
3002 => 1234,Dan,dan@thekingshotts.com,dan@thekingshotts.com,attach=yes
3003 => 1234,Dan,dan@thekingshotts.com,dan@thekingshotts.com,attach=yes
3004 => 1234,Dan,dan@thekingshotts.com,dan@thekingshotts.com,attach=yes
3005 => 1234,Dan,dan@thekingshotts.com,dan@thekingshotts.com,attach=yes

The format is as follows:

MAILBOX => MAILBOX PIN,NAME,EMAIL ADDRESS,SHORT EMAIL ADDRESS,OPTIONS

Now, it's time to setup our dialplan, Flowroute expects call to be made to an E.164 compliant number, eg:

COUNTRYCODE-AREACODE-NUMBER

I want to be able to make calls between extensions as well as dialing out both to US and International numbers, so, I will setup 2 dialplans:

Dialling the extension directly will call it 1-NUMBER will just dial the number like a US long distance via Flowroute, 6-E.164 will drop the leading 9 and allow me to dial out directly via flow route.

This leaves me with flexibility later to add another outbound dialplan via a different provider if needed (as I have done in the past with UK numbers)

When it comes to dialling between extensions each one will need configuration for it's voicemail, to simplify this, I've used a macro.

Putting all that together, here's the extensions.conf file:

[macro-phone]
exten => s,1,Dial(SIP/${MACRO_EXTEN},25,m)
exten => s,n,Goto(${DIALSTATUS},1)
exten => ANSWER,1,Hangup
exten => NOANSWER,1,Voicemail(${MACRO_EXTEN}@vmsetup,u)
exten => BUSY,1,Voicemail(${MACRO_EXTEN}@vmsetup,b)
exten => CONGESTION,1,Voicemail(${MACRO_EXTEN}@vmsetup,b)
exten => CHANUNAVAIL,1,Voicemail(${MACRO_EXTEN}@vmsetup,u)
exten => a,1,VoicemailMain(${MACRO_EXTEN}@vmsetup)

[stations]
exten => 3000,1,Macro(phone)
exten => 3001,1,Macro(phone)
exten => 3002,1,Macro(phone)
exten => 3003,1,Macro(phone)
exten => 3004,1,Macro(phone)
exten => 3005,1,Macro(phone)

[us_out]
exten => _1.,1,Set(CALLERID(num)=+6666666666)
exten => _1.,n,Dial(SIP/${EXTEN}@flowroute)

[flowroute_out]
exten => _9.,1,Set(CALLERID(num)=+6666666666)
exten => _9.,n,Dial(SIP/${EXTEN:1}@flowroute)

[users]
include => stations
include => us_out

Restart asterisk, that should be your lot, use the following commands to verify you have things setup:

phoneserver*CLI> sip show peers
Name/username             Host                                    Dyn Forcerport Comedia    ACL Port     Status      Description
3000/3000                 192.168.0.112                            D  Auto (No)  No             49776    Unmonitored
3001/3001                 192.168.0.112                            D  Auto (No)  No             49776    Unmonitored
3002/3002                 (Unspecified)                            D  Auto (No)  No             0        Unmonitored
3003/3003                 192.168.3.149                            D  Auto (No)  No             5060     Unmonitored
3004/3004                 192.168.3.149                            D  Auto (No)  No             5062     Unmonitored
3005/3005                 (Unspecified)                            D  Auto (No)  No             0        Unmonitored
flowroute/XXXXXXXX        216.115.69.144                              Auto (No)  No             5060     OK (41 ms)
7 sip peers [Monitored: 1 online, 0 offline Unmonitored: 4 online, 2 offline]

phoneserver*CLI> voicemail show users
Context    Mbox  User                      Zone       NewMsg
vmsetup    3000  Dan                                       1
vmsetup    3001  Dan                                       0
vmsetup    3003  Ellie                                     1
vmsetup    3004  Ellie                                     0
4 voicemail users configured.

phoneserver*CLI> dialplan show
[ Context 'default' created by 'pbx_lua' ]
  '1234' =>         hint: SIP/1234                                [pbx_lua]
  Alt. Switch =>    'Lua/'                                        [pbx_lua]

That's it, happy calling!