Asterisk SIP 401 unauthorized

Hi all,

I am trying to setup a sip proxy using Asterisk version 1.8.5, but I cannot seem to register with the remote server. Any help is appreciated. The following is my sip.conf, extensions.conf and the sip debug log.

[general]

allowoverlap=no
udpbindaddr=0.0.0.0

externaddr=111.69.197.238
localnet=172.16.0.0/255.255.255.0

register=>myusername:mypassword@2talk.co.nz

tcpenable=no

srvlookup=yes

[2talk]
context=default
disallow=all
allow=alaw
type=user
fromdomain=2talk.co.nz
host=2talk.co.nz
fromuser=myusername
defaultuser=myusername
remotesecret=mypassword
canreinvite=no
insecure=invite,port
nat=yes

My extensions.conf:

[general]
static=yes
writeprotect=no

[default]
; Answer inbound calls
exten => s,1,Dial(SIP/mynumber)
; outbound calls
exten => _X.*,1,Dial(SIP/${EXTEN}@2talk)

sip debug log

Scheduling destruction of SIP dialog ‘2b7a847f28e829124a626b9e1fe236fe@202.180.76.182’ in 32000 ms (Method: NOTIFY)
Really destroying SIP dialog ‘3c1a656c609ec42e7097a5664ebb1fb1@202.180.76.182’ Method: OPTIONS

<— SIP read from UDP:202.180.76.182:5060 —>
OPTIONS sip:s@172.16.0.14:5060 SIP/2.0
Via: SIP/2.0/UDP 202.180.76.182:5060;branch=z9hG4bK34fe1381;rport
From: “2talkpbx” sip:2talkpbx@202.180.76.182;tag=as727c72f2
To: sip:s@myexternalip:5060
Contact: sip:2talkpbx@202.180.76.182
Call-ID: 1f4c7ab15a726c554714c5fe05f8678d@202.180.76.182
CSeq: 102 OPTIONS
User-Agent: 2talk PBX
Max-Forwards: 70
Date: Fri, 02 Sep 2011 03:02:02 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY
Supported: replaces
Content-Length: 0

<------------->
— (13 headers 0 lines) —
Looking for s in default (domain 172.16.0.14:5060)

<— Transmitting (no NAT) to 202.180.76.182:5060 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 202.180.76.182:5060;branch=z9hG4bK34fe1381;rport;received=202.180.76.182
From: “2talkpbx” sip:2talkpbx@202.180.76.182;tag=as727c72f2
To: sip:s@myexternalip:5060;tag=as67f66e56
Call-ID: 1f4c7ab15a726c554714c5fe05f8678d@202.180.76.182
CSeq: 102 OPTIONS
Server: Asterisk PBX 1.8.5.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
Contact: sip:myexternalip:5060
Accept: application/sdp
Content-Length: 0

<------------>
Scheduling destruction of SIP dialog ‘1f4c7ab15a726c554714c5fe05f8678d@202.180.76.182’ in 32000 ms (Method: OPTIONS)
Really destroying SIP dialog ‘2b7a847f28e829124a626b9e1fe236fe@202.180.76.182’ Method: NOTIFY
Really destroying SIP dialog ‘1f4c7ab15a726c554714c5fe05f8678d@202.180.76.182’ Method: OPTIONS
[Sep 2 15:05:47] NOTICE[3264]: chan_sip.c:12578 sip_reregister: – Re-registration for username@2talk.co.nz
REGISTER 11 headers, 0 lines
Reliably Transmitting (no NAT) to 202.180.76.182:5060:
REGISTER sip:2talk.co.nz SIP/2.0
Via: SIP/2.0/UDP myexternalip:5060;branch=z9hG4bK6aa5ebf2
Max-Forwards: 70
From: sip:username@2talk.co.nz;tag=as0a0052e9
To: sip:username@2talk.co.nz
Call-ID: 3a123c7b770b8ecf67337a4315bf508f@127.0.1.1
CSeq: 104 REGISTER
User-Agent: Asterisk PBX 1.8.5.0
Authorization: Digest username=“username”, realm=“2talk.co.nz”, algorithm=MD5, uri=“sip:2talk.co.nz”, nonce=“1fb60d77”, response="10279d9244cfcda60729114420c871df"
Expires: 120
Contact: sip:s@myexternalip:5060
Content-Length: 0


