Contact has the wrong IP address

I have a Sipura SPA3102 ( (1 FXO + 1 FXS) connected to my asterisk FreePBX (, hostname paganini).

The SIP port on the Sipura FXO is configured at 5061 and that on the asterisk FreePBX is 5091. RTP Media ports for the asterisk PBX are 10000-10999.

The FXO is configured as a trunk and there is an outbound route configured for 7-digit numbers.

I have a remote extension 3002 on the FreePBX. Port forwarding is done at the firewall/router to forward 5091 and the RTP ports to the asterisk at also.

The external IP address of the site where the PBX is located is on the day of the test.

Extension 3002 is at home ( and the external IP is at the time of the test.

When I use extension 3002 (X-Lite) to dial a PSTN number, this is the sequence that I captured:

a. 192.168.64:61158 -> INVITE Via: SIP/2.0/UDP;branch=… Contact: sip:3002@ To: sip:2432196@paganini From: 3002@paganini;tag=d01ce305, SDP in the payload
b. -> 401 Unauthorized. Authorization Digest algorithm=MD5 … Headers Via, From & To are repeated from the INVITE.
c. -> ACK Headers From & To are repeated with ;tag=xxxx added to From and To.
d. -> INVITE, same as the first INVITE but added the Authorization encrypted response
e. -> TRYING Contact: sip:2432196@192.168.123.[color=#FF0000]30[/color]:5091, From and To are the same as those in the INVITE.

The mysterious thing is why is the Contact not the IP of the Sipura FXO but the IP address of some unrelated computer on the LAN? The call gets dialed. But when it is answered, all the RTP packets go to that unrelated computer.

What should the proper Contact be at the TRYING response? Should it be the PBX or the FXO?


Contact has nothing to do with where the RTP goes. That is determined by the SDP. Contact will only make a difference if a re-invite is attemped or when a BYE is attempted.

I would guess that you haven’t told the Asterisk box that it is behind NAT (externip, etc.).

Thanks. That is a good clue. But where can I set any NAT options?

The SDP specified the same erroneous machine. Should the destination be the PBX or the FXO?

  • Sdp: Response: SIP/2.0 200 OK; SDP:SessionName=Asterisk PBX, Version=0, MediaDescription=audio 10832 RTP/AVP 0 8 101
    ProtocolVersion: 0
    • Origin: root 358212947 358212947 IN IP4 192.168.123.[color=#FF0000]30[/color]
      UserName: root
      SessionID: 358212947
      SessionVersion: 358212947
      NetworkType: IN
      AddressType: IP4
      Address: 192.168.123.[color=#FF0000]30[/color]

      SessionName: Asterisk PBX

    • ConnectionInfo: IN IP4
    • ActiveTime: 0 0
    • MediaDescription: audio 10832 RTP/AVP 0 8 101
    • SessionAttribute: rtpmap:0 PCMU/8000
    • SessionAttribute: rtpmap:8 PCMA/8000
    • SessionAttribute: rtpmap:101 telephone-event/8000
    • SessionAttribute: fmtp:101 0-16
    • SessionAttribute: ptime:20
    • SessionAttribute: sendrecv

externip, externhost, stunaddr, localnets

See the sample configuration files for details, correct spellings and which combinations are possible.

My SIP settings on asterisk seem to be in order. Some lines from /etc/asterisk/sip_general_additional.conf:


I back-tracked a bit and traced the registration process. At the OPTIONS request from the PBX, the Via, From and Contact headers were changed:

Via: SIP/2.0/UDP [color=#FF0000][/color]:5091;branch=z9hG4bK769b31f6;rport
From: “Unknown” sip:Unknown@[color=#FF0000][b][/b][/color]:5091;tag=as64d0b65e
To: sip:3002@;rinstance=fd0d1cd6753fcf04
Contact: sip:Unknown@[color=#FF0000][b][/b][/color]:5091
User-Agent: Asterisk PBX
Supported: replaces, timer

I think there are two issues with First, it’s not routeable from where I am right? Second, as explained earlier, it’s neither the PBX or the Sipura device. It is some other computer that happens to be on the LAN where the PBX is located.

May I know what should be the correct values of From and Contact in the OPTIONS request and how can I set to those?


The externhost, or the reverse DNS on it.

Are these wrong on the Asterisk server? Otherwise your problem is an over enthusiastic router. You should turn off SIP ALG on the router, for a start. I can’t see Asterisk reporting an address that is neither its externXXX, nor the address of one of its interfaces.

I hope your dynamic IP only changes when you have switched the router off for a long time, otherwise your ISP is deliberately trying to stop your running services.

Note options is a secondary function, to support the qualify option. You should actually be interested in REGISTER and INVITE.

Also, nat= doesn’t do what you think it does. Please read its description carefully.

I solved the problem, simply by adding externip instead!

I am surprised that externhost does not work when externrefresh=120, and my IP address typically lasts half a day.

I added the externip parameter using the FreePBX GUI. But I could not find it in sip_general_additional.conf or sip_general_custom.conf or in any other /etc/asterisk/*.conf. Where could it possibly go?



Those other files are artifacts of the GUI.

If you IP address is changing twice a day, your ISP doesn’t want you to run servers, and are operating a deliberately broken DHCP, etc., configuration. DHCP, used correctly will maintain a stable address for a persistent user.