How to Connect a GSM Gateway to FreePBX (Step by Step)
To connect a GSM gateway to FreePBX, add it as a SIP (chan_pjsip) trunk under Connectivity › Trunks, enter the gateway’s SIP server, port, transport and credentials, choose G.711 or G.722 codecs, then create an outbound route with dial patterns and an inbound route for the mobile number. The steps below apply to FreePBX 16 and 17.
We use neutral wording for the gateway side so the guide works with any GSM gateway. If you use GSMCalls, every value you need is shown in the GSMCalls portal under SIP Trunks.
Before you start
- FreePBX 16 or 17 with admin access. FreePBX 17 runs on Debian 12 and uses chan_pjsip only; on FreePBX 16 use the chan_pjsip trunk type too.
- Gateway SIP details: the SIP server (hostname or IP), port, transport (UDP, TCP or TLS) and credentials. In GSMCalls these are shown in the portal under SIP Trunks.
- Authentication method: registration (FreePBX registers to the gateway with a username and secret) or IP authentication (the gateway trusts your PBX’s public IP). This guide uses registration and notes the IP-auth differences.
- Network basics: your PBX’s public IP, whether it sits behind NAT, and firewall access for SIP and the RTP port range (FreePBX defaults to UDP 10000–20000).
- Lawful use: mobile lines on plans that permit connection to a PBX — see our acceptable use policy.
Step 1: Check SIP transport and NAT settings
Go to Settings › Asterisk SIP Settings. On the General SIP Settings tab, check the NAT section: set External Address to your public IP (or use Detect Network Settings) and list your LAN subnets under Local Networks. Wrong values here are the most common cause of one-way audio.
On the SIP Settings [chan_pjsip] tab, make sure the transport you plan to use is enabled — UDP and TCP are usually on; TLS needs a certificate selected from Admin › Certificate Management. Submit and click Apply Config.
Step 2: Create the PJSIP trunk
Go to Connectivity › Trunks › Add Trunk › Add SIP (chan_pjsip) Trunk.
General tab
- Trunk Name: something descriptive, such as “GSM-Gateway-Site1”.
- Outbound CallerID: normally leave empty — a GSM line presents the SIM’s own number to the mobile network.
- Maximum Channels: set to the number of concurrent calls the gateway can carry (one per active line), so FreePBX doesn’t send calls it cannot place.
pjsip Settings › General
| Field | Value for registration | Value for IP authentication |
|---|---|---|
| Username | Trunk username from the gateway | Not used |
| Secret | Trunk password from the gateway | Not used |
| Authentication | Outbound | None |
| Registration | Send | None |
| SIP Server | Gateway hostname or IP | Gateway hostname or IP |
| SIP Server Port | As provided (commonly 5060 for UDP/TCP, 5061 for TLS) | As provided |
| Transport | The matching udp, tcp or tls transport | The matching transport |
| Context | from-pstn (default) | from-pstn (default) |
For GSMCalls, copy the SIP server, port, transport and credentials exactly as shown in the portal under SIP Trunks. If you use IP authentication, also add the gateway’s IP under Advanced › Match (Permit).
pjsip Settings › Advanced
- DTMF Mode: RFC 4733 (the successor to RFC 2833) is the safest choice for DTMF with IVRs and voicemail.
- Rewrite Contact, RTP Symmetric, Force rport: set to Yes when the PBX or the gateway sits behind NAT.
- Qualify Frequency: leave at the default (60 seconds) so FreePBX notices if the trunk goes down.
- Media Encryption: if you use TLS and the gateway supports SRTP, choose SRTP via in-SDP so both signalling and audio are encrypted.
- Contact User / From User: only set these if the gateway asks for a specific value to identify inbound calls.
pjsip Settings › Codecs
Enable only the codecs you need and drag them into order. For a GSM gateway that means G.711 — alaw in most of the world, ulaw in North America and Japan — plus G.722 first if the gateway offers wideband HD audio. Avoid enabling many codecs “just in case”: it invites transcoding and codec mismatches.
Click Submit, then Apply Config.
Step 3: Create an outbound route
Go to Connectivity › Outbound Routes › Add Outbound Route. On the Route Settings tab, give it a name (for example “Mobile-via-GSM”) and add the new trunk under Trunk Sequence for Matched Routes. Add a second trunk below it if you want calls to fail over to a regular SIP trunk when every mobile line is busy.
On the Dial Patterns tab, add patterns that match only the numbers this trunk should carry. FreePBX pattern syntax uses X for any digit, Z for 1–9, N for 2–9, [ ] for ranges and . for “one or more of anything”:
| Goal | Prepend | Prefix | Match pattern |
|---|---|---|---|
| North American 10-digit numbers | 1 | NXXNXXXXXX | |
| North American 11-digit numbers | 1NXXNXXXXXX | ||
| UK mobile numbers | 07XXXXXXXXX | ||
| Users dial 9 first, strip the 9 | 9 | NXXNXXXXXX |
Keep patterns specific. Mobile lines are for national calls under your carrier’s plan, so don’t send international or premium-rate patterns to a GSM trunk. Submit and Apply Config.
Step 4: Create an inbound route
Calls to the SIMs’ mobile numbers arrive from the gateway into the from-pstn context. Go to Connectivity › Inbound Routes › Add Inbound Route:
- Description: for example “Mobile line – Sales”.
- DID Number: the number the gateway sends in the call (often the SIM’s number in national or E.164 format). Check the first test call in the CDR or Asterisk log to see exactly what arrives, and match it here. Leave blank to create a catch-all route.
- Set Destination: an extension, ring group, queue or IVR.
Each mobile number can have its own route, just like a DID from a SIP provider. Submit and Apply Config.
Step 5: Test the trunk
- Open the Asterisk CLI with asterisk -rvvv and run pjsip show registrations. The trunk should show as Registered (with IP authentication there is no registration; check pjsip show endpoints instead).
- Place an outbound call from an extension to a mobile number and confirm two-way audio.
- Call the mobile number from another phone and confirm it reaches the right destination.
- Test DTMF by calling an IVR or voicemail and pressing keys.
- Check Reports › CDR Reports for correct numbers and durations.
Troubleshooting common problems
Registration fails with 401 or 403
A single 401 Unauthorized on the first REGISTER is normal: SIP uses a digest challenge, and FreePBX answers it with the credentials. A repeated 401, or a 403 Forbidden, means the username, secret or auth username is wrong, or your IP is not allowed. Re-copy the credentials, check for trailing spaces, and turn on pjsip set logger on to see the exchange. A 408 Request Timeout usually means a firewall or the wrong port or transport.
One-way or no audio
Almost always NAT. Check External Address and Local Networks (Step 1), set Rewrite Contact, RTP Symmetric and Force rport to Yes, and make sure the RTP range is open on your firewall — and forwarded if the PBX sits behind a router. Disable SIP ALG on the router; it often rewrites SIP incorrectly.
Calls fail with 488 Not Acceptable Here
The two sides share no codec. Compare the trunk’s Codecs tab with what the gateway offers and enable a common one, usually alaw or ulaw.
DTMF doesn’t work
Set DTMF Mode to RFC 4733 on the trunk and confirm the gateway uses the same method. Inband DTMF is unreliable once audio is compressed.
Choppy or robotic audio
Look for jitter and packet loss between the PBX and the gateway, and for weak mobile signal on the line that carried the call. A platform that reports per-line signal and per-call quality makes this quick to separate.
Next steps
With the trunk live, you can add more sites and route by destination, customer or time of day. GSMCalls presents each site as a standard SIP trunk to FreePBX, over UDP, TCP or TLS, with CDRs, minute profiles and monitoring in the cloud portal. See GSM gateway for FreePBX, the Asterisk and 3CX equivalents, pricing, or book a demo.
Frequently asked questions
Should I use chan_sip or chan_pjsip for a GSM gateway trunk?
Use chan_pjsip. chan_sip is deprecated and was removed in Asterisk 21, and FreePBX 17 supports PJSIP only.
Which codec should I use between FreePBX and a GSM gateway?
G.711 (alaw outside North America and Japan, ulaw inside them) is the safe default. Put G.722 first if the gateway provides wideband audio end to end.
Why does my trunk show 401 Unauthorized?
One 401 is a normal digest challenge. If it repeats, the username, secret or auth username is wrong or your IP is not allowed on the gateway.
How do I send inbound mobile calls to a specific extension?
Create an inbound route whose DID Number matches the number the gateway sends for that SIM, and set its destination to the extension, ring group or queue.
Can FreePBX fail over from a GSM trunk to a SIP provider?
Yes. List both trunks in the outbound route’s trunk sequence; FreePBX tries the next trunk when the first is busy or fails.