Connecting Two Asterisk Servers via SIP
You have two offices, each with their own Asterisk Server. And you want to be able to call between the two. How do you do this? How do you set this up with SIP? A few people have requested this article. Well, here it is.
Actually, I hadn’t done this before myself, before writing this article. In my search of the web, I didn’t find many good tutorials. One useful resource that I did find was the O’Reilly Asterisk: The Future of Telephony, Second Edition. This book is truly a great find. It’s a great addition to your library of ‘must haves.’ Okay, so let’s get right into it.
To keep things simple, I’m going to say that you have two locations: LocationA and LocationB. And at each of those locations, you have ServerA and ServerB. Now for this to work, each location must have it’s own set of employee extensions. So let’s say, ServerA has employee extensions: 1000-1999 and ServerB has employee extensions: 2000-2999. Now that we’ve setup the scenario, let’s get busy.
On ServerA, let’s make the below additions to the sip.conf. Under the general context, we’ll add the following register line, which will register this server to ServerB, and we’ll setup the peer too.
register => serverA:serverApass@<hostname-or-ip-of-serverB>/serverB
[serverB]
type=friend
secret=serverBpass
context=serverB_incoming
host=dynamic
disallow=all
allow=ulaw
We’ll make the following additions to the extensions.conf on ServerA as well:
[agents]
exten => 1050,1,Set(AGENT_SIP=${DB(agent_sip/1050)})
exten => 1050,n,Dial(SIP/${AGENT_SIP})
exten => 1100,1,Set(AGENT_SIP=${DB(agent_sip/1100)})
exten => 1100,n,Dial(SIP/${AGENT_SIP})
exten => 1150,1,Set(AGENT_SIP=${DB(agent_sip/1150)})
exten => 1150,n,Dial(SIP/${AGENT_SIP})
[phones]
include => agents
include => remote
[remote]
exten => _2XXX,1,Dial(SIP/serverB/${EXTEN},30)
exten => _2XXX,2,Hangup()
[serverB_incoming]
include => agents
Okay, so I’ll explain all of the above. We have a ‘phones’ context, which we have all of our SIP Phones apart of. The ‘phones’ context also includes our ‘agents’ context and ‘remote’ context. The ‘agents’ context is where we have our agent extensions, and they dial the SIP Phones. (I’m assuming that you have your agents context created based on my article discussed here.) We also have a ‘remote’ context which is what makes the connection to ServerB if we dial one of the 2XXX extensions. If we dial a 1XXX extension, it will ring the local (ServerA) agent. We have the ‘serverB_incoming’ context including the ‘agents’ context, because this is where calls are routed to if dialed from ServerB
Now let’s setup ServerB. The sip.conf will have the following additions:
register => serverB:serverBpass@<hostname-or-ip-of-serverA>/serverA
[serverA]
type=friend
secret=serverApass
context=serverA_incoming
host=dynamic
disallow=all
allow=ulaw
And the extensions.conf:
[phones]
include => agents
include => remote
[agents]
exten => 2050,1,Set(AGENT_SIP=${DB(agent_sip/2050)})
exten => 2050,n,Dial(SIP/${AGENT_SIP})
exten => 2100,1,Set(AGENT_SIP=${DB(agent_sip/2100)})
exten => 2100,n,Dial(SIP/${AGENT_SIP})
exten => 2150,1,Set(AGENT_SIP=${DB(agent_sip/2150)})
exten => 2150,n,Dial(SIP/${AGENT_SIP})
[remote]
exten => _1XXX,1,Dial(SIP/serverA/${EXTEN})
exten => _1XXX,2,Hangup()
[serverA_incoming]
include => agents
So for explaination, we have basically the reversed on ServerB. We have the same contexts. If someone on ServerA dials a 2XXX extension, it will route through the ‘remote’ context to ServerB, which will ring the local extension on ServerB.
Boy, that can look confusing. But it does work, and works rather well. You can do the samething with IAX for connecting two Asterisk Servers together. You simply need to setup your peers and register lines within iax.conf, and change the ‘remote’ context within extensions.conf
I hope this is useful to everyone.
September 11th, 2009 at 2:46 pm
Hello,
Thanks for all the great tutorials so far.
My scenario is as follows: I have multipleAsterisk servers, all connected RealTime to a common database. While the agents are connected to one server, the real traffic and the customer support calls are incoming on another server. The problem is when a client leaves a message on server A, and server A is trying to call an agent on Server B, I receive OutgoingSpoolFailed because Server B doesn’t find the sip username of the agent.
So, what I actually need is the right configuration to get these multiple servers act like an Asterisk Cluster. I am asking for the right setup of qualify and rtcachefriends, so when a server dials to a sip username it goes directly, without involving the Asterisk Server of the sip username.
I am sorry if I am not clear enough..I will try to explain better if required.
Thanks so much in advance
October 21st, 2009 at 5:05 pm
Hi Adrian,
I appreciate your comments and apologize for the delay.
Unfortunately, I have never setup a clustered Asterisk solution, so I would not be able to help you. I have only deployed multiple Asterisk boxes in the mentioned method to allow an office in Germany to communicate with an office in the USA, for example. I hope you find what you are looking for. I encourage you to come back here and share what you learn. I would love to hear how you have your system setup.
November 16th, 2009 at 6:53 am
its working steps use bane by one first configure two asterisk server.
November 16th, 2009 at 12:56 pm
Bipin,
Can you explain what you mean?