Asterisk: Blacklisting For Multiple Users – June 06, 2009

There are a number of tutorials for people trying to setup blacklisting for their Asterisk server, but they all seem to assume that there is only one user on the server, or at least all users want to share the same blacklist.

Since I host for multiple, unrelated people, they don't necessarily want to share the same blacklist, so I had to come up with a configuration that would work for all customers.

Here are the changes I made (for Asterisk 1.4)

Outgoing dialplan: (custom per user)

Incoming dialplan: (custom per user)

Macros:(shared among all users; I use /etc/asterisk/custom/extensions-default.conf, and have a #include "custom/extensions-*.conf" in the default extensions.conf)

You should replace "<customername>" with the name of the customer, so each customer uses a different database (note you could use the same name for certain customers, if some of them want to share the blacklist, but everyone does not).

Replace <context>, <extension> and <priority> with the appropriate values for where to jump to if a blacklisted number is found.  (I find this nicer than the n+100 syntax, particularly since I always use "n" everywhere, rather than actual hard-coded numbers (ah, remember the good old days of basic, where you always numbered your lines: 10, 20, 30, so there was room to add in code later?).

And that's it.  You can use "database show" from within the CLI to watch the entries as they are added.

If it isn't clear from the above code and comments:

*32 blacklists the number of the person who called most recently
*31 removes a number from the blacklist (you'll have voice prompts to prompt you to enter and confirm the entry)
*30 adds a number to the blacklist (same voice prompts as with *31)

The only downside of this method is that the *32 requires that there aren't lots of calls per user, so the lastcallerid value is still valid (e.g. if you were at a call center, where you had lots of incoming calls, and didn't have time to dial *32 before the next call came in, you'd have to never use *32, and use *30 and manually enter the number instead).

Questions? Have Anything to Add?
(your comments will be published on this site - click here for private questions)

How can i increase delay between each digit when read and say digit from Database.It is too fast for customers to listen and write.

Please help me, i will appreciate your help.


Posted by haseeb on October 17, 2009, 8:23 am


I guess you could use the CUT function to get each digit, and say it one at a time, with a delay in between. Though, the customers don't need to write down anything, so perhaps you were just hoping for a link to your company...

Posted by jondaley on October 17, 2009, 3:04 pm

Can you please tell me where should I modify Outgoing and Incoming dialplan for each user that will use blacklist?
I'm not quite sure in which config I should look for that.

Posted by Sebastian on February 4, 2010, 7:00 am


Unfortunately, it depends on how you have things setup. But, basically, you can put the outgoing section in whatever context each user uses for his outgoing context (each user has to have his own outgoing context - if you only have one context currently that everyone shares, you'll need to change that to have each user have his own and then include the shared context).

The incoming side should be easier, since they have to have separate contexts, so just paste in the incoming section at some point (probably towards the top) in the incoming context.

And I can't even tell you which file, since different people set it up differently.

I try to not modify any files in the /etc/asterisk directory, except to add an include line to /etc/asterisk/extensions.conf to include *-extensions.conf in /etc/asterisk/custom/ and include *-sip.conf in /etc/asterisk/sip.conf.

I couldn't figure out a good way to not modify the voicemail.conf nor the users.conf. I used to not modify the users.conf, but I changed that within the last couple months - I forget what the reason was at the moment.

Posted by jondaley on February 4, 2010, 8:06 am


I have a question about those extensions. How did you set up *30,31 adn 32 to the asterisk that you can dial them? I've implemented few codes of blacklists but don't know how to set up those numbers.


Posted by Lukas on April 23, 2012, 6:10 am

Lukas and I emailed already, but basically, the answer if anyone else comes across this - you need to understand how dial plans work, and be able to create an extension that does anything, even a Noop() command, before you start thinking about blacklisting. has a lot of information, but basically, I just use a search engine to look up the syntax of the command and look at other people's examples, etc. There are also a lot of examples that come with Asterisk, and I played around with those examples when I was first starting out.

(there are lots of sound files too, so once you get your phone to where you can dial 123 and it plays the screeching monkey sound, you are ready to move on).

Posted by jondaley on April 25, 2012, 6:00 pm

Can you please tel what do you mean by customer name here. Is it extension number ?

Can I set up blacklist based on feedback by each extension ?

Like if I have 2 extensions in system. Can each extension have its own blacklist ?

Thanks and Regards.

Posted by adam on May 2, 2012, 5:56 am

Correct, I use a customer name, rather than extension, because most of my customers use multiple extensions in the same house, and so they would want the blacklist to apply to all of their extensions.

Posted by Jon Daley on May 11, 2012, 11:34 am