Asterisk Sample Config

Lecture and Lab: Use sample config files to build a working PBX

.

CONFIG FILES:

    • sip.conf – SIP peers for extensions and carriers
    • extensions.conf – Phone system dialplan for call routing
    • voicemail.conf – Voicemail users
    • followme.conf – Route unaswered calls to a user’s mobile phone

ASTERISK CONFIG FILES

  • Leave rest as default
  • This config is for SIP only PBX
  • No GUI interface for end users
  • All configuration is done using text config files

CREATE CUSTOM RECORDINGS

  • Make a custom recording for your auto attendant greetings
  • Configure voicemail accounts
  • Record name for voicemail account, option 3
  • Record unavailable greeting for voicemail, option 1

CUSTOMIZED DIALPLAN

  • Edit extensions.conf to route your inbound phone numbers
  • Edit extensions.conf to set outbound caller ID numbers
  • Edit followme.conf to dial alternate phone number if not answered

Codec Options:

  • G.711: Most common codec (ulaw/alaw), 64 kbit/s bitrate, free
  • G.729: Second most common codec, 8kbit/s bitrate, $ licensed
  • GSM: Common low bandwidth codec, 13 kbit/s bitrate, free
  • Many others with lower bitrates to higher bitrates for better quality
  • .
      • .711
      • LPC10
      • GSM
      • iLBC
      • G.726
      • G.722
      • ADPCM

Codecs reside in /usr/lib/asterisk/modules

You need to download the appropriate codec for your CPU

cat /proc/cpuinfo

and look your cpu up to get an idea for codec

EXAMPLE:

Download G.729 codec

Browse http://asterisk.hosting.lv

copy link for your asterisk version

Asterisk11

Go down to

NOTES:

module load and module unload is used in asterisk to load or unload codecs

If you want to use a specific codec for extensions or SIP Carrier

vi /etc/asterisk/sip.conf

edit allow=ulaw to allow=g729

allow=ulaw

add the allow=ulaw as a failback incase carrier doesn’t support G729

Included with Asterisk

Voicemail setup (voicemail.conf)

vi /etc/asterisk/voicemail.conf

.

  • Scroll down to bottom of file

Should see example imapvm same sequence sort of

    • Create new name in example:

;[internal-vm]

[internal-vm]

101 => 123456,John Doe,john-email@gmail.com

102 => 123456,Jane Doe,jane-email@gmail.com

What it means:

101 => 123456,John Doe,john-email@gmail.com ** 101 is exten 123456 is password, name, email

  • What we just did was create extension 101 and 102 with password 123456 and name and email for voicemail, we will add this context to sip.conf and enable voicemail

Outbound calling (extensions.conf)

Edit /etc/asterisk/extensions.conf

You’ll create your dialplan here to making outbound calls with your SIP CARRIER

voipms has a sample sip.conf and extensions.conf you can use and replace with your sub_account username, here is what outbound looks like:

[voipms-outbound]

exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@voipms)

exten => _1NXXNXXXXXX,n,Hangup()

exten => _NXXNXXXXXX,1,Dial(SIP/1${EXTEN}@voipms)

exten => _NXXNXXXXXX,n,Hangup()

exten => _011.,1,Dial(SIP/${EXTEN}@voipms)

exten => _011.,n,Hangup()

exten => _00.,1,Dial(SIP/${EXTEN}@voipms)

exten => _00.,n,Hangup()

Important to know that you need this also in your dialplan:

[mycontext]

; Make sure to include inbound prior to outbound because the _NXXNXXXXXX handler will match the incoming call and create a loop

include => voipms-inbound

include => voipms-outbound

Creating a SIP Carrier and adding it (sip.conf/extensions.conf)

You will need to find a SIP provider and signup, I used voip.ms and dumped $25 into it for testing..

.

It has support for Asterisk

It will give you the sample configuration for Asterisk sip.conf

edit /etc/asterisk/sip.conf

find the line marked [general]

under there insert your registration tag you got from the sample and replace with needed information:

register => 220450_USERNAME:PASSWORD..@chicago.voip.ms:5060

Go to bottom need to insert the SIP CARRIER information do that before EXTENSIONS line

; ## SIP CARRIERS PEERS ###

[voipms]

canreinvite=no

context=mycontext

host=chicago.voip.ms ;(one of our multiple servers, you can choose the one closer to your location)

secret=PASSWORD.. ;your password

type=peer

username=220450_USERNAME ;(Replace with your 6 digit Main SIP Account User ID or Sub Account )

disallow=all

allow=ulaw

fromuser=220450_USERNAME;(Replace with your 6 digit Main SIP Account User ID or Sub Account username)

trustrpid=yes

sendrpid=yes

insecure=invite

nat=yes

edit /etc/asterisk/extensions.conf

** ADD THE FOLLOWING TO THE BOTTOM **

[mycontext]

; Make sure to include inbound prior to outbound because the _NXXNXXXXXX handler will match the incoming call and create a loop

include => voipms-inbound

include => voipms-outbound

[voipms-outbound]

exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@voipms)

exten => _1NXXNXXXXXX,n,Hangup()

exten => _NXXNXXXXXX,1,Dial(SIP/1${EXTEN}@voipms)

exten => _NXXNXXXXXX,n,Hangup()

exten => _011.,1,Dial(SIP/${EXTEN}@voipms)

exten => _011.,n,Hangup()

exten => _00.,1,Dial(SIP/${EXTEN}@voipms)

