Contact has the wrong IP address

I have a Sipura SPA3102 (192.168.123.34) (1 FXO + 1 FXS) connected to my asterisk FreePBX (192.168.123.35, 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 192.168.123.35 also.

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

Extension 3002 is at home (192.168.88.64) and the external IP is 219.9.9.9 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 -> 220.1.1.1:5091 INVITE Via: SIP/2.0/UDP 192.168.88.64:61158;branch=… Contact: sip:3002@219.9.9.9:61158 To: sip:2432196@paganini From: 3002@paganini;tag=d01ce305, SDP in the payload
b. 220.1.1.1:5091 -> 192.168.88.64:61158 401 Unauthorized. Authorization Digest algorithm=MD5 … Headers Via, From & To are repeated from the INVITE.
c. 192.168.88.64:61158 -> 220.1.1.1:5091 ACK Headers From & To are repeated with ;tag=xxxx added to From and To.
d. 192.168.88.64:61158 -> 220.1.1.1:5091 INVITE, same as the first INVITE but added the Authorization encrypted response
e. 220.1.1.1:5091 -> 192.168.88.64:61158 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?

Thanks.

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 1.6.2.13, 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 1.6.2.13

    • ConnectionInfo: IN IP4 192.168.123.30
    • 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:

nat=yes
externhost=xxxx.dyndns-ip.com
externrefresh=120
localnet=192.168.123.0/24

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]192.168.123.30[/color]:5091;branch=z9hG4bK769b31f6;rport
From: “Unknown” sip:Unknown@[color=#FF0000][b]192.168.123.30[/b][/color]:5091;tag=as64d0b65e
To: sip:3002@192.168.88.64:8910;rinstance=fd0d1cd6753fcf04
Contact: sip:Unknown@[color=#FF0000][b]192.168.123.30[/b][/color]:5091
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 1.6.2.13
Supported: replaces, timer
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO

I think there are two issues with 192.168.123.30. 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?

Thanks.

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?

Thanks.

sip.conf

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.