How to make Asterisk use my external address in the contact header?

I am running 13.6 from Gerritt and pjsip 2.4.5 behind NAT with a dynamic IP address. Asterisk / pjsip seems to insist on putting my private IP into the contact header. Doesn’t seem to cause a problem but I don’t like the idea of exposing it. Note that I am running enable=yes in dnsmgr.conf. I am familiar with the externaddr command but can’t use it because of the dynamic IP address. Is there a way to make Asterisk track and use the public IP?

edited I set up stun in rtp.conf and res_stun_monitor.conf.
pjsip now shows
stun show status
Hostname Port Period Retries Status ExternAddr ExternPort 3478 300 3 OK 75.23.nnn.nnn 35486

ExternAddr looks correct but when I run pjsip show transport my_transport
both External_Signaling_Addr and External_Media_Address are blank and the Contact header still lists the Lan address. This was reported in 2014 but there were no responses. Similar to post

On chan_sip you have the option “externhost = hostname[:port]” is similar to “externaddr” except
; that the hostname is looked up every “externrefresh” seconds ". I’m not sure if the option external_signaling_address on pjsip accept a hostname or just only IP

The PJSIP module does not use the data from rtp.conf and res_stun_monitor.conf. You need to set the external_signaling_address and a local_net in order to have the Contact address changed.

local_net is set. Everything else seems to work Ok without STUN. So there is no way to track the IP address when you are dealing with a dynamic IP? Correct?

The option does accept a hostname and can use dnsmgr.conf to automatically refresh the address at a specific interval. It doesn’t support the STUN method though.

1 Like

Thanks. I suspected that might be the case. I’ll probably drop it since the [local] IP isn’t routable anyway. I just had my ITSP question me as to why it was doing that. My inexpensive Obi 110 tracks it and uses the WAN IP but I’ve never used wireshark to see if it really works. I thought it might tighten security slightly.

I think the Obi is more of a consumer product. Asterisk is more of a business product, and businesses ideally have static addresses, but if they don’t they keep the XDSL link up permanently and have ISPs that don’t, gratuitously, change the IP address.

Hmmm. I came up with an unorthodox solution by simply setting both external_ addresses to a dummy unroutable IP that isn’t in my local_net. Calls both ways seem to work Ok. I looked at and it looks like the feature might be available in 2.5.5 but not sure. I use Microsip on my laptop sometimes, which also uses pjsip and it has the feature. Not saying Asterisk is bad in any way. Great product. Fills a hole in my home setup nicely.

We use PJSIP at a lower level than clients do, as a result we don’t gain some of the user client features they do (for example the behavior you may see in that area).

I have the same problem. A solution would be hostname support for external_media_address. @proftech would you agree with me?

I believe it does support hostnames but my IP address is dynamic and I am not using DYNdns or anything like that so it doesn’t help. :frowning: