๐ง FreePBX SIP Trunk Setup: Complete Configuration Guide
Summary: This comprehensive guide walks you through configuring a SIP trunk in FreePBX โ from choosing the right SIP driver (PJSIP vs chan_sip) to setting up registration, inbound/outbound routing, and troubleshooting common issues. Whether you're connecting to a major provider or a custom SIP carrier, this step-by-step tutorial ensures a smooth setup for your business phone system.
๐ Table of Contents
- 1. Understanding FreePBX SIP Trunks
- 2. PJSIP vs chan_sip: Which Driver to Use?
- 3. Prerequisites & Preparation
- 4. Step-by-Step SIP Trunk Configuration
- 5. Configuring Inbound Routes
- 6. Configuring Outbound Routes
- 7. Testing Your SIP Trunk
- 8. Common Issues & Troubleshooting
- 9. Best Practices
- 10. Frequently Asked Questions
- 11. Related Resources
๐ Understanding FreePBX SIP Trunks
A SIP trunk in FreePBX is a virtual connection that links your PBX to external networks, such as a telephone service provider or another PBX system[reference:0]. It allows you to make and receive calls over the internet using the Session Initiation Protocol (SIP). FreePBX supports two primary SIP channel drivers: chan_sip (the legacy driver) and chan_pjsip (the modern, recommended driver)[reference:1].
๐น What a SIP Trunk Does
- Outbound Calling: Routes internal extension calls to external phone numbers via your provider.
- Inbound Calling: Receives external calls and routes them to extensions, ring groups, or IVRs.
- DID Support: Handles multiple Direct Inward Dialing (DID) numbers on a single trunk.
- Cost Savings: Replaces traditional PRI or analog lines with affordable VoIP connectivity.
๐น When to Use a SIP Trunk
- You need to connect your FreePBX to an external VoIP provider.
- You want to eliminate traditional phone lines and reduce costs.
- You require scalability โ add or remove channels as your business grows.
- You need advanced features like failover routing and multiple DIDs.
โ๏ธ PJSIP vs chan_sip: Which Driver to Use?
FreePBX offers two SIP channel drivers. Here's how they compare:
| Feature | PJSIP (chan_pjsip) | chan_sip (Legacy) |
|---|---|---|
| Status | Modern, actively developed | Legacy, being phased out |
| Performance | Better performance, lower latency[reference:2] | Good but less efficient |
| NAT Handling | Enhanced NAT traversal[reference:3] | Requires more configuration |
| Multiple Registrations | Improved support[reference:4] | Limited |
| Configuration | More intuitive GUI | Requires manual peer/user details |
| Recommendation | โ Recommended for all new setups[reference:5] | Only for legacy compatibility |
๐ก Recommendation: For all new FreePBX installations, use PJSIP (chan_pjsip). It offers better performance, security, and future-proofing. The legacy chan_sip driver is still available but is gradually being deprecated[reference:6].
๐ Prerequisites & Preparation
Before you begin, ensure you have the following:
โ System Requirements
- FreePBX installed and running (version 15 or higher recommended)
- Administrative access to the FreePBX web console[reference:7]
- A SIP trunk account from a provider (e.g., NetviaVoice, Telnyx, Twilio)
- Provider credentials: SIP server, username, password (or IP whitelist)
- At least one DID (Direct Inward Dialing) number assigned
๐ Network & Firewall
- SIP Port: UDP/TCP 5060 (default) โ ensure open[reference:8]
- RTP Ports: 10000-20000 or 20000-27999 (configurable)[reference:9]
- SIP ALG: Disable SIP ALG on your router if present[reference:10]
- NAT: Enable Consistent NAT if behind NAT[reference:11]
- Firewall: FreePBX firewall auto-discovers trunks[reference:12]
โ ๏ธ Important: If your router has a SIP ALG (Application Layer Gateway) option, it is almost always better to TURN IT OFF. SIP ALG often causes more problems than it solves[reference:13].
๐ Step-by-Step SIP Trunk Configuration
Follow these steps to add a SIP trunk to your FreePBX system using the recommended PJSIP driver[reference:14][reference:15]:
- 1 Log in to FreePBX Admin โ Open your FreePBX web interface and log in with administrator credentials[reference:16].
- 2 Navigate to Trunks โ Go to Connectivity โ Trunks from the top menu[reference:17].
- 3 Add a New Trunk โ Click Add Trunk and select Add SIP (chan_pjsip) Trunk[reference:18][reference:19].
- 4 General Settings โ On the General tab:
- Trunk Name: Enter a descriptive name (e.g., "NetviaVoice-Primary")[reference:20].
- Outbound Caller ID: Set your business caller ID number[reference:21].
- Maximum Channels: Leave blank for unlimited (or set a limit)[reference:22].
- 5 PJSIP Settings โ On the pjsip Settings tab:
- Username: Your SIP provider username[reference:23].
- Secret: Your SIP provider password[reference:24].
- SIP Server: Your provider's SIP domain or IP address[reference:25].
- Context: Set to
from-internalfor internal-origin calls[reference:26]. - Authentication: Set to "Outbound"[reference:27].
- Registration: Set to "Send" to enable registration[reference:28].
- Port: Default is 5060[reference:29].
- 6 Codecs โ Scroll down and allow ulaw and alaw codecs (at minimum)[reference:30].
- 7 Submit & Apply โ Click Submit, then Apply Config to save changes[reference:31].
๐ก IP-Based Trunks: If your provider uses IP-based authentication (whitelisting), set Registration to "None" and ensure your public IP is whitelisted[reference:32].
๐ Configuring Inbound Routes
Inbound routes tell FreePBX what to do when a call comes in on your DID number[reference:33]:
- 1 Go to Connectivity โ Inbound Routes[reference:34].
- 2 Click Add Inbound Route[reference:35].
- 3 Under General:
- Description: A descriptive name (e.g., "Main Line")[reference:36].
- DID Number: Your 10-digit incoming number[reference:37].
- Set Destination: Choose where to route calls โ extension, ring group, IVR, or queue[reference:38].
- 4 Click Submit, then Apply Config[reference:39].
โ ๏ธ Note: If your DID is set to "Server" in your provider's portal, create the inbound route using the DID in E.164 format (e.g., 12125551234)[reference:40]. If set to "Device", use the SIP endpoint username[reference:41].
๐ค Configuring Outbound Routes
Outbound routes define how calls from extensions are routed to the outside world via your SIP trunk[reference:42]:
- 1 Go to Connectivity โ Outbound Routes[reference:43].
- 2 Click Add Outbound Route[reference:44].
- 3 Under Route Settings:
- Route Name: A descriptive name (e.g., "Default Route")[reference:45].
- CID: Your outbound caller ID (must match a number on the trunk)[reference:46].
- 4 Trunk Sequence: Select your newly created trunk[reference:47].
- 5 Dial Patterns: Add patterns for numbers to route:
1NXXNXXXXXXโ US 10-digit numbers[reference:48]NXXNXXXXXXโ 7-digit local numbers[reference:49][3-9]11โ Emergency/services (911, 411)[reference:50]011.โ International calls (optional)[reference:51]
- 6 Click Submit, then Apply Config[reference:52].
๐งช Testing Your SIP Trunk
After configuration, test your trunk to ensure everything works[reference:53]:
๐ Inbound Test
- Dial your DID number from an external phone (mobile or landline).
- Check if the call reaches the destination you set in the inbound route.
- Verify caller ID display and audio quality.
๐ค Outbound Test
- Dial an external number from any extension.
- Confirm the call connects and audio works both ways.
- Check that the correct outbound route is applied.
๐ก Pro Tip: Check Reports โ Asterisk Log or /var/log/asterisk/full for detailed call logs and error messages if something isn't working.
๐ Need Expert Help with FreePBX? NetviaVoice Can Assist
Our VoIP specialists can help you configure SIP trunks, optimize your FreePBX system, and troubleshoot any issues โ ensuring a reliable and cost-effective phone system.
Visit NetviaVoice๐ง Common Issues & Troubleshooting
| Issue | Possible Cause | Solution |
|---|---|---|
| Trunk not registering | Incorrect username/password, wrong SIP server, firewall blocking port 5060 | Double-check credentials. Verify SIP server domain. Ensure port 5060 is open[reference:54]. |
| Inbound calls not working | DID not configured correctly, inbound route missing or misconfigured | Verify DID number in trunk and inbound route. Check provider's DID routing[reference:55]. |
| Outbound calls fail | Dial pattern mismatch, outbound route not assigned to trunk | Review dial patterns. Ensure trunk is selected in the outbound route[reference:56]. |
| Audio issues (one-way or no audio) | Firewall blocking RTP ports, NAT issues | Open RTP ports (10000-20000). Configure NAT settings in Asterisk SIP Settings[reference:57]. |
| Registration failed โ authentication error | Incorrect secret or username format | Verify the username and secret exactly as provided by your carrier[reference:58]. |
๐ก Quick Troubleshooting: Always check the Asterisk Log (Reports โ Asterisk Log or /var/log/asterisk/full) for detailed error messages โ this is the best place to start diagnosing issues.
๐ Best Practices for FreePBX SIP Trunks
๐น Security
- Use TLS/SIPS for encrypted SIP signaling.
- Enable SRTP for encrypted media.
- Set strong passwords for SIP credentials.
- Disable SIP ALG on your router[reference:59].
- Use failover trunks for redundancy.
๐น Performance
- Use PJSIP driver for better performance[reference:60].
- Configure codec preferences (ulaw/alaw first).
- Set appropriate RTP port ranges in Asterisk SIP Settings.
- Monitor call quality and adjust as needed.
๐น Maintenance
- Keep FreePBX modules updated.
- Regularly test failover trunks (if configured).
- Review CDR (Call Detail Records) for billing and analysis.
- Document trunk configuration for future reference.
๐น Network
- Use a static public IP or reliable DDNS for IP-based trunks.
- Configure QoS to prioritize SIP/RTP traffic.
- Ensure sufficient bandwidth for concurrent calls.
- Consider VPN for secure inter-site trunking.
โ Frequently Asked Questions
PJSIP is the modern SIP channel driver in FreePBX, offering better performance, enhanced NAT handling, and improved support for multiple registrations. chan_sip is the older driver, still supported but gradually being phased out. PJSIP is recommended for all new FreePBX installations[reference:61].
Log in to FreePBX Admin, go to Connectivity > Trunks, click Add Trunk, and select Add SIP (chan_pjsip) Trunk. Enter the trunk name, username, password, SIP server, and configure authentication settings. Then create inbound and outbound routes to complete the setup[reference:62][reference:63].
SIP signaling uses port 5060 (UDP/TCP) by default. RTP media ports typically range from 10000-20000 or 20000-27999 (configurable in Asterisk SIP Settings). Ensure these ports are open in your firewall for proper call flow[reference:64].
Common causes include incorrect username/password, wrong SIP server domain, firewall blocking port 5060, or NAT issues. Check the Asterisk log (/var/log/asterisk/full) for detailed error messages. Also verify that your provider's IP is whitelisted if using IP-based authentication[reference:65].
Go to Connectivity > Inbound Routes, click Add Inbound Route. Enter a description, set the DID Number (your incoming number), and choose a destination (extension, ring group, IVR, etc.). Save and apply configuration. Repeat for each DID number you have[reference:66].
๐ Related Articles & Resources (NetviaVoice)
Explore more guides to optimize your VoIP infrastructure:
โจ For personalized assistance with FreePBX configuration, SIP trunk setup, or VoIP migration, visit our Services page or contact our team directly.
๐ข Need help setting up your FreePBX SIP trunk? Let NetviaVoice guide you.