I helped my son upgrade his Asterisk@Home system yesterday. It turns out that the only real upgrade path is to wipe away your previous configuration and start from scratch. Literally – it even wipes the entire hard drive and starts over.
I didn’t really mind that because the first time around we really didn’t know what we were doing and therefore installed a lot of crap that we didn’t need. I don’t feel like an expert by any means but there is one thing I have discovered that may help some Asterisk@Home users save a little money. Or at least it would, if it were a bit simpler to implement.
That something is ENUM. The idea is, if you have an Asterisk box and you are calling someone who has an Asterisk box (or is otherwise a VoIP user), why on earth would you want to route your call out through the PSTN, or even through an ITSP? Just send the call direct to their box or device! This is the basic idea behind the PhoneGnome appliance, which allows a customer to use the Internet for ENUM calls and calls to other PhoneGnome users. The idea, when making a call, you first check the ENUM database to see if there’s a direct route, and if there isn’t, only then do you send the call out to the PSTN or via some other, less direct route.
Asterisk@Home has support for ENUM built in BUT it is not turned on by default. So in this article I’m going to tell you how to enable it, and how to test it to make sure it’s working.
EDIT: This works with the version of AMP (the Asterisk Management Portal) that comes with Asterisk@Home 2.7. If you upgrade AMP to the latest version of FreePBX (the new name for Asterisk Management Portal) the following may not work, or may break if you’ve already done this. I found this out the hard way after we upgraded to FreePBX 2.0.1, and I have since heard from the author of the routine that handles the lookups (he sent me an e-mail and posted a comment on this blog). The problem is that this enum lookup only looks at e164.org, whereas the old routine either looked at both that and e164.arpa, or at least at e164.arpa (the test number mentioned below is an e164.arpa number). He says that in the next version of FreePBX, there’ll be a way of configuring which e164 domains to use. If you need to use e164.arpa, see his comment on this post for the lines to change in extensions.conf.
In the Asterisk Management Portal (or if you’ve just upgraded, FreePBX) go to Setup, then click on Trunks (in the left menu column). You should then be on the “Add a Trunk” screen; if not, click “Add Trunk.” Make sure you don’t have an existing ENUM trunk (listed in the column on the right), then click “Add ENUM Trunk.”
If you are in North America, you only need to add these three lines to the dial rules:
011|.
1aaa+NXXXXXX
1+NXXNXXXXXX
If your system doesn’t support seven digit dialing of numbers in your home area code, omit the second line, otherwise change aaa to your three digit area code. If your system doesn’t permit ten digit dialing (that is, you require callers to dial a “1″ before all out of area calls), you can omit the third line.
For most users, that is ALL you have to do in this screen. Click “Submit Changes” and you are done here. But there are a couple more steps.
The first is to go to each of your routes that allow outbound dialing – click “Outbound Routing” (in the left menu column) and then look at your existing routes (in the right menu column). You will want to change any that make calls to PSTN-like numbers, except perhaps for any “private” routes to other known Asterisk users you may have set up. Let’s say you have a route for Toll Free calls (if you don’t have those broken out into a separate route, you probably should), another for USA calls, and another for Canada calls. You may not have all of those, you may have the USA and Canada combined, or whatever, but my point is that you want to look for any routes capable of going out to the PSTN (directly or through your ITSP).
Click on each of those routes in turn and when the screen comes up for that route, drop to the bottom of the screen and you should see the Trunk Sequence. The lowest dropdown field will probably be blank – use that field and select the ENUM/ trunk. Click “Submit Changes” but don’t leave this screen yet. Now go back down to where you just added the ENUM/ trunk and look next to it, there should be a trashcan icon and an upward-pointing arrow. Click the up-arrow to move the ENUM/ trunk up. Continue doing that until ENUM/ is the topmost item in the trunk sequence. This is very important, if your system doesn’t check ENUM first, most of the time it will never check it at all. If there’s no ENUM route the call will then “fall though” to the next trunk in the sequence. So when you are done, your ENUM/ trunk should be in position “0″ (the topmost one). Don’t forget to click “Submit Changes”, then go to the next applicable route and make the same change.
Obviously you should NOT change the trunks for routes to NON-PSTN type numbers (for example, if you have a Free World Dialup route, don’t change that).
Now at this point it should work, but it probably won’t, (Edit: Unless you’ve upgraded to FreePBX – the latest version has fixed this bug)! The reason is that there is a bug in the extensions.conf file! So break out your text editor (either nano, or the editor accessed by clicking on “Edit” in Midnight Commander will work) and edit /etc/asterisk/extensions.conf – you want to change the following line:
exten = s,9,EnumLookup(${DIAL_NUMBER})
The enum lookups now require a + (plus sign) at the start of all lookup strings, so add one just before the $, as shown below:
exten = s,9,EnumLookup(+${DIAL_NUMBER})
(If you’re having trouble finding this code snippet, it’s in the [macro-dialout-enum] section, just a bit less than halfway down the page.)
I should probably mention one other file you will want to check – /etc/asterisk/enum.conf – make sure it has these two lines under [general]:
search => e164.arpa
search => e164.org
Some people suggest reversing the order of these two lines (placing e164.org first) but it shouldn’t matter because in theory both are checked. In theory.
NOW it should all work. In AMP/FreePBX, you may want to go to “Maintenance”, then “Config Edit”, then click on “Re-Read Configs” just to make sure that Asterisk picks up the change you just made in extensions.conf
Now you are ready to make a test call. Go to this page of ENUM test numbers and dial the first the way you would any international call (you did remember to change the trunks in whichever route handles international calls, right?). For example, in North America you’d dial 011 43 720 0101011 and after a few seconds you should hear a voice say “ENUM”, followed by some music.
If this works, what this means is that every time you make a call, your system will do a quick dip from the ENUM database to see if the call can be routed direct through the Internet. If it cannot, then it goes out the usual way. One interesting thing you will find is that all U.S. toll-free numbers that don’t have a specific routing are by default routed to a FREE gateway that sends toll-free calls to the PSTN. So, if your ITSP is charging you for calls to toll-free numbers, that cost will go away!
There’s one other interesting use for ENUM – let’s say you have identified locations you really don’t want people calling due to the cost, but those numbers are within a more general block of numbers that you do want people to be able to call. For example, let’s say you don’t want people calling 1-900 or 976-prefix numbers. You might set up a route with a dial plan that looks something like this:
1900NXXXXXX
900NXXXXXX
1NXX976XXXX
NXX976XXXX
976XXXX
Now what you do is allow that route to access the ENUM/ trunk, and nothing else, and make sure that route is higher in the route list than any of your regular routes that might also apply to calls to these numbers. More than likely there will not be an ENUM route to that number, but even if there is, since you’re not accessing it through the PSTN they should not be able to charge you for the call (no guarantees that they won’t try, particularly if they capture your caller ID. I suppose you could always set up a second ENUM trunk with a phony CallerID string like “123″ specified, and use that trunk for these routes, but that might not be legal and they might still be able to identify which system connected to them. More than likely, though, they’d just reject the call).
Caution: if, after adding routes, you have more than nine routes (that is, if you have a route numbered 9 or higher in AMP/FreePBX, which starts counting routes from zero), they will NOT be checked in the order shown in AMP/FreePBX (unless they have fixed this bug in later versions). To see the order the routes are actually being checked in, look in the [outbound-allroutes] section of /etc/asterisk/extensions_additional.conf – that is the order the routes are checked in, not the order shown in AMP/FreePBX.
Now of course, the real advantage comes when you and everyone else has your numbers listed in the ENUM database. Getting your number listed isn’t that hard; you can got to E164.org and click on signup. Unfortunately, at least when using the Firefox browser, I get a popup box that says “Website Certified by an Unknown Authority – Unable to verify the identity of *.e164.org as a trusted site.” I’m not really sure if that’s an issue or not, but I’ve sort of been waiting to see if they fix that (or at least say something about why that box is popping up)
To actually receive incoming calls may take a bit more effort. If your Asterisk system doesn’t discriminate on incoming calls (that is, all incoming calls are sent to the same place, regardless of origin or number actually dialed), you may not have any additional configuration to do. This page has some suggestions for handling incoming IAX calls, though I haven’t tried them (it also has links to dial plans you may be able to use with the ENUM trunk if you are outside North America).
One other thing that may help for incoming SIP calls, is to go into /etc/asterisk/extensions.conf and look for the [from-sip-external] section. If you find three lines that look like this:
exten => _.,1,AbsoluteTimeout(15)
exten => _.,2,Congestion
exten => _.,3,Hangup
Comment them out and add an uncommented line, as shown here:
[from-sip-external]
;exten => _.,1,AbsoluteTimeout(15)
;exten => _.,2,Congestion
;exten => _.,3,Hangup
exten => _X.,1,Goto(from-pstn,s,1)
This will allow all incoming SIP calls intended for any number on your system to go to the from-pstn context, if that is what you want. Bear in mind that this change doesn’t affect incoming IAX calls, and the changes you may make for IAX don’t affect incoming SIP calls – each is treated differently (well, at least in this situation, anyway).
This article is getting way too long already so I’ll stop here. If you are able to get ENUM working, why not leave a comment and let us know how it went for you.
Technorati Tags: Asterisk@home, Asterisk, tutorial, PBX, VoiP, telephone, telephony, ENUM, HowTo, MichiganTelephone