UA(192.168.0.1)   Kamailio(1v1 NAT)              PBX
  |      INVITE             |                                         |
  |                               |     INVITE                        |
  |                               |       183                            |
  |      183                   |                                         |


Kamailio received  INVITE, then  add Record-Route: <sip:kamailio_public_ip>


UA(192.168.0.1) received 183,  find Record-Route(kamailio_public_ip)
then send ACK  to Kamialio_public_ip   not kamailio_internal_ip,  so Kamailio can't receive ACK from UA。 
UA and Kamailio are only connected to the intranet。


this is my config,192.168.0.1 -> Kamailio ->  Other SBC(public ip)
function ksr_request_route()
      if KSR.is_INVITE() then
            KSR.rr.record_route();
            KSR.nathelper.fix_nated_contact()
      end
end



this is packet capture

2023/10/07 10:31:13.112374 192.168.0.1:45642 -> 192.168.0.2:7080
INVITE sip:+8618626439917@192.168.0.2:7080 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.11:45642;branch=z9hG4bK98457cb5b0e44505;rport
Contact: <sip:05640@192.168.0.11:45642>
Max-Forwards: 70
To: <sip:+8618626439917@192.168.0.2:7080>
From: "05640" <sip:05640@192.168.0.2:7080>;tag=5c1a6b917a705e9e
Call-ID: b430efcf360145c3
CSeq: 39379 INVITE
Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,REFER,NOTIFY,SUBSCRIBE,INFO
Supported:
Content-Type: application/sdp
Content-Length: 756

2023/10/07 10:31:13.115403 192.168.0.2:7080 -> 122.97.130.198:15060
INVITE sip:+8618626439917@122.97.130.198:15060;user=phone SIP/2.0
Record-Route: <sip:36.140.122.12:7080;lr;>
Via: SIP/2.0/UDP 36.140.122.12:7080;branch=z9hG4bKe61a.5fe9d645ef1bbe470ca6d57fa20375bf.0
Via: SIP/2.0/UDP 192.168.0.1:45642;received=192.168.0.11;branch=z9hG4bK98457cb5b0e44505;rport=45642
Contact: <sip:05640@192.168.0.11:45642>
Max-Forwards: 70
To: <sip:+8618626439917@122.97.130.198:15060;user=phone>
From: "05640" <sip:02566043847@122.97.130.198:15060;user=phone>;tag=5c1a6b917a705e9e
Call-ID: b430efcf360145c3
CSeq: 39379 INVITE
P-Preferred-Service: urn:urn-7:3gpp-service.ims.icsi.mmtel
Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,REFER,NOTIFY,SUBSCRIBE,INFO


2023/10/07 10:31:15.162198 122.97.130.198:15060 -> 192.168.0.2:7080
SIP/2.0 183 Session Progress
Via: SIP/2.0/UDP 36.140.122.12:7080;rport=7080;branch=z9hG4bKe61a.5fe9d645ef1bbe470ca6d57fa20375bf.0
Via: SIP/2.0/UDP 192.168.0.1:45642;received=192.168.0.1;branch=z9hG4bK98457cb5b0e44505;rport=45642
Record-Route: <sip:36.140.122.12:7080;lr;>
From: "05640" <sip:02566043847@28.commchina.net:15060;user=phone>;tag=5c1a6b917a705e9e
To: <sip:+8618626439917@28.commchina.net:15060;user=phone>;tag=66DUcBjQy3erB
Call-ID: b430efcf360145c3
CSeq: 39379 INVITE
Contact: <sip:+8618626439917@192.168.0.166:17060;transport=udp>
User-Agent: FreeSWITCH-mod_sofia/1.10.9.18+git~20230524T013825Z~2191e53372~64bit
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, PRACK, NOTIFY

2023/10/07 10:31:15.163165 192.168.0.2:7080 -> 192.168.0.1:45642
SIP/2.0 183 Session Progress
Via: SIP/2.0/UDP 192.168.0.11:45642;received=192.168.0.11;branch=z9hG4bK98457cb5b0e44505;rport=45642
Record-Route: <sip:36.140.122.12:7080;lr;>
From: "05640" <sip:02566043847@28.commchina.net:15060;user=phone>;tag=5c1a6b917a705e9e
To: <sip:+8618626439917@192.168.0.2:7080>;tag=66DUcBjQy3erB
Call-ID: b430efcf360145c3
CSeq: 39379 INVITE
Contact: <sip:+8618626439917@192.168.0.166:17060;transport=udp>
User-Agent: FreeSWITCH-mod_sofia/1.10.9.18+git~20230524T013825Z~2191e53372~64bit
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, PRACK, NOTIFY
Supported: precondition, 100rel, path, replaces



This question has been bothering me for a long time,  help me


发件人: 城门 虾米 <codenot@msn.com>
发送时间: 2023年10月8日 6:16
收件人: Kamailio (SER) - Users Mailing List <sr-users@lists.kamailio.org>
主题: kamailio Behind nat. How Record-Route should be added ?
 
UA(192.168.0.11) received 183,  find Record-Route(36.140.122.12)
then send ACK  to 36.140.122.12(Kamialio public ip)   not 192.168.0.2(kamailio internal ip),  so Kamailio can't receive ACK.

this is my config,192.168.0.11 -> Kamailio ->  Other SBC(public ip)
function ksr_request_route()
      if KSR.is_INVITE() then
            KSR.rr.record_route();
            KSR.nathelper.fix_nated_contact()
      end
end

This question has been bothering me for a long time,  help me