Asterisk as a trunk

Hi all, I’m fairly new to Asterisk and I’m currently operating 2 servers:

  1. A trunk in testing, a RaspberryPi with Raspbx and a 3G dongle acting as a trunk. Working fine inside the Rpi. With FreePBX

  2. A server on which physical SIP phones are connected (~10) and also working normally. FreePBX Distro.

What I would like to do, is to configure the Rpi as a trunk for the « server », and relay every call made to the 3g dongle, to the server. Currently, i have created an extension (222) on the Rpi and the server has a trunk configured with the extension. The inbound route on the RPI dials the extension, sngrep shows correctly an invite sent by the Rpi to the server.

But, the issue is, the INVITE doesn’t contain AT ALL any reference to the DID (which is the extension called), the URI called in the invite is: PJSIP/222/sip:s@SERVER.IP:5060, so the server can’t match à DID as the extension received in the dialplan is “s”.

Is there a setting on the Rpi to send the extension instead of the “s” (I tracked down the calls until PJSIP_DIAL_CONTACTS which is returning the s@ .

Thanks for your assistance

I think there is a FreePBX wiki entry that explains how to connect 2 FreePBX servers.

I don’t think you mean a trunk; I think you mean an internet telephony service provider.

DID is a term that is abused in the VoIP world. I think you really mean using the user part of the To header for DNID (dialled number indication). My Google searches suggest that

is still correct, and there is no way of doing this with chan_pjsip.

As I recall it, there is a, little used, dialstring parameter for chan_sip which allows you to set the To header.

Indeed, it seems to be this one: Connecting Two FreePBX/Asterisk Systems Together Over the Internet - PBX GUI - Documentation

I’m digging into it, thank you

I’m indeed probably abusing the term as well. I’m using “DID” as the “dialed phone number”. On the Rpi, the 3G dongle is set as a trunk (in FreePBX) and the DID is the SIM phone number (sent by the 3G dongle to Asterisk).

On the server (on which the Rpi is set as a trunk), I would expect the DID to be the extension dialed by PJSIP to reach the server (in my case, the extension used is the sim phone number).

I understand the URI can’t be manipulated, in the other hand I may be able to add a header… I’ll dig into it also, thanks for the hints

Note that IAX2 is little used and hasn’t been updated for a long time. If you are trying to emulate an ITSP, in general they won’t use it.

Also,

why are you using s here, if you actually want ${EXTEN}.

A typical ITSP would use the equivalent of, PJSIP/trunk, and if you are lucky ass the request URI in To, which doesn’t actually seem to be supported by PJSIP. That’s because it will be using dynamic addresses, and the customer system will provide full URI in the REGISTER.

If you are not trying to be an ITSP, there is a good chance that you can use static addresses at both ends, in which case you can specify the original URI.

Using 222 for a trunk name is confusing, as it looks like an end user phone number.

The third and fourth examples in

https://wiki.asterisk.org/wiki/display/AST/Dialing+PJSIP+Channels

are probably most relevant here.

Thanks for the detail. But there is no “they”, the 2 Asterisks are mine for testing purposes. The Rpi is in another country and I’m trying to route calls placed on the 3G dongle to my softphone wherever I am.

This is what ${PJSIP_DIAL_CONTACTS()} returns to the context [macro-dial-one] before setting the SIP headers. I don’t know why it outputs “s” instead of the extension… Maybe it has to do with how the server is stored in the Rpi database? (the extensions are truncated)

call*CLI> database show
[...]
/DEVICE/77000/default_user               : 77000           
/DEVICE/77000/dial                       : PJSIP/77000     
/DEVICE/77000/tech                       : pjsip                    
/DEVICE/77000/type                       : fixed                    
/DEVICE/77000/user                       : 77000           
/registrar/contact/77000;@b71c765d2da17a2dc04106ef88e94df6: {"via_addr":"192.168.27.68","qualify_timeout":"3.000000","call_id":"5209adc6-05e9-43c6-a11f-6b6e8b357da2","reg_server":"","prune_on_boot":"no","path":"","endpoint":"77000","via_port":"5060","authenticate_qualify":"no","uri":"sip:s@192.168.27.68:5060;line=cdallms","qualify_frequency":"60","user_agent":"FPBX-15.0.17.37(16.15.1)","expiration_time":"1625494529","outbound_proxy":""}
[...]

The uri contains “s” instead of the endpoint there.

I’d be glad to change the URI and the “s” myself, but with FreePBX I don’t know where to change it. Moreover if the “s” is got from the /registrat/contact/EXTEN db line, I don’t know how I can change it.

Any idea why the Rpi registered it this way?

PS: The extension used is the full e164 format number of the SIM card, the 222 and 77000 are the same extension number truncated.

What registered to Asterisk said it wanted to be contacted at that. The registering side, if Asterisk using PJSIP, would need the contact_user option set. The PJSIP_DIAL_CONTACTS dialplan function also allows it to be overridden[1]. It is the request user.

[1] Asterisk 18 Function_PJSIP_DIAL_CONTACTS - Asterisk Project - Asterisk Project Wiki

To add to the above, why are your registering? If this is really a private tie trunk, rather than trying to emulate an ITSP, you would normally have a symmetrical arrangement, in which you knew both addresses.

Also, why are you using PJSIP_DIAL_CONTACTS? That will always give you complete URIs, but is only really necessary if you have multiple devices with the same address of record.

@jcolp Thanks for the suggestion, I’ll try to do my best.

I’m registering for 2 reasons, first because I’m new to Asterisk and as I have a real trunk configured (with a normal ITSP), I was naturally trying to do the same. Secondly, because while it’s private, the servers are still publicly accessible, so I didn’t know much other options to avoid allowing “guest” calls, as I have a trunk capable of calling outside (which is my ITSP) and an Rpi with a 3G dongle also capable of calling outside (with a lot of guest attempts). I’m testing but

I don’t know about PJSIP_DIAL_CONTACTS, I’m using Asterisk with FreePBX distro, the contexts I’m talking about are included in FreePBX. I tracked down why THISDIAL at some point was showing “s@” are I arrived at the context [macro-dial-one] and a line with PJSIP_DIAL_CONTACTS.

I’m opened to suggestions though

Solved it!

In the server’s “Trunk” details > pjsip settings > Advanced > contact user: I put the extension used, and it was used instead of the “s@”

But I’m still opened to suggestions to do better and one day put it in production.

That’s an example of why FreePBX users should only use the FreePBX forum.

However, in this case, and backed up by your strange trunk name, I think it reflects that you are using FreePBX structures designed for what they call extensions, on the side that isn’t doing the registering.

Register is not primarily about authentication. In any case, if you based your configuration on one designed as the Asterisk end of an ITSP trunk, you are likely to be wide open to toll fraud, as ITSP’s don’t authenticate themselves, so password based authentication is turned off for calls incoming to Asterisk.

You can make a call of up to 30 seconds using a spoofed source IP address, and, if your tie trunk can make chargeable calls, that could mean 30 seconds of the hackers premium rate number. (It is most secure to use a VPN for tie trunks.)

On the FreePBX forums, what I think you want is referred to as an intra-company trunk, although I couldn’t find a definitive document on them, and am I am not familiar with the GUI, so I don’t know how well that supports them.

Sorry for having wasted Asterisk’s enthusiasts time over a FreePBX issue… I really though I had a configuration issue, which I would have tried to fix in FreePBX.

Indeed. As on FreePBX, pjsip trunks are using an extension and a password. As is my ITSP.

[quote=“david551, post:12, topic:89130”]
Register is not primarily about authentication. In any case, if you based your configuration on one designed as the Asterisk end of an ITSP trunk, you are likely to be wide open to toll fraud, as ITSP’s don’t authenticate themselves, so password based authentication is turned off for calls incoming to Asterisk.[/quote]

I see an option to authenticate both incoming and outgoing calls. Currently, the server doesn’t allow unauthenticated inbound calls, the Rpi :5060 port isn’t accessible from internet and the server and Rpi are on VPN. The Rpi is apparently the weak link.

I’m interested in knowing how to build an ITSP, I’m in Congo and we don’t have any provider, it may be an interesting market.

Will look at intra-company trunk, thank you again

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.