<— SIP read from UDP:202.180.76.182:5060 —>
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 172.16.0.14:5060;branch=z9hG4bK6aa5ebf2;received=myexternalip
From: sip:username@2talk.co.nz;tag=as0a0052e9
To: sip:username@2talk.co.nz
Call-ID: 3a123c7b770b8ecf67337a4315bf508f@127.0.1.1
CSeq: 104 REGISTER
User-Agent: 2talk PBX
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY
Supported: replaces
Contact: sip:username@202.180.76.182
Content-Length: 0

<------------->
— (11 headers 0 lines) —

<— SIP read from UDP:202.180.76.182:5060 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 172.16.0.14:5060;branch=z9hG4bK6aa5ebf2;received=myexternalip
From: sip:username@2talk.co.nz;tag=as0a0052e9
To: sip:username@2talk.co.nz;tag=as53939628
Call-ID: 3a123c7b770b8ecf67337a4315bf508f@127.0.1.1
CSeq: 104 REGISTER
User-Agent: 2talk PBX
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY
Supported: replaces
WWW-Authenticate: Digest algorithm=MD5, realm=“2talk.co.nz”, nonce="2c4aa1d7"
Content-Length: 0

<------------->
— (11 headers 0 lines) —
Responding to challenge, registration to domain/host name 2talk.co.nz
REGISTER 11 headers, 0 lines
Reliably Transmitting (no NAT) to 202.180.76.182:5060:
REGISTER sip:2talk.co.nz SIP/2.0
Via: SIP/2.0/UDP myexternalip:5060;branch=z9hG4bK791bd224
Max-Forwards: 70
From: sip:username@2talk.co.nz;tag=as6442f718
To: sip:username@2talk.co.nz
Call-ID: 3a123c7b770b8ecf67337a4315bf508f@127.0.1.1
CSeq: 105 REGISTER
User-Agent: Asterisk PBX 1.8.5.0
Authorization: Digest username=“username”, realm=“2talk.co.nz”, algorithm=MD5, uri=“sip:2talk.co.nz”, nonce=“2c4aa1d7”, response="4a0b4424c480503483980f22b7aa8cfb"
Expires: 120
Contact: sip:s@myexternalip:5060
Content-Length: 0


<— SIP read from UDP:202.180.76.182:5060 —>
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 172.16.0.14:5060;branch=z9hG4bK791bd224;received=myexternalip
From: sip:username@2talk.co.nz;tag=as6442f718
To: sip:username@2talk.co.nz
Call-ID: 3a123c7b770b8ecf67337a4315bf508f@127.0.1.1
CSeq: 105 REGISTER
User-Agent: 2talk PBX
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY
Supported: replaces
Contact: sip:username@202.180.76.182
Content-Length: 0

<------------->
— (11 headers 0 lines) —

<— SIP read from UDP:202.180.76.182:5060 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.16.0.14:5060;branch=z9hG4bK791bd224;received=myexternalip
From: sip:username@2talk.co.nz;tag=as6442f718
To: sip:username@2talk.co.nz;tag=as53939628
Call-ID: 3a123c7b770b8ecf67337a4315bf508f@127.0.1.1
CSeq: 105 REGISTER
User-Agent: 2talk PBX
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY
Supported: replaces
Expires: 120
Contact: sip:s@172.16.0.14:5060;expires=120
Date: Fri, 02 Sep 2011 03:02:46 GMT
Content-Length: 0

<------------->
— (13 headers 0 lines) —
Scheduling destruction of SIP dialog ‘3a123c7b770b8ecf67337a4315bf508f@127.0.1.1’ in 32000 ms (Method: REGISTER)
[Sep 2 15:05:48] NOTICE[3264]: chan_sip.c:20043 handle_response_register: Outbound Registration: Expiry for 2talk.co.nz is 120 sec (Scheduling reregistration in 105 s)

It keep on repeating this cycle indefinitely…

thanks

That’s a successful registration with a timeout of 2 minutes. If you mean by indefinitely that it repeats every minute, that is what I would expect, if it were working properly.