You may have a scenario where you’ve a particular extension assigned to a special service and you want only a select group of people/extensions to be able to make calls to this extension.
This can be easily achieved with the dial plan below. There’s just one file to edit : extensions_custom.conf
[kick]
exten => _X.,1,Playback(invalid)
exten => _X.,n,Hangup[from-internal-custom]
exten => 7572/7520,1,Answer()
exten => 7572/7507,1,Answer()
exten => 7572/7584,1,Answer()
exten => 7572/4914,1,Answer()
exten => 7572/7500,1,Answer()
exten => 7572/_XXXX,1,Goto(kick,${EXTEN},1)
exten => 7572/_X.,1,Answer()
Let’s analyse what’s happening here.
The first section [kick] tells Asterisk to play a message saying the dialed destination is invalid and then to hang up.
The next section [from-internal-custom] defines what extension can connect/dial to this particular extension (in this example ext 7572 is the one needing incoming restrictions).
The part before the “/” defines the destination extension and the part after the “/” defines the source extensions.
So in this scenario extensions 7500, 7507, 7520, 7584 and 4914 will be able to call 7572. All other 4 digit extensions will be sent to [kick] which will terminate their calls.
The last part will allow any other call to be picked up by the extension (for example, an external call).
Original idea from : source