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:
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.
Edit 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.
[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
TL;DR ( Fast way to configure two Asterisk servers with SIP protocol) :
On Server 1 sip.conf file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[general] register => ast:mysupersecret@192.168.1.200:5060/ast [ast] type=friend host=dynamic username=ast secret=mysupersecret context=ast_incoming qualify=yes insecure=invite disallow=all allow=alaw allow=gsm allow=g729 |
On Server 2 sip.conf file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[general] register => ast:mysupersecret@192.168.1.100:5060/ast [ast] type=friend host=dynamic username=ast secret=mysupersecret context=ast_incoming qualify=yes insecure=invite disallow=all allow=alaw allow=gsm allow=g729 |