Soft phones don't connect: using Asterisk on a remote server (cloud instance)

Setting up Asterisk on GCP

I have used Asterisk 13, on a Google Cloud Platform instance, I am very new to Asterisk (started using it a few days ago). I need help with understanding how to connect devices (softphone would do) on my local machine.

sip.conf

[general]
context=public                  ; Default context for incoming calls. Defaults to 'default'
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
udpbindaddr=0.0.0.0             ; IP address to bind UDP listen socket to (0.0.0.0 binds to all)
tcpenable=no                    ; Enable server for incoming TCP connections (default is no)
tcpbindaddr=0.0.0.0             ; IP address for TCP server to bind to (0.0.0.0 binds to all interfaces)
transport=udp                   ; Set the default transports.  The order determines the primary default transport.
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
[authentication]
[basic-options](!)                ; a template
        dtmfmode=rfc2833
        context=from-office
        type=friend
[natted-phone](!,basic-options)   ; another template inheriting basic-options
        directmedia=no
        host=dynamic
[public-phone](!,basic-options)   ; another template inheriting basic-options
        directmedia=yes
[my-codecs](!)                    ; a template for my preferred codecs
        disallow=all
        allow=ilbc
        allow=g729
        allow=gsm
        allow=g723
        allow=ulaw
[ulaw-phone](!)                   ; and another one for ulaw-only
        disallow=all
        allow=ulaw
[peer-default]                    ; Added by me, above all is default
        disallow=all
        allow=alaw,ulaw
        type=friend
        host=dynamic
        context=softphone
        secret=<secret>
[peer-xvhy]
        disallow=all
        allow=alaw,ulaw
        context=softphone
        type=friend
        host=dynamic
        secret=<secret>

Addresses

My GCP instance has a public IP = GCP_IP
and my local machine(macOs) has a public IP = LOCAL_IP
I connect two softphones, with the domain = GCP_IP
one with username = peer-default
the other with username = peer-xvhy

With that, I am able to connect my phones.
On sip show peers I see:

eer-default/peer-default LOCAL_IP                          D  No         No             52629    Unmonitore
d                                  
peer-xvhy/peer-xvhy       LOCAL_IP                          D  No         No             52629    Unmonitore
d                                  
2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 2 online, 0 offline]

I find it strange that both have same ip and port.

When I try to call a phone using this extensions.conf:

[softphone]
exten => 100, 1, Dial(SIP/peer-default)
        same => n, Hangup()

I see this in the sip set debug on console:

<------------>
    -- Executing [100@softphone:1] Dial("SIP/peer-default-00000021", "SIP/peer-default") in new stack
  == Using SIP RTP CoS mark 5
Audio is at 16760
Adding codec alaw to SDP
Adding codec ulaw to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (no NAT) to <LOCAL_IP>:52629:
INVITE sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK5664fbba
Max-Forwards: 70
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@<LOCAL_IP>:52629;ob>
Contact: <sip:peer-default@<LOCAL_IP>:5060>
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
To: <sip:100@<GCP_IP>>;tag=as78507fab
CSeq: 102 INVITE
User-Agent: Asterisk PBX certified/13.21-cert2
Date: Fri, 06 Jul 2018 17:38:06 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 282

v=0
o=root 886654089 886654089 IN IP4 <LOCAL_IP>
s=Asterisk PBX certified/13.21-cert2
c=IN IP4 <LOCAL_IP>
t=0 0
m=audio 16760 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=maxptime:150
a=sendrecv

---
    -- Called SIP/peer-default

<--- SIP read from UDP:<LOCAL_IP>:52629 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK5664fbba
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@192.168.3.227;ob>
CSeq: 102 INVITE
Content-Length: 0

<------------->
--- (7 headers 0 lines) ---

<--- SIP read from UDP:<LOCAL_IP>:52629 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK5664fbba
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@192.168.3.227;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
CSeq: 102 INVITE
Contact: "jacken-hagar" <sip:peer-default@<LOCAL_IP>:52629;ob>
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

<------------->
--- (9 headers 0 lines) ---
sip_route_dump: route/path hop: <sip:peer-default@<LOCAL_IP>:52629;ob>
    -- SIP/peer-default-00000022 is ringing

