Hi there,

I'm already using Kamailio as a simple proxy and it worked flawlessly.

This time, I need to have a new setup like this:

[UAC (sip phone)] <--- register & has to deal only with ----> | PUBLIC | [Kamailio + RtpEngine] | PRIVATE | <----> [Asterisk]
Client = 37.100.100.100 (public)
Asterisk = 172.17.200.20 (private)
Kamailio/RtpEngine = 172.17.203.102 (private, advertising 3.99.99.99 public IP)

Kamailio and RtpEngine will behave as a SBC/B2BUA, the client will deal only with kamailio using public access (internet), and asterisk will handle the calls but stays 100% private behind kamailio.

Kamailio will handle registrations to reduce the load put on the asterisk boxes.

The setup is running on AWS, my Kamailio has 1 Private IP address tied to 1 Public IP address (an Elastic public IP) so, no multi-homing, one network interface.

I made a "simple" work in progress configuration, the registration is working as a PoC, and my calls are *almost* working but with some nonsense.

My Main issue is that when my UAC (SIP phone) make a call, to let's say +1000, the call enters kamailio, then kamailio handle the invite, trigger rtpEngine, but the IP addresses in Record-Route and Via headers are wrong.

From Kamailio to UAC Sip Phone, it seems OK.
But from Kamailio to Asterisk, the record-route/via headers are set with Kamailio Public IP when it should be the Kamailio private IP.

So, when Asterisk sends a BYE, it tries to send it to the public IP of Kamailio, which is wrong.
There are probably other quirks in the configuration but this one, I can't figure out what's wrong.

I'm attaching a capture file, a log file and my configuration file (some informations are redacted).
I am missing something and sadly I can't figure out what, a little help would be appreciated :) 

Regards