Documenting Problems That Were Difficult To Find The Answer To

Linksys SIP Call Terminates After 32 Seconds Because of Invalid Asterisk Contact Header

I had a friend call me from their Linksys VoIP phone to my Asterisk server using SIP (over the Internet).

The call would come in – ring my internal extension just fine. I would pick up the phone – and we could both hear each other.

However approximately 30 seconds later the call would terminate suddenly. It turned out the call was terminated precisely 32 seconds later.

Using debugging (sip set debug on) I captured the SIP packets for debugging.

The incoming INVITE from my friend looked like this (anonymised):

Via: SIP/2.0/UDP;branch=z9hG4bK-fe593a22;rport
From: "Test Client" <>;tag=a824af307af335a1o0
To: <>
Call-ID: 1c5d63e3-6ade2eca@
CSeq: 101 INVITE
Max-Forwards: 70
Contact: "Test Client" <sip:1234567890@>
Expires: 240
User-Agent: Linksys/SPA942-6.1.5(a)
Content-Length: 399
Supported: replaces
Content-Type: application/sdp

All good. Well, things would go well until I picked up the call and I would see the SIP OK from my Asterisk server being retransmitted without acknowledgement from my friend’s Linksys phone:

Retransmitting #10 (NAT) to
SIP/2.0 200 OK
Via: SIP/2.0/UDP;branch=z9hG4bK-fe593a22;received=;rport=5060
From: "Test Client" <>;tag=a824af307af335a1o0
To: <>
Call-ID: f8227f59-90d685a6@
CSeq: 101 INVITE

[Sep 8 13:48:08] WARNING[15643]: chan_sip.c:3641 retrans_pkt: Retransmission timeout reached on transmission f8337f49-91d68a12@ for seqno 101 (Critical Response) -- See
Packet timed out after 32000ms with no response

I used tcpdump to confirm that no SIP packets were being transmitted to me after I picked up the call.

So I looked up a little further to see what Asterisk was telling the Linksys phone after it attempted to INVITE me to a call.

SIP/2.0 200 OK
Via: SIP/2.0/UDP;branch=z9hG4bK-fe593a22;received=;rport=5060
From: "Test Client" <>;tag=a824af307af335a1o0
To: <>;tag=as7cf44a28
Call-ID: 91d68a12-f8337f49@
CSeq: 101 INVITE
Server: Asterisk PBX
Supported: replaces, timer
Contact: <sip:222@>
Content-Type: application/sdp
Content-Length: 277

My Asterisk server was sending a Contact: header with an internal IP address! And the Linksys phone was using this Contact-header (Contact-URI) to send all future SIP packets. Thus I stopped receiving SIP packets from the Linksys phone once I answered the call. Now my friend and I could talk – RTP was working – but the call would be terminated by Asterisk after 32 seconds.

How To Fix The Contact Header In Asterisk

There were two steps. Firstly I needed to specify what my external IP address was. There are two ways. If you know your external IP address and it doesn’t change then specify it directly:


However if you’re running an Asterisk server at home you probably have a dynamic address. I personally use a free Dynamic DNS account and have my SIP domain name as a CNAME to my Dynamic DNS domain name. In this case specify:

externrefresh=180           ; update address from domain name every 3 minutes

The next step is to ensure your Asterisk server knows what a local address is – so that it can present this externip or externhost in the Contact header when INVITEd from outside your local network:


Now you should see outgoing Contact: URLs using your external IP address – and the Linksys phone should now be able to correctly contact your Asterisk server once you’ve picked up your extension to answer.

Alternative Method

What if your Asterisk server is NATted behind another NAT? For example – in my configuration I had a router (running NAT) connected to the Internet and my home network. On my home network I had a Linux server (also running NAT) – and hosted on that Linux server I had a LXC container running my Asterisk server.

Linux has the nf_nat_sip module which should re-write the appropriate Contact: header.

Try loading the module on your NAT server by typing modprobe nf_nat_sip, confirm it is loaded with lsmod |grep nf_nat_sip, and re-try your call.

One response to “Linksys SIP Call Terminates After 32 Seconds Because of Invalid Asterisk Contact Header

  1. Fog_Watch June 10, 2016 at 1:16 am

    Thanks SO much for this.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: