Asterisk Behind NAT And Kamailio –> Internal IP In SDP And Not “externip”

Home » Asterisk Users » Asterisk Behind NAT And Kamailio –> Internal IP In SDP And Not “externip”
Asterisk Users 2 Comments


We have some Asterisk servers that we are moving behind a NAT to preserve public addresses and make room for growth. This is Asterisk 1.4

NAT works very good with the externip/localnet-setting when we are connected directly to our teleco. But when I try to use NAT and put them behind our Kamailio something interesting happens: The media-address in the SDP is the internal ip and not the external.

This is the setup:

Teleco <-> Kamailio <-> Asterisk
SIP –> –>


RTP <----------------> (NAT:ed to

On an incomming call from the teleco -> to kamailio (public addr) -> to asterisk in the private net. Asterisk responds with the following SDP:

o=root 1889 1889 IN IP4
s=session c=IN IP4
t=0 0
m=audio 23344 RTP/AVP 8 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16

Asterisk seems to think that because the proxy is on the localnet, the media is too, so it doesn’t use the externip as the RTP-ip.

This is a incomming call and the RTP ip of the other leg is another public address. So the RTP-ip should the public address (externip).

If I connect to the teleco directly from the pbx (bypassing kamailio)
Asterisk correctly uses the externip as the rtp-ip in the SDP.

I know this is an old and unsupported version of Asterisk, but any input on the topic is welcome. If this is supported in later versions we can maybe work around until we migrate later.


2 thoughts on - Asterisk Behind NAT And Kamailio –> Internal IP In SDP And Not “externip”

  • Hello,

    what I did when I had similar scenario was to let asterisk completely behind NAT, using only the local IP. I used rtpproxy running on the same host as kamailio to bridge the rtp between external and internal networks.

    Cheers, Daniel

  • 2013-07-01 15:04, Daniel-Constantin Mierla skrev:

    I think that you are right that this should be done with Kamailio. Maybe the nathelper-module in Kamilio would do the trick in modifying the SDP/Contact to the NAT:ed address instead of using rtpproxy.

    Thanks for the feedback!