# Asterisk as a trunk

**URL:** <https://community.asterisk.org/t/asterisk-as-a-trunk/89130>\
**Category:** Asterisk SIP\
**Created:** [July 5, 2021, 3:46am UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130 "2021-07-05T03:46:35Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![max13](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@max13](https://community.asterisk.org/u/max13)\
**Post date:** [July 5, 2021, 3:46am UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/1 "2021-07-05T03:46:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![EkFudrek](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@EkFudrek](https://community.asterisk.org/u/EkFudrek)\
**Post date:** [July 5, 2021, 4:51am UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/2 "2021-07-05T04:51:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 5, 2021, 10:44am UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/3 "2021-07-05T10:44:16Z")

</div>

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

> [@Asterisk 13 Pjsip Manipulate To: Header on Dial](https://community.asterisk.org/t/asterisk-13-pjsip-manipulate-to-header-on-dial/67550/9#post_9):
>
> Were you signed up on the mailing list? I don’t see anything about that on it… As for your question no, it can’t manipulate the To header. When creating the SIP dialog the same URI is used for both the request header and the To URI. As for adding a “toheaderfield” to the channel structure this would not be accepted. Channel variables already exist that are generic which can be set and read. That would be the quickest way to do it.

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.

---

<div class="post-metadata">

**Author:** ![max13](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@max13](https://community.asterisk.org/u/max13)\
**Post date:** [July 5, 2021, 1:37pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/4 "2021-07-05T13:37:31Z")

</div>

Indeed, it seems to be this one: [Connecting Two FreePBX/Asterisk Systems Together Over the Internet - PBX GUI - Documentation](https://wiki.freepbx.org/pages/viewpage.action?pageId=4161588)

I’m digging into it, thank you

---

<div class="post-metadata">

**Author:** ![max13](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@max13](https://community.asterisk.org/u/max13)\
**Post date:** [July 5, 2021, 1:50pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/5 "2021-07-05T13:50:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 5, 2021, 1:56pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/6 "2021-07-05T13:56:20Z")

</div>

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,

> [@max13](#):
>
> PJSIP/222/sip:s@SERVER.IP:5060

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](https://wiki.asterisk.org/wiki/display/AST/Dialing+PJSIP+Channels)

are probably most relevant here.

---

<div class="post-metadata">

**Author:** ![max13](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@max13](https://community.asterisk.org/u/max13)\
**Post date:** [July 5, 2021, 2:28pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/7 "2021-07-05T14:28:53Z")

</div>

> [@"david551](#):
>
> 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.

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.

> [@"david551](#):
>
> why are you using s here, if you actually want `${EXTEN}`.

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)

```auto
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.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [July 5, 2021, 2:59pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/8 "2021-07-05T14:59:57Z")

</div>

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](https://wiki.asterisk.org/wiki/display/AST/Asterisk+18+Function_PJSIP_DIAL_CONTACTS)

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 5, 2021, 3:46pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/9 "2021-07-05T15:46:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![max13](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@max13](https://community.asterisk.org/u/max13)\
**Post date:** [July 5, 2021, 10:43pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/10 "2021-07-05T22:43:23Z")

</div>

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

> [@david551](#):
>
> why are your registering?
> 
> Also, why are you using PJSIP\_DIAL\_CONTACTS?

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

---

<div class="post-metadata">

**Author:** ![max13](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@max13](https://community.asterisk.org/u/max13)\
**Post date:** [July 5, 2021, 11:09pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/11 "2021-07-05T23:09:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 5, 2021, 11:10pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/12 "2021-07-05T23:10:41Z")

</div>

> [@max13](#):
>
> 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`

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.

> [@max13](#):
>
> I didn’t know much other options to avoid allowing “guest” calls

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.)

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 5, 2021, 11:17pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/13 "2021-07-05T23:17:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![max13](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@max13](https://community.asterisk.org/u/max13)\
**Post date:** [July 5, 2021, 11:28pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/14 "2021-07-05T23:28:34Z")

</div>

> [@david551](#):
>
> That’s an example of why FreePBX users should only use the FreePBX forum.

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.

> [@david551](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 4, 2021, 11:29pm UTC](https://community.asterisk.org/t/asterisk-as-a-trunk/89130/15 "2021-08-04T23:29:35Z")

</div>

Closed on August 4, 2021, 11:29pm UTC

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