Complete Guide: Connecting FreeSWITCH with Asterisk (PRI Routing)

Published On: March 17, 2026
Follow Us
Connecting FreeSWITCH with Asterisk

This guide explains how to connect FreeSWITCH → Asterisk (PRI server) and route calls (e.g., numbers starting with 5) from FreeSWITCH to Asterisk.


🧭 Architecture Overview

SIP Phone (1000 / 1003 / etc)

FreeSWITCH
↓ (SIP Trunk)
Asterisk Server

PRI Line

PSTN (Mobile Number)

🎯 Use Case

  • Users dial numbers like: 578776152252
  • FreeSWITCH:
    • Removes 5
    • Sends 078776152252to Asterisk
  • Asterisk:
    • Routes call via PRI

⚙️ 1. Asterisk Configuration

📍 File:

/etc/asterisk/sip.conf

✅ SIP Trunk (IP-based authentication)

[from_10]
type=peer
host=192.168.200.10
context=tata
insecure=invite,port
disallow=all
allow=ulaw,alaw
qualify=yes
nat=no

🔍 Key Points

ParameterDescription
hostFreeSWITCH IP
context=tataIncoming calls go to this dialplan
insecure=invite,portDisable auth (IP-based trust)
type=peerBest for trunk

📞 2. Asterisk Dialplan

📍 File:

/etc/asterisk/extensions.conf

✅ Example:

[tata]exten => _0X.,1,NoOp(Call from FreeSWITCH)
exten => _0X.,n,Dial(SIP/${EXTEN}@TATA)
exten => _0X.,n,Hangup()

🔁 Reload Asterisk

asterisk -rx "sip reload"
asterisk -rx "dialplan reload"

⚙️ 3. FreeSWITCH Gateway Configuration

📍 File:

/usr/local/freeswitch/conf/sip_profiles/external/asterisk_pri.xml

✅ Gateway Config:

<include>
<gateway name="asterisk_pri">
<param name="proxy" value="192.168.200.19"/>
<param name="register" value="false"/>
<param name="caller-id-in-from" value="true"/>
</gateway>
</include>

🔁 Reload FreeSWITCH

fs_cli -x "reloadxml"
fs_cli -x "sofia profile external restart"

🔍 Verify Gateway

fs_cli
sofia status gateway asterisk_pri

Expected:

Status: UP

⚙️ 4. FreeSWITCH Dialplan

📍 File:

/usr/local/freeswitch/conf/dialplan/default.xml

✅ Routing Rule

<extension name="send-to-asterisk">
<condition field="destination_number" expression="^5(\d+)$"> <!-- Remove first digit (5) -->
<action application="set" data="destination_number=0${destination_number:1}"/> <!-- Send call to Asterisk -->
<action application="bridge" data="sofia/gateway/asterisk_pri/${destination_number}"/> </condition>
</extension>

👤 5. FreeSWITCH Users (Extensions)

📍 Directory:

/usr/local/freeswitch/conf/directory/default/

✅ Example (1000)

<include>
<user id="1000">
<params>
<param name="password" value="1000"/>
</params>
<variables>
<variable name="user_context" value="default"/>
<variable name="effective_caller_id_number" value="1000"/>
</variables>
</user>
</include>

🔄 Reload Users

fs_cli -x "reloadxml"

🚀 Call Flow (Working)

Example:

Extension 1003 dials → 578776152252

Flow:

1003

FreeSWITCH
↓ (dialplan match ^5\d+)
remove 5 → 078776152252

sofia/gateway/asterisk_pri

Asterisk (context=tata)

PRI

Mobile number connected

❗ Common Issues & Fixes


🔴 Issue 1: “extension not found in context default”

Cause:
Asterisk not matching SIP peer.

Fix:

  • Use type=peer
  • Ensure host=FreeSWITCH_IP
  • Use insecure=invite,port

🔴 Issue 2: “username mismatch”

username mismatch, have <1003>, digest has <FreeSWITCH>

Cause:
Auth conflict between extension and trunk.

Fix:
👉 Use IP-based authentication (no username/password)


🔴 Issue 3: FreeSWITCH error USER_NOT_REGISTERED

Cause:
Trying to call non-registered SIP user instead of gateway.

Fix:
Use:

sofia/gateway/asterisk_pri/number

🔴 Issue 4: Gateway NOREG

Normal when:

register=false

✔ Not an issue.


🔧 Debug Commands

Asterisk

asterisk -rvvv
sip set debug on

FreeSWITCH

fs_cli
sofia status
sofia status gateway asterisk_pri

🏁 Final Result

✔ FreeSWITCH extensions (1000–1010 etc.) can dial
✔ Numbers starting with 5 routed to Asterisk
✔ Asterisk sends calls via PRI
✔ No authentication issues
✔ Stable SIP trunk

sapan singh

👨‍💻 About Sapan Singh Hi, I’m Sapan Singh — a passionate software developer with a strong love for technology, gaming, and building useful digital tools.

Join WhatsApp

Join Now

Join Telegram

Join Now

Leave a Comment