How 2 keep calls on Asterisk made from the same Asterisk

Hello everyone,

I am having a small issue that I am unable to resolve.

How do we keep calls made to a number on Asterisk made from an extension on the same Asterisk on the same Asterisk?

We are running a VoIP company and have setup our customers as extensions, using their DID as their extension numbers.

To place a call, customers dial 1+NUMBER, and based on call plans the call is directed across the required trunks (ie: local, Canada, US or international trunks, based on rates or no charge lines established).

If there is no 1, the system will treat it as an internal call, and thus route to the users extension.

How, without setting up dialing plans for each customer, do I keep a 1+NUMBER call that is actually on the same Asterisk server, on the server so that it does not grab a trunk, go out and then back in. This is actually restricted with one of our carriers, as they see it as a looped back call.

Any suggestions… ?


You do not provide many details, but I would suggest looking into one of these functions: … sion_state … lan_exists

My apologies, I tried to provide as much details as I could…
Let me explain in more specific details:

We area provider, offering VOIP services.
Users are not aware of each other, so the concept of extensions do not exist.

Users dial 1+AREACODE+NUMBER in order to place a call.
A SIP trunk is used to route the call through a provider to the called number.

The issue is when a user dials a number that happens to be on the same Asterisk switch.
ie: Asterisk switch has extension 5555551212 and 5556661313.
Extension 5555551212 dials 15556661313 and the call is then routed off a SIP trunk hits the DID provider and then ends up routing back to this same Asterisk server.

How do I get the Asterisk server to know that 5556661313 is on the same Asterisk server as 5555551212 and keeps the call within the same Asterisk and does not attempt to send the call out a SIP trunk ?

Where he is making this difficult is that he doesn’t want to but the DDI numbers into the dialplan in two places.

If this is “Realtime”, read the database directly for outgoing calls.

Otherwise, set a channel variable and jump to the incoming context. The variable permits the call to be routed out of the upstream trunk. It’s probably not necessary, as the upstream should probably never send numbers that would loop back.

Or, create a subroutine that decodes the number and sets a channel variable and use it for both incoming and outgoing calls.

I’m agreeing with david55. First off, please tell me you’re using a database for this system. If you’ve got more than a handful of subscribers, you really need to use a database. The scalability just isn’t there with a flat file. You should be filtering calls with a query to make sure they don’t match any local people first, and then doing a “last resort” route, and shipping it out your outgoing trunk. Something like this

MYSQL(Query does this number exist in our database?)
MYSQL(Fetch matches)

Obviously this is not REAL script… but it should point you in the right direction.

What file would this setup go in?

Every file I think may be it, FreePBX tells me not to edit the file as it is controlled by the web panel.

I am actually surprised this is not a base feature… as I can not imagine anyone who would not want calls to an extension to remain on Asterisk and not go off a trunk and back.

Now I realize I am not using a dial 9 type of request for making an outgoing call… but if the number I am dialing matches exactly to an extension why would it not goto the extension (currently it goes to a trunk based on the dialing plan).

Asterisk works at a much lower level than this. If this were a base feature, it would be one in FreePBX, not in Asterisk.

Did you try:


Why not just say google “freepbx keep local”. The first few hits look to be false positives.

The first hit has the relevant info. Google is probably showing you personalized results. Try logging out of Google. :smiley: