1
ewpratten.com/content/blog/2022-02-14-personal-pbx.md
Evan Pratten 66528d6284 Revert "The great migration"
This reverts commit f184e610368cedc50f9dd557953c83f70b55f329.
2024-11-14 12:45:30 -05:00

6.5 KiB

title description date tags draft extra aliases
I built my own private telephone network Nobody makes phone calls anymore 2022-02-14 project pbx true
auto_center_images
true
/blog/personal-pbx

Over the past few months, I have built my own internet backbone router (and an internet exchange). So logically, the next step is to branch off into telephony... right?

Eh, even if I never get any practical use out of any of this in the end, at least its content for the blog.

A simplistic introduction to telephone networking

This is all coming from someone that has very little experience with the telephony world, but I have managed to make all my gear work, so this can't go too badly.

As far as I have ever been concerned, the telephone network looks as follows:

The magical phone network

But in reality, it looks a little more like the internet (I guess that makes sense, since dialup was a thing).

The magical phone network, with more phones

The Dark Magic still exists, and I am still not entirely sure whats going on there. Presumably some kind of routing protocols exists to handle country codes and such, but I have had no need (yet) to explore this further.

Continuing on with terminology, Phones are simply endpoints. Such endpoints could be cellphones, VOIP clients, automated answering machines, etc. Carriers are the same as the internet world. Big companies that own switching gear and phone number blocks they charge you to connect up to.

Finally, PBXes. A Private Branch eXchange (PBX) combines the concepts of routers and NATs in the telephony world. A PBX can be hardware-controlled, or software-defined through something like Asterisk.

I have personally used Asterisk a fair bit due to its heavy use in the Amateur Radio world as the backbone for repeater interconnections. More on this in a bit.

The goals for this project

Going in to this project, I had a few seperate goals I decided to complete at the same time:

  • Build my own PBX without using someone else's base configs
  • Play around with Twilio's services
  • Spice up my existing Hamshack Hotline connection

And of course, like all my other projects, this one is running on a budget. Less than $10 per month for all required SAAS and IAAS subscriptions.

Acquiring a PSTN phone number

The Public Switched Telephone Network (PSTN) is likely the only phone network you have interacted with knowingly. This is the network your cellphone number will be allocated under, and the network that routes your calls to your friends.

Generally, if you wanted a PSTN number, you have to go to a phone carrier and get a landline or cellular subscription. Since I needed a number for a PBX, I took a slightly different approach.

Twilio provides a programatically controllable PSTN service. Their services include:

  • SMS/MMS messaging APIs
  • VOIP phone numbers
  • Email APIs
  • Elastic SIP trunking
  • ..and much more

I am personally interested in their SIP Trunking service. When renting a number from Twilio (which costs just a dollar a month), you can create a SIP trunk from your PBX to theirs, and they will route all inbound calls back to you, plus allow you to place outbound calls to the PSTN through them.

Hey students, you practically do all of the Twillio stuff in this post for free through GitHub Student Pack 😉

Software PBXes and Trunking

Before I get much further, I should explain the options for hosting a PBX, along with an explanation of trunking.

Ignoring physical PBXes, there are a few options for self-hosting a phone network.

  • Using a commercial service like 3CX
  • Using one of the many Asterisk-based sofware packages
  • Using SIPFoundry

As previously stated, I chose to go with an Asterisk-based system. Specifically, FreePBX 15. There are other Asterisk-based systems available as well:

Trunking

Trunking in the telephony world, is essentially the same as VLANs in the computer networking world. A trunk is a seperate network that can be routed to and from based on your PBX routing rules.

In my system, I have two trunks, one for Twilio (and by extension the whole PSTN), and one for Hamshack Hotline.

My trunking setup

Provisioning an IAX2 Trunk through Hamshack Hotline

Hamshack Hotline is a service for Amateur Radio operators that allows us to connect physical VOIP phones to a private phone network for direct-calling other operators, clubs, and even supported repeaters. All users must prove their licence status.

Since this section does not apply to the majority of my audience, I will not go into the details of how to link up with Hamshack Hotline. Instead, I'll just link their guide for doing this.

Pulling everything together

To get this whole system working, I spun up a droplet on Digital Ocean and used their FreePBX image to quickly get up and running.

Then, I set up a number on Twilio and followed their Elastic SIP Trunking guide. As well as the Hamshack Hotline guide linked above.

Conclusion

In the end, with some additional tweaking to the IVR settings to allow external password access, I was able to get a working PBX up and running.

I can now place a PSTN call from my cellphone to the PBX, enter a password, then dial a Hamshack Hotline RF-Link number to call up repeaters from my phone.