Connecting two Asterisk servers using SIP protocol

If you have two office branches in two different locations, Both branches are running its own Asterisk server. There may be a time to make calls between these servers, In this case, you need to configure a Trunk between them. So in this article we will try to setup the SIP trunk between the two Asterisk servers.

Connecting Two asterisk servers using SIP:

We have two asterisk servers so we will start it by editing configuration files on both servers. We need to edit the sip.conf file and extensions.conf file of both servers. Let’s start with the sip.conf file.

Note : For our convenience I am using names for both servers and my first server name is serverA and second one name is serverB. so I will use these names to represent the both servers throughout this article.

Quick view of my present Setup:
serverA IP Address: 192.168.18.100
serverB IP Address: 192.168.18.75

Edit the SIP.conf file:

In serverA add the following data to the sip.conf file.
Register your server with other end server using register parameter in sip.conf.[general]
register => serverA:mysupersecret@192.168.18.75/serverB

[ServerB]
type=friend
context=serverB_incoming
host=dynamic
disallow=all
allow=ulaw
allow=gsm
secret=mysupersecret

; I also want to test my setup so for testing, I am creating one extra extension.
[1000]
type=friend
context=test
disallow=all
allow=ulaw
allow=gsm
host=dynamicThen add the server A details in serverB sip.conf.[general]
register => serverB:mysupersecret@192.168.18.100/serverA

; Create one extension for the other end Asterisk server
[ServerA]
type=friend
context=serverA_incoming
host=dynamic
disallow=all
allow=ulaw
allow=gsm
secret=mysupersecret[2000]
type=friend
context=test
disallow=all
allow=ulaw
allow=gsm
host=dynamic

The register parameter is responsible for registering our Asterisk server to other end Asterisk server. and Please note that we are using slash ( / ) and username of other asterisk server, This will tell another end asterisk to use this name as Digest username while establishing the call. If you forgot to specify this option then, there is a very good possibility of getting username mismatch error.

you’ll see the following at your Asterisk CLI:

[Jun 26 16:26:15] WARNING[4561]: chan_sip.c:8117 check_auth: username mismatch, have <serverA>, digest has <s>

Dialplan Configuration:

Now Edit the extension.conf file to route appropriate calls to Another end Asterisk server.

ServerA extensions.conf :
[test]
exten => _XXXX,1,Dial(SIP/${EXTEN}@serverB,30,r)
exten => _XXXX,n,playback(unavail)  ; play unavailable sound file, or use voicemail

ServerB extensions.conf :
[test]
exten => _XXXX,1,Dial(SIP/${EXTEN}@serverA,30,r)
exten => _XXXX,n,playback(unavail)  ; play unavailable sound file, or use voicemail

Now we need to test our setup, To test our setup registrar to one asterisk server using our testing extension and dial other end extension. If everything went well other end phone will ring.

Troubleshooting :

You can see the registration status of SIP trunk by running below command in the Asterisk CLI
sip show registry

You can also see SIP messages in by running below command in Asterisk CLI.
sip set debug on

Congrats, You are successfully configured one SIP trunk between two Asterisk servers.

TL;DR ( Fast way to configure two Asterisk servers with SIP protocol) :

If you don’t have enough time to setup everything like above. Then just copy and paste the following lines into your two asterisk servers.

On Server 1  sip.conf file:

IP Address of Server  1: 192.168.1.100

On Server 2  sip.conf file:

IP Address of Server  2: 192.168.1.200

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

Leave a Reply