exten => _00.,n,Hangup()

; inbound context example for your DID numbers, do not add the number 1 in front

[voipms-inbound]

exten => 7863643011,1,Answer() ;your DID

edit /etc/asterisk/sip.conf

go to our extensions we setup 101 and 102 need to replace context=internal to context=mycontext

go to asterisk -rvvv

reload

sip show peers

sip show registry

Echo Test call with voip.ms SIP Carrier (extensions.conf)

You can dial 4443 from your SIP device to start the echo test

Need to make changes for this to work you will see some errors

[Aug 30 14:59:40] NOTICE[2099][C-00000005]: chan_sip.c:25503 handle_request_invite: Call from ‘101’ (172.16.24.173:58413) to extension ‘4443’ rejected because extension not found in context ‘mycontext’.

edit /etc/asterisk/extensions.conf

add the following

exten => 4443,1,Answer

exten => 4443,n,NoOp(Echo-Test-4443)

exten => 4443,n,Dial(4443@voipms)

open asterisk -rvvv

reload

dial again, get new error

then open /etc/asterisk/extensions.conf

edit the following

Aug 30 15:02:10] WARNING[2223][C-00000006]: app_dial.c:2330 dial_exec_full: Dial argument takes format (technology/resource)

== Spawn extension (mycontext, 4443, 3) exited non-zero on ‘SIP/101-00000006’

exten => 4443,n,Dial(4443@voipms) ** change to exten => 4443,n,Dial(SIP/4443@voipms) **

asterisk -rvvv

reload

dial and it’s a success!

Troubleshooting

Basic troubleshooting issues you might experience in Asterisk

— Executing [103@internal:1] Answer(“SIP/101-00000003”, “”) in new stack

— Executing [103@internal:2] NoOp(“SIP/101-00000003”, “Internal-phone-call”) in new stack

— Executing [103@internal:3] Dial(“SIP/101-00000003”, “SIP/103,12,r”) in new stack

  1. [Aug 30 11:43:24] WARNING[2128][C-00000002]: chan_sip.c:6071 create_addr: Purely numeric hostname (103), and not a peer–rejecting!
  2. [Aug 30 11:43:24] WARNING[2128][C-00000002]: app_dial.c:2437 dial_exec_full: Unable to create channel of type ‘SIP’ (cause 20 – Subscriber absent)

== Everyone is busy/congested at this time (1:0/0/1)

— Executing [103@internal:4] VoiceMail(“SIP/101-00000003”, “103@internal-vm”) in new stack

  1. [Aug 30 11:43:24] WARNING[2128][C-00000002]: app_voicemail.c:6321 leave_voicemail: No entry in voicemail config file for ‘103’

1 This error occurred because the extension/user was not defined in sip.conf


2 This error occurred because the phone does not exist in sip.conf

1 This error occurs because a voicemail is not defined in voicemail.conf
View mailbox users, voicemail show users ** lists users from /etc/asterisk/voicemail.conf with voicemail accounts**

Installing and Configuring Asterisk CentOS 7

You will need a Linux OS to install Asterisk.

 

 

The above is version 7 32 or 64 depending on CPU and is a minimal install

 

  • Stuff to do once Linux OS is installed
  • vi /etc/sysconfig/network-scripts/ifcfg-eth0
  • Make sure onboot=yes change that from disabled
  • service network restart
  • ip addr show ( should show an ip address for eth0 )
  • yum -y update ( update the system without prompting )
  • shutdown -r now ( reboot system after updating to apply )
  • cd /usr/src
  • yum -y install wget ( install wget package to download files from the internet)
  • You can either wget Asterisk from up above or use CentOS repos to install Asterisk ( A word of caution is to make sure it is a LTS version or certified version of Asterisk)
  • yum method: yum -y install asterisk ( this will install asterisk with all dependencies )
  • It is also a good idea with CentOS to install the epel-release repo
  • yum -y install epel-release; yum repolist ( should install the epel-release and then list repos and should see epel)
  • If you download asterisk using wget
  • wget url-for-asterisk.tgz
  • tar zxfv name.of.file.tgz
  • cd name.of.folder
  • ** Have to install some custom files to run asterisk if you just run ./configure it’ll error out and complain**
  • yum -y install gcc gcc-c++ libxml2-devel sqlite-devel ncurses-devel
  • ./configure
  • make menuselect
  • make
  • make install
  • make samples ( install sample configuration files )
  • Have Asterisk start as a service
  • cd /usr/src/name-of-folder; cp contrib/init.d/rc.redhat.asterisk /etc/init.d/asterisk
  • vi /etc/init.d/asterisk ( locate AST_SBIN= ) replace that with AST_BIN=/usr/sbin/
  • service asterisk start ( if it complains about 64bit libraries do the following)
  •  ln -s /usr/lib/libasteriskssl.so.1 /usr/lib64/libasteriskssl.so.1 ( only if it complaines about 64bit .so file)
  • Disable selinux by vi /etc/selinux/config ( change SELINUX=enabled to SELINUX=disabled
  • shutdown -r now ( need to reboot otherwise selinux will enforce still )
  • chkconfig asterisk on ( enable to start on reboot ) or if chkconfig does not exist because of systemctl then use systemctl enable asterisk
  • systemctl status iptables or service iptables status ( if iptables is running need to disable )
  • systemctl disable iptables ( or firewalld ) service iptables stop systemctl stop iptables
  • chkconfig iptables off systemctl disable firewalld