Currently Asterisk seems to use the IP address of the device the INVITE is being sent to but I would like it to use a/the domain of the account the INVITE is being sent to.
By independently set them do you mean there is no way to set the To: to something different than request URI or do you mean they are one and the same and there is no way to set either/both of them to any other value than what Asterisk wants to set them to itself?
Maybe I’m not understanding the significance of pointing out the request URI in this context. Is it perhaps to indicate that by changing the request URI I can change the To: value? If so, how do I set the request URI?
I meant there is no way to set the To without also changing the Request URI.
The Request URI is either the contact specified on an AOR, a registered contact, or the URI specified in the endpoint. It determines the target of the SIP request as well as the Request URI and To URI. You haven’t shown configuration or elaborated on the complete configuration, so I can’t give real specifics unique to your configuration.
If you want to send the SIP request to one address, but have the Request and To URI be something else then you would set an outbound proxy using:
outbound_proxy=sip:target\;lr\;hide
In the configuration file on the endpoint. This would cause the SIP request to be sent to that address, but the Request and To URI be something else.
What goes in the request URI will be what was in the Contact header in the REGISTER from the other party. If you wan the domain name there, you must configure the remote entity appropriately.
But doesn’t the Contact: header in the REGISTER need to identify the specific device that is registering? IOW, doesn’t it need to be the IP address of the device otherwise Asterisk doesn’t know how to reach it when it needs to send an INVITE does it?
The exact address is needed in the domain part of the request URI for the call to go to the right device.
It is the address of record that can represent multiple devices, and that goes in the To header of the REGISTER. What goes in the Contact header must uniquely identify the the registering device.
I suppose Asterisk could have been implemented so that it inserts a, purely internal, proxy, when accessing dynamic hosts, but that isn’t how it has been done.
Even if that were done, the simple implementation would result in the domain name being that of the Asterisk UAC, Having the domain name considered when doing AOR lookups would confuse most users (it is possible that chan_pjsip does allow domain names in AOR section names, but dialstrings don’t currently use those).