Routing calls from Zap Trunks to SIP trunks in Asterisk
So i had this situation where i have 2 Asterisk boxes, the 1st one of them had a PRI card and the 2nd one is just attached to the network through an ethernet card
Goal: redirect all of the incoming calls on the PRI to the 2nd Asterisk box through a SIP Trunk (The 2nd box holds the IVR and all of those stuff, all of the IP phones are connecting to this one), There was no decent documentation about this out there so i am documenting this and may be someone will find it useful.
Here is what you should do (I am assuming you are using an Asterisk installation that uses FreePBX):
- Create the Zap Trunk as you normally do from the FreePBX interface: Trunks -> Add Zap Trunk
- Create a SIP trunk that points to the 2nd Asterisk box, we will use this Trunk later in the configuration: Trunks -> Add SIP Trunk, scroll down to outgoing settings and add the following
- Trunk name: to-2ndAsterisk
- Peer details:
type=peer
host=<IP Address of 2nd Asterisk Box>
- Connect to the 1st Asterisk box using SSH and edit the file /etc/asterisk/dahdi-channels.conf, you will find some configuration like
group=0,11context=from-pstnswitchtype = euroisdnsignalling = pri_cpechannel => 1-15,17-31context = defaultgroup = 63
- So as you can see all of the incoming calls are directed to the from-pstn context, we will now edit this line to direct the calls to the from-pstn-custom context and do the rest of the magic in this context so the file should be as follows
group=0,11context=from-pstn-customswitchtype = euroisdnsignalling = pri_cpechannel => 1-15,17-31context = defaultgroup = 63
- Now edit the file /etc/asterisk/extensions_custom.conf and add the following at the end of the file
[from-pstn-custom]
exten => _.,1,Dial(SIP/to-2ndAsterisk/${EXTEN:2},20,rt)
So what this does is that it matches all of the calls (_.) then redirect them through the SIP trunk to the 2nd Asterisk box
- And the last step is to allow calls coming from the 1st Box to the 2nd Box, you should do IP-based authentication on the 2nd box by editing /etc/asterisk/sip_custom.conf and add the following
[1stAsterisk]
type=peer
canreinvite=no
host=<IP Address of 1st Asterisk Box>
context=from-pstn
nat=no
dtmfmode=rfc2833
disallow=all
allow=ulaw
insecure=port
qualify=yes
Of course you can now create any inbound routes on the 2nd Asterisk Box to match your needs.
I hope this works for you, and if you need any assistance please don’t hesitate to ask me in the comments
Thanks for listening






good work ahmed
thank u.. good work!