Upgrade 3CX to v18 and get it hosted free!

Asterisk config template

Author image

Asterisk configuration templates

Configuration templates are a means to avoid repetitive sections in Asterisk configuration files, such as extensions.conf, sip.conf or iax.conf.

For use template configurations, the syntax for defining a section is as follows:

[section](options)
label = value

The options field follows the section name immediately without any
white-space between the closeing “]” and the leading “(” of the field.

The options field define a template, refers to a template and hides
a template. Any section can be used as a template.

 

Defining a template-only section

[section](!)
label = value

The exclamation mark indicates to the config parser that this is a only
a template and should not itself be used by the Asterisk module for
configuration. The section can be inherited by other sections (see section
“Using templates” below) but is not used by itself.

Using templates (or other configuration sections)

[section](name[,name])
label = value

The name within the parenthesis refers to other sections, either
templates or standard sections. The referred sections are included
before the configuration engine parses the local settings within the
section as though their entire contents (and anything they were
previously based upon) were included in the new section.

Example 1

[foo]
permit=192.168.0.2
host=asdf
deny=192.168.0.1

[bar]
permit=192.168.1.2
host=jkl
deny=192.168.1.1

[baz](foo,bar)
permit=192.168.3.1
host=bnm

The [baz] section will be processed as though it had been written in the
following way:

[baz]
permit=192.168.0.2
host=asdf
deny=192.168.0.1
permit=192.168.1.2
host=jkl
deny=192.168.1.1
permit=192.168.3.1
host=bnm

Example 2

In top-level sip.conf:

[defaults](!)
type=friend
nat=yes
qualify=on
dtmfmode=rfc2833
disallow=all
allow=alaw

  1. include accounts/*/sip.conf

In accounts/customer1/sip.conf:

[def-customer1](!,defaults)
secret=this_is_not_secret
context=from-customer1
callerid=Customer 1 <300>
accountcode=0001

[phone1](def-customer1)
mailbox=phone1@customer1

[phone2](def-customer1)
mailbox=phone2@customer1

This example defines two phones – phone1 and phone2 with settings
inherited from “def-customer1”. The “def-customer1” is a template that
inherits from “defaults”, which also is a template.

 

Adding to an existing section

This is a closely related technique, although not strictly a template use.

[section]
label = value

[section](+)
label2 = value2

In this case, the plus sign indicates that the second section (with the
same name) is an addition to the first section. The second section can
be in another file (by using the #include statement). If the section
name referred to before the plus is missing, the configuration will fail
to load.

 

See also


Go back to Asterisk

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.