simtrunkDocs

Connect simtrunk to Asterisk or FreePBX

Your SIM lines as a SIP trunk on Asterisk (PJSIP) or FreePBX, with dial-in by DID and dial-out on the SIMs.

simtrunk connects to Asterisk and FreePBX as an ordinary SIP trunk: calls to your SIMs reach the PBX addressed to each line's DID, and the PBX's outbound calls leave on the SIMs. SIP trunks to a PBX explains the trunk itself; this guide shows the PBX's side.

The steps below use the registrar mode: the PBX registers to simtrunk, as a phone does, so it works with the PBX behind NAT. If your PBX is on the internet, the register mode (simtrunk signs in to the PBX) and the peer mode work too.

1. Add the trunk in simtrunk

  1. Open SIP trunks and choose Add.
  2. Mode registrar. Choose a username and a strong password: the PBX signs in with them.
  3. Turn Dial-out on if the PBX may call out on the SIMs. It is off by default, as an open trunk is a toll-fraud risk.
  4. Add a route per line: its DID (the number the PBX sees for it, by default the line's own number) and, optionally, a dial-out prefix.

Your organization's SIP domain is on the dashboard's telephony settings, and in the API (GET /v1/sip). Below it is your-sip-domain.

2a. Asterisk (PJSIP)

Add the trunk to pjsip.conf, with the username and password from step 1. This is a starting point: adapt the transport, codecs and contexts to your setup.

pjsip.conf
[simtrunk-auth]type=authauth_type=userpassusername=TRUNK_USERNAMEpassword=TRUNK_PASSWORD; Asterisk registers to simtrunk, so simtrunk can reach it behind NAT.[simtrunk-reg]type=registrationtransport=transport-udpoutbound_auth=simtrunk-authserver_uri=sip:your-sip-domainclient_uri=sip:TRUNK_USERNAME@your-sip-domaincontact_user=TRUNK_USERNAMEretry_interval=60; Calls back to this registration are matched to the endpoint below.line=yesendpoint=simtrunk[simtrunk]type=aorcontact=sip:your-sip-domain[simtrunk]type=endpointtransport=transport-udpcontext=from-simtrunkdisallow=allallow=g722,ulaw,alawoutbound_auth=simtrunk-authaors=simtrunkfrom_domain=your-sip-domain; simtrunk sends and receives RTP on the same port.rtp_symmetric=yesforce_rport=yesrewrite_contact=yes

Then the dialplan. Dial-in arrives with the line's DID as the extension; dial-out sends the number to the trunk:

extensions.conf
[from-simtrunk]; A call to a SIM: ring extension 100 (send it to a queue or an IVR as you need).exten => _[+0-9].,1,NoOp(SIM call to ${EXTEN} from ${CALLERID(num)}) same => n,Dial(PJSIP/100,30) same => n,Hangup()[to-simtrunk]; Dial 9 then the number: it leaves on a SIM.exten => _9X.,1,Dial(PJSIP/${EXTEN:1}@simtrunk,60) same => n,Hangup()

Include to-simtrunk in your phones' context, then reload: asterisk -rx "core reload". pjsip show registrations shows the trunk as Registered.

2b. FreePBX

  1. Connectivity → Trunks → Add Trunk → Add SIP (chan_pjsip) Trunk. Name it simtrunk.
  2. On pjsip Settings → General: Username and Secret from step 1, Authentication Outbound, Registration Send, SIP Server your-sip-domain, SIP Server Port 5060, Context from-pstn.
  3. On pjsip Settings → Advanced: turn on Rewrite Contact, RTP Symmetric and Force rport if the PBX is behind NAT.
  4. Connectivity → Inbound Routes: add a route per DID from step 1, and send it to an extension, ring group, queue or IVR.
  5. Connectivity → Outbound Routes: add a route with the simtrunk trunk and the dial patterns you want on the SIMs.
  6. Apply the config. Reports → Asterisk Info → Registries shows the trunk as registered.

3. Test it

  • Dial-in: call a SIM's number from a mobile phone. The PBX rings the destination of its DID.
  • Dial-out: call a mobile number from an extension. It leaves on the SIM chosen by its DID or prefix, or the first idle line.
  • USSD: a code such as *100# dialled over the trunk is not a call; the answer comes back as a SIP MESSAGE. See USSD.

Every step is on the SIP traces page, both legs in one ladder: start there when a call fails.

No audio?

Calls that connect with no audio in one or both directions are almost always NAT. Turn on symmetric RTP and NAT handling on the PBX (rtp_symmetric, force_rport, rewrite_contact in Asterisk; the same switches in FreePBX's trunk), and make sure the PBX's RTP ports are open to simtrunk.

How is this guide?

Last updated on

On this page