Asterisk/FreePBX – How to restrict an extension to call certain extension only

There may come a time that you want a public access phone that can only dial out a certain set of extensions. To accomplish this, a custom context needs to be created and applied to that extension.

Here’s the scenario.
Extension 312 is the public access phone. This should only be able to dial x530 & x555. All other calls needs to be terminated.

Define the context in extensions_additional.conf

[from-intercom]
exten => 530,1,goto(from-internal,${EXTEN},1)
exten => 555,1,goto(from-internal,${EXTEN},1)
exten => _.,1,hangup()

If FreePBX, go inside the extension and the context from from-internal->from-intercom. Apply the settings and you’re good to go.