PSTN with Cisco SPA devices, FreePBX & Asterisk

Table Of Contents


This page deals with getting PSTN lines working with Asterisk/FreePBX when using a Cisco SPA (such as a 3012 or 232D)

The author has found a few pages that get most of the way there, but each has it's own issues - and this will get you running with the SPA as a trunk for incoming & outgoing calls, inbound CLID presentation, Privacy Manager and Google Contacts not breaking Privacy Manager.

Please read ALL of the page, as it's all relevant, and please send some feedback via the Contact form if you found it useful!


FreePBX is a rather marvelous, free way to control Asterisk - which is in itself a rather marvelous, free, Voice over IP (VoIP) server.

This author has a traditional PSTN line to the house, as well as various SIP lines with their own (Direct Inbound Dialling, or DID) number. In the past, with a Cisco SPA3102, Asterisk (8 thru 11) have been mostly made to work with the SPA, so that the PSTN line would be a failover line if any of the VoIP lines failed.

Asterisk will use the SPA device as a trunk, meaning it will allow devices on the network to make calls, which can route over the PSTN line. Additionally it will allow incoming calls to the PSTN line, to ring devices on the network.

Disclaimer : These instructions were set using FreePBX and Asterisk GIT-15-caad08d on Debian Jessie, mostly built using the official FreePBX instructions, but as long as you have FreePBX 13+ and Asterisk 14 or higher, you should probably be fine!


  • The instructions below require access to the SPA advanced administrator pages (it is presumed you have access to this!)

  • The instructions below require access to the FreePBX administrator pages (it is presumed you have access to this!)

  • {Your Asterisk Server IP} should be replaced with your Asterisk server IP, i.e. (or whatever yours is)

  • {Your SPA IP} should be replaced with your SPA device IP, i.e. (or whatever yours is)

  • {Your PSTN DID} should be replaced with your PSTN line number, i.e. 01234567890

  • {Incoming SPA} should be replaced with something such as incomingspa (or whatever you want to refer to your SPA device as) - however do NOT use the same value as {Your PSTN DID}

  • {Incoming SPA Password} should be replaced with a password you will set/use for <Incoming SPA>

  • Field names to change are highlighted in italic

  • Settings to use in the fields are highlighted in bold. Anything not in bold should not be entered anywhere

  • Curly {} brackets have been used as setting identifiers - they can be removed. Any other character you see in a bold section should be copied as is

  • The instructions below are based on a Cisco SPA232D, but the fields are mostly common with SPA3102s and other devices...