<--- Transmitting (no NAT) to <LOCAL_IP>:52629 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
To: <sip:100@<GCP_IP>>;tag=as78507fab
Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
CSeq: 26560 INVITE
Server: Asterisk PBX certified/13.21-cert2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:100@<LOCAL_IP>:5060>
Content-Length: 0


<------------>

<--- SIP read from UDP:<LOCAL_IP>:52629 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK5664fbba
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@192.168.3.227;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
CSeq: 102 INVITE
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Contact: "jacken-hagar" <sip:peer-default@<LOCAL_IP>:52629;ob>
Supported: replaces, 100rel, norefersub
Content-Type: application/sdp
Content-Length: 282

v=0
o=- 3739887487 3739887488 IN IP4 <LOCAL_IP>
s=pjmedia
b=AS:117
t=0 0
a=X-nat:0
m=audio 4010 RTP/AVP 8 101
c=IN IP4 <LOCAL_IP>
b=TIAS:96000
a=rtcp:4011 IN IP4 192.168.3.227
a=sendrecv
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
<------------->
--- (11 headers 14 lines) ---
Found RTP audio format 8
Found RTP audio format 101
Found audio description format PCMA for ID 8
Found audio description format telephone-event for ID 101
Capabilities: us - (alaw|ulaw), peer - audio=(alaw)/video=(nothing)/text=(nothing), combined - (alaw)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
Peer audio RTP is at port <LOCAL_IP>:4010
sip_route_dump: route/path hop: <sip:peer-default@<LOCAL_IP>:52629;ob>
set_destination: Parsing <sip:peer-default@<LOCAL_IP>:52629;ob> for address/port to send to
set_destination: set destination to <LOCAL_IP>:52629
Transmitting (no NAT) to <LOCAL_IP>:52629:
ACK sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK7fa42c02
Max-Forwards: 70
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@<LOCAL_IP>:52629;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
Contact: <sip:peer-default@<LOCAL_IP>:5060>
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
CSeq: 102 ACK
User-Agent: Asterisk PBX certified/13.21-cert2
Content-Length: 0


---
    -- SIP/peer-default-00000022 answered SIP/peer-default-00000021
Audio is at 19568
Adding codec alaw to SDP
Adding codec ulaw to SDP
Adding non-codec 0x1 (telephone-event) to SDP

<--- Reliably Transmitting (no NAT) to <LOCAL_IP>:52629 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
To: <sip:100@<GCP_IP>>;tag=as78507fab
Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
CSeq: 26560 INVITE
Server: Asterisk PBX certified/13.21-cert2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:100@<LOCAL_IP>:5060>
Content-Type: application/sdp
Content-Length: 282

v=0
o=root 401214028 401214028 IN IP4 <LOCAL_IP>
s=Asterisk PBX certified/13.21-cert2
c=IN IP4 <LOCAL_IP>
t=0 0
m=audio 19568 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=maxptime:150
a=sendrecv

<------------>
    -- Channel SIP/peer-default-00000022 joined 'simple_bridge' basic-bridge <f1c38edc-c2d7-4681-ad97-7bcb7f7b19b1>
    -- Channel SIP/peer-default-00000021 joined 'simple_bridge' basic-bridge <f1c38edc-c2d7-4681-ad97-7bcb7f7b19b1>
set_destination: Parsing <sip:peer-default@<LOCAL_IP>:52629;ob> for address/port to send to
set_destination: set destination to <LOCAL_IP>:52629
Audio is at 16760
Adding codec alaw to SDP
Adding codec ulaw to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (no NAT) to <LOCAL_IP>:52629:
INVITE sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK71beb7ff
Max-Forwards: 70
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@<LOCAL_IP>:52629;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
Contact: <sip:peer-default@<LOCAL_IP>:5060>
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
CSeq: 103 INVITE
User-Agent: Asterisk PBX certified/13.21-cert2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
X-asterisk-Info: SIP re-invite (External RTP bridge)
Content-Type: application/sdp
Content-Length: 281

v=0
o=root 886654089 886654090 IN IP4 <LOCAL_IP>
s=Asterisk PBX certified/13.21-cert2
c=IN IP4 <LOCAL_IP>
t=0 0
m=audio 4008 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=maxptime:150
a=sendrecv

---

<--- SIP read from UDP:<LOCAL_IP>:52629 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK71beb7ff
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@192.168.3.227;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
CSeq: 103 INVITE
Contact: "jacken-hagar" <sip:peer-default@<LOCAL_IP>:52629;ob>
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Content-Type: application/sdp
Content-Length: 282

