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

Hi,

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 –> 1.2.3.4
10.0.0.1 –> 10.0.0.2

externip=1.2.3.5
localnet.0.0.0/255.255.255.0

RTP <----------------> 1.2.3.5 (NAT:ed to 10.0.0.2)

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

v=0
o=root 1889 1889 IN IP4 10.0.0.2
s=session c=IN IP4 10.0.0.2
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
a=ptime:20
a=sendrecv

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.

Thanks!

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!

    /Johan