Cisco SPA Configuration

    1. Open the PSTN settings tab or page, and find the SIP Settings section

    2. Check the SIP port is set to 5061 (this is normally default)

    3. Within the Proxy and Registration section

      1. Change Proxy to {Your Asterisk Server IP}:5160 (5160 is the default port for a pjsip trunk, which you'll configure later)

      2. Change Register to no (your SPA will not be registering with Asterisk)

      3. Change Use OB Proxy in Dialog to yes

      4. Change Make call without reg to yes

      5. Change Answer call without reg to yes

    4. Within the Subscriber Information Section

      1. Leave Display Name blank. If anything is in there, clear it out

      2. Change User ID to {Incoming SPA}

      3. Change Password to {Incoming SPA Password}

      4. Change Use Auth ID to yes

      5. Change Auth ID to {Incoming SPA}

    5. Within the Dial Plans section

      1. Ensure Dial Plan 1 is (xx.)

      2. Change Dial Plan 8 to (S0<:{Your PSTN DID}@{Your Asterisk Server IP}>)
        NB : Include all the () and <> brackets you see above, just NOT the {} ones!

    6. Within the VoIP-To-PSTN Gateway Setup section

      1. Change VoIP to PSTN GW Enable to yes

      2. Change VoIP Caller Auth Method to HTTP Digest

      3. Change One Stage Dialling to Yes

      4. Set each of:

        1. Line 1 VoIP Caller DP

        2. DECT Line Caller DP

        3. VoIP Caller Default DP

        4. Line 1 Fallback DP
          to none

    7. Within the VoIP Users and Passwords (HTTP Authentication) section

      1. Change VoIP User 1 Auth ID to {Incoming SPA}

      2. Ensure VoIP User 1 DP is left at 1

      3. Change VoIP User 1 Password to {Incoming SPA Password}

    8. Within the PSTN-To-VoIP Gateway Setup section

      1. Change PSTN-To-VoIP Gateway Enable to yes

      2. Change PSTN Caller Auth Method to none

      3. Change PSTN Ring Thru to no

      4. Change PSTN CID For VoIP CID to yes

      5. Change PSTN Caller Default DP to 8

    9. Within the PSTN Timer Values (sec) section

      1. Change VoIP Answer Delay to 1
        NB : Setting to 0 has sometimes meant the SPA is quicker than Asterisk and calls don't complete. Setting to 1 may mean you get 1 (or 2) ringtones calling out, but this is better than the occasional abandoned outgoing call

      2. Change PSTN Answer Delay to 2

    10. Click Submit
      Your SPA should reboot, taking about 40 seconds....
      NB: This article is not concerned with regional settings for your PSTN line. If you're a UK user, the ones found
      here are usable.

FreePBX Configuration

  1. Within the Connectivity > Trunks section

  2. Click + Add Trunk and select Add SIP (chan_pjsip) Trunk (do NOT add a chan_sip trunk)

  3. On the General tab

    1. Change Trunk Name to {Your PSTN DID}

    2. Change Outbound CallerID to {Your PSTN DID}

    3. Change Maximum Channels to 1

    4. Click Submit

  4. On the pjsip Settings tab

    1. On the General sub tab

    2. Change Username to {Incoming SPA}

    3. Change Secret to {Incoming SPA Password}

    4. Change SIP Server to {Your SPA IP}

    5. Change SIP Server Port to 5061

    6. Change Context to from-pstn

    7. Click Submit

  5. On the Advanced sub tab

    1. Change DTMF Mode to inband

    2. Ensure Permanent Auth Rejection is NOT highlighted

    3. Change Forbidden Retry Interval to 10

    4. Change General Retry Interval to 15

    5. Change Expiration to 60

    6. Change Max Retries to 10

    7. Change Qualify Frequency to 15

    8. Click Submit

  6. Within the Connectivity > Outbound Routes section

    1. Click Add Outbound Route

    2. On the Route Settings tab

    3. Change Route Name to Force PSTN

    4. Under Trunk Sequence for Matched Routes select the trunk named {Your PSTN DID}

    5. Click Submit

    6. On the Dial Patterns tab

    7. Leave Prepend blank

    8. Change Prefix to 9

    9. Change Match Pattern to X.
      Note: Not counting for spaces & blank fields, the line you entered should look something like ()9|X./

    10. Click Submit

  7. Within the Connectivity > Inbound Routes section

    1. Click Add Inbound Route

    2. Change Description to My PSTN Line

    3. Change DID Number to {Your PSTN DID}

    4. Under Set Destination choose Extension and then choose the extension you want to ring when someone calls your PSTN DID.
      Note: This author uses a ring group, so select whatever works best for you.

    5. Click the red Apply Config button at the top of the screen

If you now pick up an extension and dial a number, prefixed with a 9, you should get a call made over your PSTN line.

Similarly, if you call your PSTN DID from another number (i.e. your mobile), you should hear ringing (on your mobile) for 1-2 seconds as the SPA answers the call and process CLI, before passing the call to Asterisk, where your chosen extension or ring group should ring, presenting your mobile CLI.

You can also now use the new PSTN trunk as a failover, in the event a SIP line you may use as a primary is either busy, or out of credit etc.

Similarly, you might want to set a new Outbound Route for your emergency number (999, 112, 911 etc) and use the PSTN as the default trunk for that, set as an Emergency Route, with the dial pattern set to whatever your regional emergency number is (999, 112, 911 etc).

If you're interested, what you've basically done is:

  • Outgoing Calls

    • You've configured the SPA as a VoIP (Asterisk) to PSTN (your line) gateway

    • You've created a user ( {Incoming SPA} ) on the SPA

    • You've told FreePBX that any calls prefixed with a 9 will send calls over the trunk named {Your PSTN DID}

    • You've configured the trunk to authenticate with the SPA using the account {Incoming SPA}

    • The SPA accepts the call and initiates a PSTN call, and bridges it back to your dialling extension through Asterisk

  • Incoming Calls

    • You've configured the SPA to know about Asterisk (via {Your Asterisk Server IP} )

    • You've configured the SPA to not register with Asterisk, so it just "waits" for PSTN calls

    • You've also configured the PSTN (your line) to VoIP (Asterisk) gateway

    • You've told the SPA to wait 2 seconds when it gets a call (which is enough time to receive CLI information)

    • You've told the SPA that any incoming PSTN calls will use Dial Plan 8

    • Dial Plan 8 immediately sends all calls to a user called {Your PSTN DID} on {Your Asterisk Server IP} - using Dial Plan 8

    • Asterisk doesn't have a user called {Your PSTN DID}, but it matches the call against the trunk setup for {Your PSTN DID}

    • The Inbound Route for {Your PSTN DID} then sends the call to your extension

This method also resolves a problem the author found, where the author used Google Contacts within the FreePBX CallerID Superfecta. All calls from the SPA to Asterisk will be initiated as {Incoming SPA} before the number is replaced with the inbound CLI. Similar instructions to the above exist, but suggest you use {Your PSTN DID} where this article uses {Incoming SPA}. That will still work, but if you use Google Contacts in the Superfecta and have an entry called "Home" or "Home Phone" with your PSTN DID in, FreePBX will use that when incoming calls don't have a CLID (i.e. number withheld) - which means Privacy Manager (if you use it) never works....

This author also found that occasionally, calls over the PSTN trunk would fail on first attempt - which seemed to be down to registration issues (timeouts) on the SPA - so the lowered timing settings correct this.

Hopefully this has been of use. If it has, please let us know!