HowTo, Problem Solving, Recipe, The Basics
Build Your PBX – Step 5: Add a VOIP provider
To be able to make calls to regular phone numbers and receive calls, you need a VOIP provider. There are so many providers coming and going that it is hard to know who to choose. If you want to do research yourself, an excellent resource is DSL Report’s The Good The Bad and The Ugly Charts. In the future, I hope to describe the pros and cons of the better service providers, but for this tutorial, I’m going to assume that you’ll be using Les.net. They offer a pay-as-you-go plan which gives you a US phone number for $1/month or a Canadian number for $3.50/month (prices in Canadian dollars). (If you use a different VOIP provider, the instructions for the most part should apply, however but you might have to do a bit of translation and interpretation as each provider is a little bit different.)
Create an Account
Les.net uses a pay-as-you-go model, so you need to create an account and add a few dollars to get started. Assuming you have a verified Paypal account, your payment is immediately added to your account. (If you don’t have to a verified account, you have to wait 14 days.) It’s possible to pay with a normal credit card, but this involves printing and faxing an application, so I never bothered with that. You are responsible for any payment fees, which usually is in the 3% range. Also, if you are in Canada, GST will be charged. This means that if you add $10 to your account, the actual amount added is a bit less. The payment system at Les.net is by far the most difficult part of the whole process. Once you get some money is your account, you are given all the necessary tools to select a phone number and configure your account.
Get a Phone Number
If you want people to call your PBX from anywhere, you need a number. This is called a DID, and you can hopefully get one for the area code you need. Or you can get a Toll-free number.
If you just want to make calls, and don’t want people to be able to call you, you can save some money and skip the DID.
Create a Peer
On the Peers/Trunks screen you can create a peer. The peer is a number which is essentially your username. Once you’ve created your peer, edit it. You’ll see a screen with many options. Setup the peer as follows:
# Les.net - Edit Peer Peer Name: 999999 // pre-defined - this is your 'username' Your Description PBX // whatever you like Peer Technology SIP DTMF Mode INFO Error Method Coded Codecs G.711 Peer Type Registration Peer Address // ignore Password voipsecret // choose your own secret password! Registered // ignore Registered IP // ignore Registration Expires // ignore Outbound CallerID // ignore 7-Digit Dialing // ignore 7-Digit Area Code Prefix // ignore 10-Digit Dialing, Prefix 1 // ignore Voicemail Enabled // unchecked Go to voicemail after (seconds) // ignore Voicemail Password // ignore Voicemail Access Code // ignore Email voicemail to // ignore
Click “Save Settings” and you now have a peer.
Connect DID to Peer
You want incoming calls to go to this new peer. On the “Your DIDs” screen you can see all of your DID numbers. Click on your number to edit it, and set “Route to” to the new peer.
Tell the PBX about the VOIP provider
Now that the VOIP provider is setup, you need to tell the PBX to use the VOIP provider. First, we need the PBX to register with the VOIP provider. Second, we need to specify what happens for incoming calls from the outside world, as well as outgoing calls from your VOIP phone.
Register
Just as your phone registers with your PBX, your PBX registers with your VOIP provider. Under the [general] context, add the username and password in the form:
register => username:password@did.voip.les.net/username
Using the values from the example above,
username: 999999 password: voipsecret
This would look like:
[general] register => 999999:voipsecret@did.voip.les.net/999999
Now we need to define some basic parameters for this connection. Add this after the [general] context:
[lesnet_peer] type=friend host=did.voip.les.net dtmfmode=auto insecure=very disallow=all allow=ulaw context=incoming ; incoming DID calls will arrive in the incoming context. see: /etc/asterisk/extensions.conf canreinvite=no
We now have defined a SIP extension called “lesnet_peer”. What does that mean? It means we can dial to the outside world. We do that in the dialplan file extensions.conf
.
Calling the Outside World
We need to tell our phone what to do when we dial a phone number. So far, we’ve only told it how to dial single digits like 9 to get voicemail. If you dial a proper phone number (10-digits), we want to send that call to our VOIP provider. We need to add a rule to our dialplan.
[internal-phone1] ;; calls from our VOIP phone
exten => 9,1,Answer
exten => 9,n,Wait(1) ;; wait or we lose the first syllable
exten => 9,n,VoiceMailMain(s20) ;; s=skip login, listen to msgs in box 20
exten => _XX.,1,Noop(Dialing the outside world: ${EXTEN})
exten => _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN})
Asterisk supports simple pattern matching in the dialplan. (The “_” indicates it is a pattern. The “X” matches any digit, and the “.” [period] matches one or more times. So, “_XX.” matches any three digits or more.) Reload your asterisk configuation, so these changes take effect and try calling a regular phone number.
Incoming Calls
Incoming calls are also handled in extensions.conf. In sip.conf we specified that calls should come in on the “incoming” context. We need to define that context. Incoming calls come from your DID number. If we assume our DID is ’212-555-9999′ we would need the following rule:
[incoming]
exten => 2125559999,1,Noop(Incoming call from: ${CALLERID(all))
exten => 2125559999,n,Dial(SIP/phone1,20)
exten => 2125559999,n,Playback(vm-goodbye)
exten => 2125559999,n,Hangup
An incoming call to your DID would simply rings your phone (for 20 seconds) and if there is no answer, the caller hears the ‘goodbye’ recording and the call ends.
Troubleshooting
If things don’t work as expected, there are several places to look for error messages. First, from the asterisk console, make sure you have verbose messages on.
You should see activity on your VOIP phone as you attempt to dial a number. Alternately, you can view the asterisk log file.
On the Les.net Edit Peer screen, you can see if your server is registered. The fields “Peer Address”, “Registered”, “Registered IP” and “Registration Expires” should all have relevant information. If they are empty, then asterisk has not registered with your VOIP provider.
Next Steps
You now have a functional PBX. It doesn’t do much at the moment, but it is a solid foundation uponw which you can start to build a phone system that works exactly how you want it to. Most of the behaviour of the phone system is controlled by the dialplan, which we will examine next.
Continue to: Overview of the essential Asterisk Dialplan Commands [Sorry, still working on the dialplan article... Can I interest you in how to record phone calls?]

Your link above doesn’t work, error 404.
“Overview of the essential Astersik Dialplan Commands”.
Thought you should know…
Jay
Thanks. Still working on that post…
Update: Biggest drawbacks with les.net are that they don’t provide monthly invoices. (Hard to calculate expenses.) Plus I have to cover the PayPal fees and there is now a $2/month fee for simply having an account.
I’ve been looking at other options. For example:
http://www.unlimitel.ca/
Pay-as-you-go, account topped up automatically in $50 increments from credit card. $15 to port numbers (LNP). Daily email reports of usage. Similar pricing to les.net. DIDs for $3.50/month.
http://voip.ms/
Crazy low rates. e.g. Germany for 1.4ยข/minute. US and Canadian DIDs for $1.50/month.
As of July 5, 2010 les.net has a new ridiculous rule: To make an outgoing call, you need to have enough of a balance for a 4 hour call. So, if I wanted to call a European cellphone @ $0.25/min, I would need to have a balance of $60 or my call wouldn’t be connected.
So, now all of my outgoing calls are through Unlimitel. (And Porting my numbers away from les.net is on my todo list.)