Thoughts, tips and ideas on next-gen technology by: Moshe Brevda


FreePBX: Restrict an extension to a specific trunk

Many a time, the question has arisen on how to address a seemingly simple issue: restrict a given extension to a specific trunk when using the FreePBX gui for Asterisk. Due to the internals of FreePBX, this is no simple feat, especially if you are trying to do this from the gui. However, if your willing to get your hands dirty (just a bit!), here is a simple and clean method to restrict an extension to a specific trunk.

Be forewarned: this method can easily confuse even the most initiated as it works counter to the logic that is FreePBX. That being said, as long as you don't forget that you have this code in place, it shouldn't be a problem for most installations.

Here is what you need to do. First you need to get the name of the outbound trunk you wish to limit the extension to. In FreePBX, select the trunk from the trunk page. Then have a look at the url in the browser's address bar. The url will look something like this:

We are looking for the number part of the blue text, and it is likely to be different on your system. Here is a screenshot of the url, with the part we want circled in red:

 In your favorite text editor, add the following to /etc/asterisk/extensions_custom.conf:

exten => s,1,goto(${AMPUSER},1)
exten => 1234,1,Set(DIAL_TRUNK=my_trunk_number)

Do not edit the first two lines. On the third line, replace 1234 with the extension that you wish to restrict and my_trunk_number with the number of your trunk which we retrieved earlier. Add additional lines for more extensions, replacing 1234 with the extension number you want and my_trunk_number with the number of the trunk.

In closing, there exists a FreePBX module with a purpose similar to our's, however I think it overly complicates the issue in a way that most user will not appreciate. Should you want to have a look, you can find it here.

Moshe Brevda, FreePBX Development Team
(lazytt on the FreePBX forums)
read more tips and tricks here: