Asterisk dialplan to dial over multiple trunks with call limit set

Asterisk dialplan to dial over multiple trunks with call limit set. Today, companies use a wide range of tools to maximize profit on their telephone networks. One of those tools is an Asterisk dialplan, which helps manage incoming and outgoing calls in an efficient and organized manner. By using an Asterisk dialplan, companies can easily manage the number of calls sent and received over multiple trunks and set a specific call limit for each trunk.

An Asterisk dialplan allows companies to easily make calls over multiple trunks, while controlling the amount of minutes each trunk is used. This ensures that calls are sent and received in an efficient manner, while also ensuring that resources are used most effectively.

Additionally, the Asterisk dialplan provides functionality to add various call rules, such as setting a maximum number of calls allowed or routing calls to different trunks in different order.

By utilizing an Asterisk dialplan, companies can easily and efficiently manage calls over multiple trunks while limiting the overall call usage. This Dialplan grants companies better control in managing their outgoing and incoming calls and provides them with a more efficient and optimized communication system. Utilizing an Asterisk dialplan allows companies to better capitalize on their resources and maximize profitability on their telephone networks.

In this Article I have provided the asterisk Dialplan to dial over multiple trunks which also includes the call limit for each Trunk and dial out in random between the trunks.

Same Dialplan can be used as grouping of multiple sip trunks together with call limit set.

Asterisk Trunk Grouping

As part of this tutorial i have three sip trunks which are named as TRUNKA, TRUNKB, and TRUNKC.
The call limit for each trunks are
TRUNKA    =    6
TRUNKB    =    8
TRUNKC    =    4
The intension of this Dialplan is to dial over or grouping multiple sip trunks and each trunk is having a call limitation.

Asterisk application and Functions:

Asterisk dialplan to dial over multiple trunks with call limit set. Below are the asterisk applications and functions used in this Dialplan.


RAND(min,max) Choose a random number between min and max, used to generate a random number between 1 and 3 


Group and Group_Count function used to set the call limit for each trunk based on number of active channels count

GotoIf function used to validate the Call limit count , 

Asterisk Dialplan with Group and Group_Count

    Below is the sample Dialplan to dial over multiple trunks with call limit set and dial in random mode.

exten => _X.,1,Goto(trunk${RAND(1,3)})

exten => _X.,n(trunk1),Set(GROUP()=TRUNKA)

exten => _X.,n,Set(COUNTA=${GROUP_COUNT(TRUNKA)})

exten => _X.,n,NoOp(MY current COUNT is ${COUNTA})

exten => _X.,n,GotoIf($[${COUNTA} > 6]?trunk2:trunkA)

exten => _X.,n(trunkA),Dial(SIP/TRUNKA/${EXTEN},,Tto)

exten => _X.,n,Hangup()

exten => _X.,n(trunk2),NoOp(Dialing TRUNKB)

exten => _X.,n,Set(GROUP()=TRUNKB)

exten => _X.,n,Set(COUNTB=${GROUP_COUNT(TRUNKB)})

exten => _X.,n,GotoIf($[${COUNTB} > 8]?trunk3:trunkB)

exten => _X.,n(trunkB),Dial(SIP/TRUNKB/${EXTEN},Tto)

exten => _X.,n,Hangup()

exten => _X.,n(trunk3),NoOp(Dialing TRUNKC)

exten => _X.,n,Set(GROUP()=TRUNKC)

exten => _X.,n,Set(COUNTC=${GROUP_COUNT(TRUNKC)})

exten => _X.,n,GotoIf($[${COUNTC} > 4]?recheck:trunkC)

exten => _X.,n(trunkC),Dial(SIP/TRUNKC/${EXTEN},Tto)

exten => _X.,n,Hangup()

exten => _X.,n(recheck),Set(GROUP()=tryagain)

exten => _X.,n,Set(COUNTD=${GROUP_COUNT(tryagain)})

exten => _X.,n,GotoIf($[${COUNTD} > 1]?hangup:trunk1)

exten => _X.,n(hangup),Set(DIALSTATUS=CHANUNAVAIL)

exten => _X.,n,Hangup()

Dialplan Description

    In Priority 1 i used RAND function to choose a random number from 1 to 3  and set the variable as trunk1 or trunk2 or trunk3, with the Goto applicaiton the respective Labels will be selected eg n(trunk1) or n(trunk2) or n(trunk3)

exten => _X.,1,Goto(trunk${RAND(1,3)})

    Folowed to that trunk selection, GROUP and GROUP_COUNT are used to set a Count value based on number of active channels dialed with the variable as COUNTA, COUNTB , COUNTC, COUNTD
here COUNTD is used to recheck once for any free channel available to dialout.

exten => _X.,n(trunk1),Set(GROUP()=TRUNKA)

exten => _X.,n,Set(COUNTA=${GROUP_COUNT(TRUNKA)})

    Next with the GotoIf application the COUNTx variable value is checked with call limit value using greater than mathematical syntax (>)  ,if the count is greater than the value mentioned then proceed with next trunk.

exten => _X.,n,GotoIf($[${COUNTA} > 6]?trunk2:trunkA)

    Finally we will hangup the call with hangup status of CHANUNAVAIL for logging purpose.

exten => _X.,n(hangup),Set(DIALSTATUS=CHANUNAVAIL)

For Basic tutorial on Dial Plan check my article on Dialplan Entry Tutorial 


    Hope the Dialplan is helpful for dialing over multiple trunks with call limit also loadbalance between the trunks, if you like my article kindly subscribe ,share . For professional support reach me at [email protected]

About Me:I'm the digital marketing specialist, competent in SEO (Google, Yahoo & Bing), Google Adwords (Search, Display, Google Shopping etc.), Facebook & Instagram Advertising etc. I can work in all platforms of digital marketing & advertise the legitimate products/services in a specific country, city or all over the world.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Subscribe to our newsletter!

    Leave a Comment

    No Comments