Skip to end of metadata
Go to start of metadata

In order for our phones to communicate with each other, we need to configure an account for each phone in the channel driver which corresponds to the protocol they'll be using. Since the phones are using the SIP protocol, we actually have two options for a SIP channel driver, the configuration file would be sip.conf for chan_sip, or pjsip.conf for chan_pjsip/res_pjsip (res_pjsip actually provides the configuration). You may already know that chan_pjsip is only available in Asterisk 12 or later. These files reside in the Asterisk configuration directory, which is typically /etc/asterisk. We'll include separate instructions for each channel driver below, so you have the option of using either.


For the sake of the examples in this section, you should only configure and use one SIP channel driver at a time. Advanced configuration is needed to use two different SIP channel drivers simultaneously.

Use of templates

In the below examples of channel driver configuration we will use templates. Using templates can make the configuration seem a bit more confusing at first, but in the long run it will simplify managing larger groups of extensions. Templates are used to define sections of options or settings that can then be inherited by a child section. Read about templates here. The short story is that parents are defined with a bang in parentheses after their section name, and children specify a parent in the parentheses after their section name.

On this page


Configuring chan_sip

Open sip.conf with your favorite text editor, and spend a minute or two looking at the sample file. (Don't let it overwhelm you — the sample sip.conf has a lot of data in it, and can be overwhelming at first glance.) Notice that there are a couple of sections at the top of the configuration, such as [general] and [authentication], which control the overall functionality of the channel driver. Below those sections, there are sections which correspond to SIP accounts on the system.

Now copy the sample sip.conf to something like sip.conf.sample and create a new blank sip.conf to work with.

Create the following sections of configuration in the sip.conf file. Let's name your phones Alice and Bob, so that we can easily differentiate between them.



secret=verysecretpassword ; put a strong, unique password here instead

secret=othersecretpassword ; put a strong, unique password here instead

You can read what each of the options do in the sip.conf sample file. However, let's take a look at why we are using each option here.

In the general section:

  • transport=udp: sets the general transport used by all chan_sip accounts defined in configuration if they don't have their own transport defined. We want to use UDP

In the template for friends_internal:

  • type=friend: we are using the friend type to make things easy. See the sip.conf.sample for more explanation on the section types available in sip.conf
  • host=dynamic: our phones will register to Asterisk. Otherwise we would define the IP address of the phone here.
  • context=from-internal: When Asterisk receives a call from this phone, it'll look for the dialed extension number inside this context within dialplan (/etc/asterisk/extensions.conf typically)
  • disallow=all; Don't allow any codecs to be used except what is set in 'allow'

  • allow=ulaw; Only allow the ulaw codec to be used.

In the sections for demo-alice and demo-bob:

  • secret=verysecretpassword: This is the authentication password the phone needs to use when authenticating against Asterisk.

Note that in chan_sip configuration, the authentication username for each SIP account is the section name itself. That is "demo-alice" is the name you'll have your phone authenticate against when registering. This will be covered more in the next wiki section on registering phones to Asterisk.

Configuring chan_pjsip

Take a minute to look over the pjsip.conf sample file if you haven't already. Then backup your pjsip.conf file and create a new blank one.

Add the following configuration:


;Templates for the necessary config sections




;Definitions for our phones, using the templates above

password=unsecurepassword ; put a strong, unique password here instead

password=unsecurepassword ; put a strong, unique password here instead

This configuration is roughly comparable to the chan_sip configuration in its end result. The pjsip configuration is a little more complex as the channel driver's architecture allows for more flexibility in configuration, so things tend be more modular and broken out.

Each configuration section has a type.

In the transport type section we configure the following:

  • type=transport; This defines a transport that can be used by other configuration objects/sections, such as endpoints

  • protocol=udp; We want to use the UDP protocol

  • bind=; We want to communicate over the most appropriate available interfaces.

In the endpoint template, endpoint_internal:

  • type=endpoint; This defines an endpoint; a primary configuration section that you could think of as a profile of settings for a SIP connection

  • context=from-internal; When Asterisk receives a call from this phone, it'll look for the dialed extension number inside this context within dialplan (/etc/asterisk/extensions.conf typically)

  • disallow=all; Don't allow any codecs to be used except what is set in 'allow'

  • allow=ulaw; Only allow the ulaw codec to be used.

In theauth template, auth_userpass:

  • type=auth; This defines an auth section which describes credentials used for authentication. Any particular endpoint or registration will typically reference an auth section by name.
  • auth_type=userpass; This tells Asterisk to use the 'username' and 'password' options set in this auth.  In this case we'll be setting those in the children auths that inherit this template.

In the aor template, aor_dynamic:

  • type=aor; This defines an aor section which describe location information making up an Address of Record. Endpoints make use of an AOR so that Asterisk knows where to send calls to the endpoint.
  • max_contacts=1; We want to allow up to a maximum of one registration to this AOR. That is, we are only going to have one phone registering for each AOR.

In the AOR type configuration section (see type=aor) we purposefully don't define any contacts, and instead we set "max_contacts=1", this allows us to register phones to the AORs configured for each endpoint. This accomplishes similar behavior to "host=dynamic" for account entries in the older chan_sip driver.

After the templates, you'll see the definitions of the demo-alice and demo-bob endpoints. In those, all we do is tie them to their own auth and aor sections. In their auth sections we set their unique usernames and passwords. In their aor sections we don't set anything, because the necessary settings were already set in the template.

If you want to explore pjsip configuration more deeply after you finish this PBX tutorial, check out the Configuring res_pjsip wiki section.

Loading the configuration

We have more configuration to do in the next section, so there is no need to load configuration yet. However if you do want to go ahead and load the configuration; note that for some channel drivers, like chan_pjsip, certain configuration sections (transport, system) can't be reloaded at runtime. Therefore it is easiest to restart Asterisk completely here since we have made set transport settings.

#service asterisk restart
#asterisk -rx "core restart now"
  • No labels