Restricting outbound calls in FreePBX (blacklist)

Perhaps one of the most requested features in FreePBX is the ability to configure calling permissions. While this is a complex and costly request from a development point of view, there are some simple techniques which can be used to provide some level of outbound call control. It is said that well written software can be used in a way totally different to what its author intended. Some of the current FreePBX modules can be ‘exploited’ to provide just such functionality. You may also want to have a look at the custom contexts module, however that is (still) considered a ‘contributed’ module, and isn’t supported by FreePBX.



Typically, there are two types of outbound call control that you will want to implement:

  1. Call all numbers except these (blacklist)
  2. Block all number except these (whitelist)

For both blacklists and white lists, there are (at least) two methods to block/allow calls. For this article, we will focus on blacklisting numbers. Merriam-Webster defines a blacklist as "a list … who are disapproved of". While only one method described here is actually a "list", both serve he same purpose: to restrict outbound calls. Which one you should use depends on your needs – and the length of our list.

If you only need to block one number you could set up a Misc Application with a destination of Hangup. To do this, click on Misc Applications from the module tool bar on the left hand side of the FreePBX window (if you don’t see the module, you will need to install it by clicking Module Admin -> Check for updates online -> Misc Application -> Download and Install -> Process (top or bottom of the page) ). Once the module page opens, you have the option to enter a new Misc Application. Enter a description in the Description box and the number that you wish to block in the Feature Code box. Now select a Hangup (or Busy) from the Terminate Call destinations option.Hit submit, click the orange bar, and reload FreePBX. Try to call the blocked number – your phone should disconnect the call (or play a busy signal).

You can take this a step further by sending the call to an announcement explaining that (and why) the call is barred, and then going to Hangup.
While this method is good if you want to block one specific mother (your wife/girlfriend from calling her mother?) what do you do if you want to block a whole list of numbers? (Premium rate numbers come to mind here). This can be accomplished quite simply as well (seems everything is simple when using FreePBX!).
First click on Trunks, and click Add Custom Trunk. In the dialstring add BARRED and click Submit. Next, click on outbound routes. Use standard dial rules to create dial rules for all your blocked numbers – list them one at a time or use dial patterns. You should probably call this Outbound Route BARRED (enter it in the Route name box). In the Trunk Sequence, select BARRED. Now click submit.

Here comes an important step: using the arrows under the route BARRED, move the route to the top of the list. Now click submit, click the orange bar, and reload FreePBX. Your calls should now be blocked. Once again, should you need to play a specific message or explanation, you can get fancy by sending the custom trunk to a specific destination or even a custom context.

Check back here soon for the next installment of this topic: Restricting outbound calls in FreePBX (whitelist)

update: Philippe has pointed out that best practice would be to always have an EMERGENCY route, and keep that as your first route. You would then place your BARRED route in second place. Click here to find out how you can hear more best practices.
Moshe Brevda, FreePBX Development Team
lazytt – FreePBX forums
hi365 – IRC

Found this tip useful? Don’t forget to donate by click the donate button!

11 thoughts on “Restricting outbound calls in FreePBX (blacklist)

  1. If the idea is simply to block calls that cost too much money, then another approach is to create an ENUM trunk (which you should probably have anyway if you are truly concerned about costs). Then you create your BARRED route as described above, move it to the second from the top on your list of routes (after your emergency route), and in it put the numbers or patterns you want to avoid calling as toll calls. In the trunk sequence you select the ENUM trunk. It’s the same concept as Moshe has described, but the advantage is that you don’t have to create a custom trunk that goes nowhere if you already have an ENUM trunk created, and if by some odd chance the call can actually be completed via ENUM it will go through (and cost you nothing!).

    Note that for ENUM to work properly you will have to send numbers to it in the format it wants, using dial rules to add or strip digits if necessary – the format is simply country code plus area or city code (if any, and no 0 at the start of that code) plus number. Only a small percentage of calls can be placed via ENUM at present so the likelihood is that the call won’t go through, but either way it won’t cost you anything.

  2. I am using the following method, which sort of is a blacklist/whitelist all in one…

    On the outbound route, in the Dial Pattern section, I do something like this:
    [code]
    ./1122
    N[0-8]XNXXXXXX/2233
    [/code]

    Adding a / after the pattern specifies that it is for that particular extension only. So in my example above, extension 1122 can dial anywhere/anything and extension 2233 can only dial North American numbers and since there are no further rules, all other extensions can only dial internal extensions and cannot make any outgoing calls at all on this particular outbound route.

    So this blacklists ALL outbound calling for all extensions, but then whitelists extension 1122 and 2233 to be able to make certain types of calls.

    This is probably ok for small organizations with not a lot of extensions, but it might be a problem if you have a lot of extensions because you would have to enter a line for each extension!

  3. And as an additional side note, if you use the /1122 method, you can NOT do pattern matching on the extension itself.

    Pattern matching works on the number, but does not on the extension (I am using Asterisk v1.4.18 with FreePBX v2.7.0.3).

    Hey, I think there is a feature request in there somewhere (hint hint). If pattern matching worked on the /1122 extension part, you could setup some quick rules for a whole range of extensions, instead of one extension per line.

    Thanks for the article… very helpful! I was wondering how I could block those ‘900’ numbers, so now with the BARRED outbound route and trunk I can set up blocks on these numbers first.

  4. pattern matching works on the cid component (the “extension” as you are calling it).

    On 2.7 you just need to put it Asterisk’s pattern format, e.g. “_[1-2]XXX” would match extensions 1000-2999.

    In version 2.8, we have removed the need to preceded it with “_” (and if you migrate from 2.7 to 2.8, it will fix this for you).

  5. That’s the fastest feature request implementation I’ve ever seen! lol

    Thanks so much for this… I did not know about the _ having to be in front!

    So now I can do this:
    [code]
    ./1122
    N[0-8]XNXXXXXX/_[2][2]XX
    [/code]

    and it will allow all extensions from 2200 to 2299 make outbound north america calls! That is great!

    Thanks again mbrevda and p_lindheimer

  6. I like the how to description, but trying to apply it to the 2.8 trunk screen is confusing: “In the dialstring add BARRED”. Which field is this in the 2.8 release? I’ll try to figure it out, but screen shots for the applicable release(s) would go a long way for translating forward…

    thanks – freepbx is *fabulous*

Leave a Reply