v=0
o=- 3739887487 3739887489 IN IP4 <LOCAL_IP>
s=pjmedia
b=AS:117
t=0 0
a=X-nat:0
m=audio 4010 RTP/AVP 8 101
c=IN IP4 <LOCAL_IP>
b=TIAS:96000
a=rtcp:4011 IN IP4 192.168.3.227
a=sendrecv
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
<------------->
--- (11 headers 14 lines) ---
Found RTP audio format 8
Found RTP audio format 101
Found audio description format PCMA for ID 8
Found audio description format telephone-event for ID 101
Capabilities: us - (alaw|ulaw), peer - audio=(alaw)/video=(nothing)/text=(nothing), combined - (alaw)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
Peer audio RTP is at port <LOCAL_IP>:4010
set_destination: Parsing <sip:peer-default@<LOCAL_IP>:52629;ob> for address/port to send to
set_destination: set destination to <LOCAL_IP>:52629
Transmitting (no NAT) to <LOCAL_IP>:52629:
ACK sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK3f0206ce
Max-Forwards: 70
From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
To: <sip:peer-default@<LOCAL_IP>:52629;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
Contact: <sip:peer-default@<LOCAL_IP>:5060>
Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
CSeq: 103 ACK
User-Agent: Asterisk PBX certified/13.21-cert2
Content-Length: 0


---
Retransmitting #1 (no NAT) to <LOCAL_IP>:52629:
SIP/2.0 200 OK
Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
To: <sip:100@<GCP_IP>>;tag=as78507fab
Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
CSeq: 26560 INVITE
Server: Asterisk PBX certified/13.21-cert2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:100@<LOCAL_IP>:5060>
Content-Type: application/sdp
Content-Length: 282

v=0
o=root 401214028 401214028 IN IP4 <LOCAL_IP>
s=Asterisk PBX certified/13.21-cert2
c=IN IP4 <LOCAL_IP>
t=0 0
m=audio 19568 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=maxptime:150
a=sendrecv

The retransmit log appears 10 times and then the call disconnects
this happens within 32 seconds every time.

with this error:

WARNING[25825]: chan_sip.c:4069 retrans_pkt: Retransmission timeout reached on transmission f60f2b6a32c0d48cc30f2e0f9c5174c8 for seqno 1 (Critical Response) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions
Packet timed out after 32000ms with no response

What (whatever little) I can understand is:

From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
To: <sip:100@<GCP_IP>>;tag=as78507fab

Is the problem it should be sending to and from LOCAL_IP because that’s what sip show peers says about the address about my soft phones.

Also, I can’t hear a thing :stuck_out_tongue: (Guess that gets’ fixed when this is taken care of)

Finally got to fix that, hope this helps someone else out.

Retransmitting #1 (no NAT) to <LOCAL_IP>:52629:
SIP/2.0 200 OK
Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
To: <sip:100@<GCP_IP>>;tag=as78507fab
Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
CSeq: 26560 INVITE
Server: Asterisk PBX certified/13.21-cert2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:100@<LOCAL_IP>:5060>
Content-Type: application/sdp
Content-Length: 282

Each time you see the above in sip set debug on logs you should focus on the contact header

Contact: <sip:100@<LOCAL_IP>:5060>

In my case <LOCAL_IP> was the internal address of my GCP Instance, and not the LOCAL_IP of my machine.

From here on in the sip.conf

[general]
context=public                  ; Default context for incoming calls. Defaults to 'default'
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
udpbindaddr=0.0.0.0             ; IP address to bind UDP listen socket to (0.0.0.0 binds to all)
tcpenable=no                    ; Enable server for incoming TCP connections (default is no)
tcpbindaddr=0.0.0.0             ; IP address for TCP server to bind to (0.0.0.0 binds to all interfaces)
transport=udp                   ; Set the default transports.  The order determines the primary default transport.
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
externip=<PUBLIC_IP_OF_YOUR_INSTANCE>
localnet=<INTERNAL_IP_OF_YOUR_INSTANCE>/<MASK (255.255.255.255)>

Also I heard some pink floyd echoes style sounds (because the calling and callee softphones were both on my local machine which kept feeding each other their outputs leading to the echoes).