[How To] install and configure a full Voip server (Asterisk 13 & 16) on OpenWrt

Chan_dongle website:

http://wiki.e1550.mobi/doku.php?id=main_page

Block calls based on area code

in this example all area codes are rejected except 011 and 0141 (commented out)

;
exten => 0123456789,1,GotoIf($[${REGEX("^010" ${CALLERID(NUM)})}=1]?spam)
;exten => 0123456789,n,GotoIf($[${REGEX("^011" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^012" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^013" ${CALLERID(NUM)})}=1]?spam)
;exten => 0123456789,n,GotoIf($[${REGEX("^014" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^015" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^016" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^017" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^018" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^019" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^02" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^03" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^04" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^05" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^06" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^07" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^08" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^09" ${CALLERID(NUM)})}=1]?spam)
exten => 0123456789,n,GotoIf($[${REGEX("^00" ${CALLERID(NUM)})}=1]?spam)
;
exten => 0123456789,n,Answer()
;
exten => 0123456789,n,Set(CHANNEL(language)=en)
exten => 0123456789,n,Ringing
exten => 0123456789,n,Wait(1)
exten => 0123456789,n,Dial(SIP/200,30,r)
exten => 0123456789,n,Hangup()
;
; spam
exten => 0123456789,n(spam),Wait(0)
exten => 0123456789,n,Set(CHANNEL(language)=en)
exten => 0123456789,n,Answer()
exten => 0123456789,n,Wait(2)
exten => 0123456789,n,Playback(ss-noservice)
exten => 0123456789,n,Wait(2)
exten => 0123456789,n,Hangup()

Transfer a call coming from SIP number to another number via Dongle GSM

;
;exten => 0123456789,n,Dial(dongle/dongle0/+39024242424,60)

Automatic calls on schedule

configuration files:

nano /root/testcall.call
note: if you haven't installed nano (opkg install nano) use vi

Channel: dongle/dongle0/+39022446688 #outbound channel to be used
#Channel: SIP/0123456789@+39022446688 #alternative SIP outbound channel
MaxRetries: 0 # 0 = no retries if number is busy or unavailable, 1 = 1 retry, etc
RetryTime: 60 # wait time between retries if > 0
WaitTime: 60 # ring time
Extension: 980 # extension to launch

nano /etc/asterisk/extensions.conf

[from-pstn] ;comment out if dongle channel is not used
; [default] ;uncomment if SIP channel is used

;
; 980 audio message
;
exten => 980,1,Answer
exten => 980,n,Playback(/custom/somemessage)
exten => 980,n,Wait(2)
exten => 980,n,Hangup()

create script:

nano /root/testcall.sh

#!/bin/sh
/bin/cp /root/testcall.call /tmp/testcall.call
/bin/sleep 1
/bin/mv /tmp/testcall.call /var/spool/asterisk/outgoing/

note: the call starts as soon the .call file is placed in /var/spool/asterisk/outgoing/

give permission:

chmod 755 /root/testcall.sh

to start automatic call lanch:

/bin/sh /root/testcall.sh

you may want to put the script on crontab:


crontab -e

5 7 * * * /bin/sh /root/testcall.sh # automatic call every day at 07:05 AM

script to chek if SIP account is registered, if not reload SIP on asterisk

#!/bin/bash
#
checkifok=`/usr/sbin/asterisk -rx "sip show peer 0123456789" | grep Status | grep -wc OK`
if [[ $checkifok == 0 ]]; then
/bin/sleep 3
/usr/sbin/asterisk -rx "sip reload"
else
/bin/echo "Trunk OK" > /dev/null 2>&1
fi

1 Like

Create and use a free SIP account at https://www.ippi.com/
(and get a free INUM +883 number - https://en.wikipedia.org/wiki/INum_Initiative)

nano /etc/asterisk/sip.conf

add the following lines under appropriate sections:

[general]
register => youruser:yourpassword@ippi.fr

[ippi_incoming] ;  incoming calls from ippi
type=peer
host=ippi.fr
context=from_ippi
nat=yes
canreinvite=no

[ippi_outgoing] ; outgoing calls from ippi
type=peer
host=ippi.fr
username=youruser
secret=yourpassword
fromuser=user
fromdomain=ippi.fr
nat=yes
canreinvite=no
context=ippi_outgoing

nano /etc/asterisk/extensions.conf

[from_ippi]
;
exten => s,1,Answer()
exten => s,n,Dial(SIP/200,30,r)
exten => s,n,Hangup()
;

[ippi_outgoing]
exten => _X.,1,Dial(SIP/ippi_outgoing/${EXTEN})
; free calls between ippi accounts

Restart Asterisk after any change

/etc/init.d/asterisk restart

1 Like

If you need some help you can contact me on my INUM: +883 5100 0807 8385 free call from many voip providers (ex. www.ippi.fr, see above)

SORRY, INUM is dead :pensive:

Tool-free calls

make free calls to tool-free numbers (USA and Poland) without any SIP account or registration

nano /etc/asterisk/extensions.conf

[from-internal]

; USA tool-free calls
exten => _800NXXXXXX,1,Dial(SIP/${EXTEN}@tollfree.alcazarnetworks.com)
exten => _855NXXXXXX,1,Dial(SIP/${EXTEN}@tollfree.alcazarnetworks.com)
exten => _866NXXXXXX,1,Dial(SIP/${EXTEN}@tollfree.alcazarnetworks.com)
exten => _877NXXXXXX,1,Dial(SIP/${EXTEN}@tollfree.alcazarnetworks.com)
exten => _888NXXXXXX,1,Dial(SIP/${EXTEN}@tollfree.alcazarnetworks.com)

; Poland tool-free calls
exten => _48800XXXXXX,1,Dial(SIP/${EXTEN}@tollfree.easycall.pl)

ECHO TEST

for evaulating echo latency

;
; 982 audio test (echo)
;
exten => 982,1,Answer
exten => 982,n,Wait(1)
exten => 982,n,Playback(demo-echotest)
exten => 982,n,Echo
exten => 982,n,Playback(demo-echodone)
exten => 982,n,Wait(2)
exten => 982,n,Hangup()

Openwrt 19 and Asterisk 16 (openwrt build) are too young to use them safely in production, I prefer using stable and full tested versions, particularly for critical application like telephony, I don't want to take the risk to have my OpenWRT Voip server hacked and then lose money :wink:

For a critical mission I used Barrier Breaker and Asterisk 11, it works very well and I've never had any problem at all.

My main Voip server with dozen of trunks, extensions and lines uses Asterisk 1.6.24 (Ubuntu 10.04) since 2010 :smiley:

My next step is to try to create a SBC (Session Border Controller) on Openwrt with FreeSWITCH and maybe later on an Asterisk Realtime server (database version) on OpenWRT.

I'm moving to OpenWRT for small/medium voip server because it is very reliabile, robust, stable and has a low power consumption.

Asterisk requires about 30 MHz of CPU power per active voice channel and about 8 Mbytes per concurrent SIP call (no transcoding).
The router I prefer using is TP-Link TL-WDR4900 (PowerPC cpu @ 800 Mhz, 128 MB ram + 64 Mbytes swap with ZRAM), it can easily handle up to 20 concurrent SIP calls.

this is the main reference about voip and asterisk too:

How about tls encrypted calls? Is it much more costly for router CPU?

I've never tested encrypted calls on OpenWRT, it would be interesting to try

I try to start asterisk on vocore2 (mtk7628) and get Illegal instruction
Any ideas?

Listing is here: https://pastebin.com/pT0qsg8F

@pilovis,

First of all thank you for putting together this guide and for blazing the trail for us. It truly makes it easier co’z you did it first. Kudos to you! :smiley:

I have one question. Is it possible to setup Asterisk for internal extension use only? Though I have a couple of callcentric numbers. I just wish, at least for now, only use this internally?

Thanks much in advance!

Vince

What do you exactly mean for setting Asterisk for internal extension use only?
Callcentric numbers are not internal extensions, internal extensions are the extensions you create in sip.conf (example 200, 201, etc.)

@pilovis,

Yes, i mentioned my callcentric numbers because they were to be used for something else in the future. For now I am content to using asterisk for extension based calling.

At any rate, it looks from your response the answer to my question is “yes” it is possible to configure for internal use and no outward or inward dialing configuration needed. Let me know if I misunderstood.

In more detail what I want to do, Example, inside my house I have 3 cheap smartphones which can act as extension (1 @ living room and 1 @ my bedroom and 1 @ my kitchen) phones. So I can call my living room from my bed room. I just wanna get my feet wet with asterisk with this extension based config. Besides, I don’t have ATA (ObiTalk) equipment yet. I plan to hook up my POTS lines and configure for external calls.

Sincerely,

Vince

Yes you can.

Example for 2 internal extensions (200 & 201)

/etc/asterisk/sip.conf

 [general]
 transport=udp
 bindport=5060
 bindaddr=0.0.0.0
 nat=yes
 language=en
 allowguest=no
 srvlookup=no
 disallow=all
 allow=ulaw
 allow=alaw
 allow=gsm
 dateformat=%F %T
 alwaysauthreject=yes
 localnet=192.168.1.0/255.255.255.0 ;; change this according to your LAN configuration
 localnet=127.0.0.0/255.255.255.0
 tcpbindaddr=0.0.0.0
 tcpenable=yes
 jbenable=yes
 jbforce=yes
 jbmaxsize=250
 jbimpl=adaptive
 jbtargetextra=40
 jblog=no
 
 [200] ; internal extension ; SIP phones must be connected to LAN
 user=200
 type=friend
 secret=password_change_me
 host=dynamic
 qualify=yes
 nat=yes
 insecure=invite,port
 context=from-internal
 
 [201] ; internal extension ; SIP phones must be connected to LAN
 user=201
 type=friend
 secret=password_change_me
 host=dynamic
 qualify=yes
 nat=yes
 insecure=invite,port
 context=from-internal

/etc/asterisk/extensions.conf

[globals]

[general]
static=yes
writeprotect=yes
autofallthrough=yes

[from-internal]

;
;internal extension 200 - rings for 30 seconds
exten => 200,1,Dial(SIP/200,30)
exten => 200,2,Hangup()

;
;internal extension 201 - rings for 30 seconds
exten => 201,1,Dial(SIP/201,30)
exten => 201,2,Hangup()

Script for installing full Asterisk16 (OpenWrt 19.x), all the configurations described above remain the same.

nano /root/asterisk-install.sh

    opkg update
    opkg install asterisk16 asterisk16-app-authenticate asterisk16-app-chanisavail asterisk16-app-chanspy asterisk16-app-confbridge asterisk16-app-controlplayback asterisk16-app-disa asterisk16-app-dumpchan asterisk16-app-exec asterisk16-app-followme asterisk16-app-ices asterisk16-app-ivrdemo asterisk16-app-minivm asterisk16-app-mixmonitor asterisk16-app-mp3 asterisk16-app-originate asterisk16-app-playtones asterisk16-app-read asterisk16-app-readexten asterisk16-app-record asterisk16-app-saycounted asterisk16-app-sayunixtime asterisk16-app-senddtmf asterisk16-app-sendtext asterisk16-app-sms asterisk16-app-stack asterisk16-app-system asterisk16-app-transfer asterisk16-app-url asterisk16-app-userevent asterisk16-app-verbose asterisk16-app-waitforring asterisk16-app-waitforsilence asterisk16-app-waituntil asterisk16-app-while asterisk16-app-zapateller asterisk16-bridge-builtin-features asterisk16-bridge-holding asterisk16-bridge-native-rtp asterisk16-bridge-simple asterisk16-bridge-softmix asterisk16-cdr asterisk16-cel-custom asterisk16-cel-manager asterisk16-chan-alsa asterisk16-chan-bridge-media asterisk16-chan-console asterisk16-chan-dongle asterisk16-chan-mobile asterisk16-chan-motif asterisk16-chan-oss asterisk16-chan-phone asterisk16-chan-rtp asterisk16-chan-sip asterisk16-codec-a-mu asterisk16-codec-alaw asterisk16-codec-g722 asterisk16-codec-gsm asterisk16-codec-lpc10 asterisk16-codec-resample asterisk16-codec-ulaw asterisk16-curl asterisk16-format-g723 asterisk16-format-g726 asterisk16-format-gsm asterisk16-format-ilbc asterisk16-format-ogg-vorbis asterisk16-format-pcm asterisk16-format-siren14 asterisk16-format-siren7 asterisk16-format-sln asterisk16-format-wav asterisk16-format-wav-gsm asterisk16-func-base64 asterisk16-func-blacklist asterisk16-func-callcompletion asterisk16-func-channel asterisk16-func-config asterisk16-func-cut asterisk16-func-dialgroup asterisk16-func-dialplan asterisk16-func-groupcount asterisk16-func-hangupcause asterisk16-func-holdintercept asterisk16-func-iconv asterisk16-func-jitterbuffer asterisk16-func-module asterisk16-func-periodic-hook asterisk16-func-pitchshift asterisk16-func-shell asterisk16-func-sysinfo asterisk16-func-talkdetect asterisk16-func-uri asterisk16-func-version asterisk16-func-vmcount asterisk16-func-volume asterisk16-pbx-loopback asterisk16-pbx-spool asterisk16-pjsip asterisk16-res-adsi asterisk16-res-agi asterisk16-res-clialiases asterisk16-res-clioriginate asterisk16-res-convert asterisk16-res-hep asterisk16-res-hep-pjsip asterisk16-res-hep-rtcp asterisk16-res-limit asterisk16-res-manager-presencestate asterisk16-res-monitor asterisk16-res-musiconhold asterisk16-res-mutestream asterisk16-res-parking asterisk16-res-phoneprov asterisk16-res-pjproject asterisk16-res-pjsip-phoneprov asterisk16-res-realtime asterisk16-res-rtp-asterisk asterisk16-res-rtp-multicast asterisk16-res-security-log asterisk16-res-smdi asterisk16-res-sorcery asterisk16-res-speech asterisk16-res-srtp asterisk16-res-timing-timerfd asterisk16-res-xmpp asterisk16-sounds asterisk16-util-smsq asterisk16-util-streamplayer asterisk16-voicemail

chmod 755 /root/asterisk-install.sh

sh /root/asterisk-install.sh

1 Like

I've just added instruction above how to install Asterisk16