Sip Contact Header Manipulation

Good day Team.
i need your assistance, first time configuring a freePBX.
so I have configured a sip trunk as per below:

so the issue is when the upstream service provider receives the registration request the contact on the request is Contact:sip:[email protected]:26213 instead of Contact:sip:[email protected]:5060.
where in freePBX can I change this of fix it ?

The 26213 will reflect the port number from you sent the request. You would only get that if you had explicitly configured that, or if a router is translating the port number. Although it is common advice not to use anything similar to 5060, to reduce toll fraud attempts, 26213 is so strange that, is unlikely that you chose this value, and I, therefore, think that problem lies with your router.

If the ITSP cares about the user part of the Contact header, their SIP implementation is broken. They should return it as is. It is configurable in Asterisk, and I’m pretty sure it is configurable in FreePBX, but you need to make a corresponding change in the dialplan, as the important requirement is that it match what is in the dialplan, not anything that the ITSP knows about you.

Thanks David… how do you configure it in Asterisk ?

Firstly you shouldn’t be using chan_sip for new installations.

You can set the port number using

NB this is in the general section.

And you set the user part as detailed here:

Changing the first, if the router is actually changing the port (which you should stop it doing) will result in incoming calls not arriving and may result in outgoing calls dropping after varying amounts of time. In any case, it should only be manipulated through the GUI when using FreePBX.

Changing the latter, without a coordinated dialplan change may result in incoming calls failing saying that the extension wasn’t found, or change FreePBXes DID identification. Again it is something that should be changed using FreePBX, not Asterisk.

I was unable to find a sample screen image but I think the port number will be on the chan_sip tab under sip settings. For the user name, see the reference to DID in

NB These may refer to different versions of FreePBX.

Possibly from different versions of FreePBX, but, although I can’t find a screenshot, the port number is probably on the chan_sip tab of sip settings. and see the reference to DID in

However, I would strongly suggest that the port number is being mangled by your router, as it is unlikely that you manually set it to the value shown.

Then fix your register string. 1) type=peer means no REGISTER. You’re peering via IP. 2) You’re still sending a REGISTER which is dealt with in the REGISTER string, you’re missing the /contact portion of it and that is why your REGISTER location is s vs the actual user. You’re not specifying the user.

Also, you should be using Chan_PJSIP for this stuff.

can you please send me an example of where I need to fix it ?

; Asterisk can register as a SIP user agent to a SIP proxy (provider)
; Format for the register statement is:
;       register => [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry]

The /extension part is what you are looking for.

type=peer has no effect on registration. It means don’t match the other party by from user name on incoming requests other than register. It has no impact at all on incoming registers, which always match on the section name, and it is irrelevant for outgoing registers which are controlled by the register => line.

Most trunks and extensions should be type=peer. The only exception is where the same source IP address can be associated with multiple end point. Most suggested configurations are poor in this respect.

I’m going to be honest, having this discussion in 2021 when Chan_SIP is deprecated, requires extra steps to be installed/compiled in versions 17+ and the fact it gets removed in the next Standard release of 21…is a waste of our time.

As I understand it, this option will have no effect when not using host=dynamic. It is however, possible, that you need fromuser set to the same value, but this won’t affect the registration step.

I agree that first time users of FreePBX should only use chan_pjsip, even if the ITSP claims not to support it. I would advise against mechanically translating provider provided chan_sip configurations.

The weird port number may be the result of trying to use chan_sip on FreePBX with both drivers enabled. It will use 5060 for chan_pjsip, and a different port for chan_sip, although still a lowish numbered one. The router may be being very clever, recognizing that the port isn’t being forwarded, and creating a dynamic port number and forwarding rule, but also noticing that the content is SIP, so rewriting the SIP headers to match.

Again the fix for that is to disable chan_sip and do a purely chan_pjsip configuration. You should also look to disabling intelligent handling of SIP in the router, as application level gateways reportedly break things more often than they help.

Let’s start from the basics here. Although I agree with the others that you should be using pjsip, I suspect that there is an easy fix using chan_sip and we should try that first.

Contact:sip:[email protected]:5060

Change the Register String to read:
27123210737:[email protected]/27123210737
(of course, use your actual username and password)
That will fix the username part of the Contact header.

The port number is apparently being rewritten by your router/firewall. Please post the make and model, along with any VoIP-specific settings you are using.

Also, please post: Does Asterisk register successfully? If so, does anything get logged on an attempted incoming call?

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