Asterisk SIP Trunking : Asterisk as SIP Client

4.9 (97.14%) 7 votes

Asterisk SIP Trunking : Asterisk as SIP Client

The following Configuration Guides are intended to help you connect your SIP Infrastructure (IP-PBX, SBC, etc) to a Asterisk based solution.

Be aware, due to the large number of versions, variations, add-ons, and options for many of these systems, the settings you see may differ from those shown in our Configuration Guides.

As such, these documents are intended as general guidelines, rather than configuration templates. There is an assumption of familiarity with your network and SIP infrastructure, and how they work.

A SIP trunk is often defined using many buzz and marketing words throughout the web, but, what it basically is, is a two-way connection to a VOIP-provider, that routes the calls you send to it, out on the PSTN for you, and charges you for the calls you make. If you also have a DID (Direct Inward Dialing) number at the provider, calls made to you are forwarded to your Asterisk PBX, then you switch the calls as you see fit. Through a trunk, many calls can be sent, the limit is only your bandwidth and computer resources at the machine where your Asterisk runs, unless your VOIP-provider, or you for that matter, limit the number of calls in some way (by configuring the PBX at either end of the trunk), that are allowed to go through it.

When you have bought a suitable SIP trunk, and have gotten your account information from the provider, we can continue, and set it up.

SIP trunk configuration would be done in two basic files.

  • sip.conf
  • extensions.conf


Let’s Start to configure SIP trunk

In sip.conf under [general] add a register definition:


register => user:secret:authuser@host:port/extension

register => fromuser@fromdomain:secret@host

register => fromuser@fromdomain:secret:authuser@host:port/extension


  • user is the user id for this SIP server
  • authuser is the optional authorization user for the SIP server
  • secret is the user’s password
  • host is the domain or host name for the SIP server. This SIP server needs a definition in a section of its own in SIP.conf
  • port send the register request to this port at host. Defaults is 5060
  • /1234 is the Asterisk contact extension. 1234 is put into the contact header in the SIP Register message. The contact extension is used by remote SIP server when it needs to send a call to Asterisk.

If you have problems with your network connection going up and down (e.g. an unreliable cable connection) and you keep losing your sip registry, you may want to add registerattempts and registertimeout settings to the general section above the register definitions.

Setting registerattempts=0 will force Asterisk to attempt to reregister until it can (the default is 10 tries). registertimeoutsets the length of time in seconds between registration attempts (the default is 20 seconds).

Check the server Registration

Check the success of your own server’s sip registrations at the CLI with “SIP SHOW REGISTRY“, whereas to obtain a list of clients that registered with your server with the help of “SIP SHOW PEERS“.

Outbound Call Setting from sip trunking

The server definition for outgoing calls looks like this:

username=2345 or IP address of the SIP server
context=from-sipprovider ; this section will be defined in extensions.conf

Outbound Calling setting in extensions.conf

In extensions.conf, use a statement like this:

exten => _9.,1,Dial(SIP/${EXTEN:1}@sipprovider-out,30,r)

Please note that the ${EXTEN:1} variable here extracts all but the first characters from the current extension will be escaped.

Incoming Call setting in extensions.conf

exten => 1234,1,Answer ; 1234 is the contact extension, default contact extension is “s”
exten => 1234,2,Dial(SIP/111,25,Ttr) ; incoming calls are redirected to SIP telephone with number 111
exten => 1234,3,Hangup





For any query or issue, feel free to discuss on

Leave a Reply

%d bloggers like this: