I am using Asterisk version 188.8.131.52
The Asterisk server is running on an AWS EC2 instance (and is not behind a NAT). It is communicating with a Kamailio Server which is in the same local network as the Asterisk.
The issue which I am observing is that whenever Asterisk is sending any SIP request like OPTIONS or INVITE to Kamailio, it is setting its public IP in the contact header instead of the local IP. Due to this, for any REINVITE in the call, Kamailio will try to send the packets to the Public IP of Asterisk which is unnecessary. The relevant part of my sip.conf is provided below:
[general] context=sip-archit subscribecontext=sip-archit externip=x.x.x.x (Public IP) localnet=10.x.x.x/255.255.255.0 ;Kamailio [kamailio.dummy.com] type=friend ;kamailio.dummy.com (hostname changed from actual) resolves to 10.x.x.x IP address host=kamailio.dummy.com disallow=all allow=ulaw allow=alaw nat=no insecure=invite,port canreinvite=no context=sip-archit sendrpid=yes trustrpid=yes relaxdtmf=yes qualify=yes
So my questions are:
- On what basis does Asterisk decide whether to use Public IP or Local IP in the contact header?
- In this case it makes logical sense for Asterisk to use local IP in the contact header right - since the kamailio machine is in the same local network?
- How can I fix this so that the contact header has the local IP? Also in general how can I configure/ override the contact header in Asterisk?