IAX2 trunk: "No authority found" problem

Hello! Asterisk newbie, so bear with me please. I am trying to configure an IAX2 trunk, but I am having a problem. My setup is the following: Two Asterisk servers. On Server A (with IP 192.168.1.2) I have setup the SIP extensions in the range of 1000 and the IAX2 extensions in the range of 3000. On Server B (with IP 192.168.2.2) I have setup the SIP extensions in the range of 2000 and the IAX2 extensions in the range of 4000, respectively. The SIP trunk works perfectly as well as the SIP local calls. But with the IAX2 trunk there is a problem (IAX2 local calls work fine though). So when i am trying to call from 3001 extension (which is on Server A) the 4000 extension (which is on Server B), Server A gives me the infamous “No authority found” error. On the other hand issuing the iax2 show registry and iax2 show peers commands in the CLI things look good. Following are my confs:

Server A

sip.conf

[code][general]
register => asterisk1sip:welcome@192.168.2.2/asterisk2sip
register => 1000:1000@192.168.1.2/1000

defaultexpirey=1800
maxexpirey=3600

disallow=all
allow=speex
allow=ulaw
allow=alaw

[asterisk2sip]
type=friend
secret=welcome
context=asterisk2_incoming
host=dynamic

[1000]
type=friend
context=phones
username=1000
secret=1000
host=dynamic
port=5060
nat =yes
qualify=Yes

[1001]
type=friend
context=phones
username=1001
secret=1001
host=dynamic
port=5060[/code]

iax.conf

[code][general]

autokill=yes
requirecalltoken=no
calltokenoptional=0.0.0.0/0.0.0.0
maxcallnumbers=16382

minregexpire=180
maxregexpire=180

register => asterisk1iax:welcome@192.168.2.2
register => 3000:3000@192.168.1.2

[asterisk2iax]
type=friend
host=dynamic
trunk=yes
secret=welcome
context=asterisk2_incoming
deny=0.0.0.0/0.0.0.0
permit=192.168.2.2/255.255.255.255

[3000]
type=friend
context=phones
secret=3000
host=dynamic

[3001]
type=friend
context=phones
secret=3001
host=dynamic[/code]

extensions.conf

[code][globals]

[general]
autofallthrough=yes

[default]
include => phones

[incoming_calls]

[phones]
include => internal
include => remote

[internal]
exten => _1XXX,1,NoOp()
exten => _1XXX,n,Dial(SIP/${EXTEN},30)
exten => _1XXX,n,Playback(demo-congrats)
exten => _1XXX,n,Hangup()

exten => _3XXX,1,NoOp()
exten => _3XXX,n,Dial(IAX2/${EXTEN},30)
exten => _3XXX,n,Playback(demo-abouttotry)
exten => _3XXX,n,Hangup()

[remote]
exten => _2XXX,1,NoOp()
exten => _2XXX,n,Dial(SIP/asterisk1sip/${EXTEN})
exten => _2XXX,n,Hangup()

exten => _4XXX,1,NoOp()
exten => _4XXX,n,Dial(IAX2/asterisk1iax:welcome@192.168.2.2/${EXTEN})
exten => _4XXX,n,Hangup()

[asterisk1_incoming]
include => internal[/code]

Server B

sip.conf

[code][general]
register => asterisk2sip:welcome@192.168.1.2/asterisk1sip
register => 2000:2000@192.168.2.2/2000

defaultexpirey=1800
maxexpirey=3600

disallow=all
allow=speex
allow=ulaw
allow=alaw

[asterisk1sip]
type=friend
secret=welcome
context=asterisk1_incoming
host=dynamic

[2000]
type=friend
context=phones
username=2000
secret=2000
host=dynamic
port=5060
nat =yes
qualify=Yes

[2001]
type=friend
context=phones
username=2001
secret=2001
host=dynamic
port=5060[/code]

iax.conf

[code][general]

autokill=yes
requirecalltoken=no
calltokenoptional=0.0.0.0/0.0.0.0
maxcallnumbers=16382

minregexpire=180
maxregexpire=180

register => asterisk2iax:welcome@192.168.1.2
register => 4000:4000@192.168.2.2

[asterisk1iax]
type=friend
host=dynamic
trunk=yes
secret=welcome
context=asterisk1_incoming
deny=0.0.0.0/0.0.0.0
permit=192.168.1.2/255.255.255.255

[4000]
type=friend
context=phones
secret=4000
host=dynamic

[4001]
type=friend
context=phones
secret=4001
host=dynamic[/code]

[code]extensions.conf

[globals]

[general]
autofallthrough=yes

[default]
include => phones

[incoming_calls]

[phones]
include => internal
include => remote

[internal]
exten => _2XXX,1,NoOp()
exten => _2XXX,n,Dial(SIP/${EXTEN},30)
exten => _2XXX,n,Playback(demo-congrats)
exten => _2XXX,n,Hangup()

exten => _4XXX,1,NoOp()
exten => _4XXX,n,Dial(IAX2/${EXTEN},30)
exten => _4XXX,n,Playback(demo-congrats)
exten => _4XXX,n,Hangup()

[remote]
exten => _1XXX,1,NoOp()
exten => _1XXX,n,Dial(SIP/asterisk2sip/${EXTEN})
exten => _1XXX,n,Hangup()

exten => _3XXX,1,NoOp()
exten => _3XXX,n,Dial(IAX2/asterisk2iax:welcome@192.168.1.2/${EXTEN})
exten => _3XXX,n,Hangup()

[asterisk2_incoming]
include => internal[/code]

You can also see the log from the IAX2 debug in Server A that gives the “No authority found” error:

[code][KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 006 ISeqno: 009 Type: IAX Subclass: ACK
Timestamp: 13895ms SCall: 32378 DCall: 01983 [192.168.1.7:4569]

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 000 ISeqno: 000 Type: IAX Subclass: POKE
Timestamp: 00003ms SCall: 03168 DCall: 00000 [192.168.2.2:4569]

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 001 ISeqno: 001 Type: IAX Subclass: ACK
Timestamp: 00003ms SCall: 03168 DCall: 00001 [192.168.2.2:4569]

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 000 ISeqno: 000 Type: IAX Subclass: REGREQ
Timestamp: 00008ms SCall: 01816 DCall: 00000 [192.168.2.2:4569]
USERNAME : asterisk2iax
REFRESH : 180

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 000 ISeqno: 000 Type: IAX Subclass: REGREQ
Timestamp: 00011ms SCall: 01816 DCall: 00000 [192.168.2.2:4569]
USERNAME : asterisk2iax
REFRESH : 180
CALLTOKEN : 51 bytes

[KAsterisk1A*CLI>
[0KTx-Frame Retry[000] – OSeqno: 000 ISeqno: 001 Type: IAX Subclass: REGAUTH
Timestamp: 00018ms SCall: 02164 DCall: 01816 [192.168.2.2:4569]
AUTHMETHODS : 2
CHALLENGE : \x31\x31\x37\x32\x36\x31\x35\x37\x31
USERNAME : asterisk2iax

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 001 ISeqno: 001 Type: IAX Subclass: REGREQ
Timestamp: 00014ms SCall: 01816 DCall: 02164 [192.168.2.2:4569]
USERNAME : asterisk2iax
REFRESH : 180
MD5 RESULT : 96a41d1209abca15e2dbf11c66f2fd67

[KAsterisk1A*CLI>
[0KTx-Frame Retry[000] – OSeqno: 001 ISeqno: 002 Type: IAX Subclass: REGACK
Timestamp: 00019ms SCall: 02164 DCall: 01816 [192.168.2.2:4569]
USERNAME : asterisk2iax
DATE TIME : 2010-07-02 17:00:18
REFRESH : 180
APPARENT ADDRES : IPV4 192.168.2.2:4569

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 002 ISeqno: 002 Type: IAX Subclass: ACK
Timestamp: 00019ms SCall: 01816 DCall: 02164 [192.168.2.2:4569]

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 000 ISeqno: 000 Type: IAX Subclass: NEW
Timestamp: 00003ms SCall: 32379 DCall: 00000 [192.168.1.7:4569]
VERSION : 2
CALLING NUMBER :
CALLING NAME :
FORMAT : 5259734
CAPABILITY : 260
USERNAME : 3001
CALLED NUMBER : 4000
DNID : 4000
CALLED CONTEXT : 192.168.2.2

Tx-Frame Retry[000] – OSeqno: 000 ISeqno: 001 Type: IAX Subclass: AUTHREQ
Timestamp: 00005ms SCall: 00934 DCall: 32379 [192.168.1.7:4569]
AUTHMETHODS : 2
CHALLENGE : \x33\x35\x32\x37\x32\x34\x34\x35\x34
USERNAME : 3001

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 001 ISeqno: 001 Type: IAX Subclass: AUTHREP
Timestamp: 00003ms SCall: 32379 DCall: 00934 [192.168.1.7:4569]
MD5 RESULT : 3adf971930f1b328ecf1a88d36c12a0a

Tx-Frame Retry[-01] – OSeqno: 001 ISeqno: 002 Type: IAX Subclass: ACK
Timestamp: 00003ms SCall: 00934 DCall: 32379 [192.168.1.7:4569]

Tx-Frame Retry[000] – OSeqno: 001 ISeqno: 002 Type: IAX Subclass: REJECT
Timestamp: 00008ms SCall: 00934 DCall: 32379 [192.168.1.7:4569]
CAUSE : No authority found
CAUSE CODE : 50

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 002 ISeqno: 002 Type: IAX Subclass: ACK
Timestamp: 00008ms SCall: 32379 DCall: 00934 [192.168.1.7:4569]

[KAsterisk1A*CLI>
[0KTx-Frame Retry[000] – OSeqno: 000 ISeqno: 000 Type: IAX Subclass: POKE
Timestamp: 00004ms SCall: 00036 DCall: 00000 [192.168.2.2:4569]

[KAsterisk1A*CLI>
[0KRx-Frame Retry[Yes] – OSeqno: 000 ISeqno: 001 Type: IAX Subclass: PONG
Timestamp: 00004ms SCall: 00001 DCall: 00036 [192.168.2.2:4569]

[KAsterisk1A*CLI>
[0KTx-Frame Retry[-01] – OSeqno: 001 ISeqno: 001 Type: IAX Subclass: ACK
Timestamp: 00004ms SCall: 00036 DCall: 00001 [192.168.2.2:4569]

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 000 ISeqno: 000 Type: IAX Subclass: REGREQ
Timestamp: 00003ms SCall: 32380 DCall: 00000 [192.168.1.7:4569]
USERNAME : 3001
REFRESH : 60

[KAsterisk1A*CLI>
[0KTx-Frame Retry[000] – OSeqno: 000 ISeqno: 001 Type: IAX Subclass: REGAUTH
Timestamp: 00013ms SCall: 11577 DCall: 32380 [192.168.1.7:4569]
AUTHMETHODS : 3
CHALLENGE : \x31\x35\x31\x34\x38\x33\x34\x33\x34
USERNAME : 3001

[KAsterisk1A*CLI>
[0KRx-Frame Retry[ No] – OSeqno: 001 ISeqno: 001 Type: IAX Subclass: REGREQ
Timestamp: 00016ms SCall: 32380 DCall: 11577 [192.168.1.7:4569]
USERNAME : 3001
REFRESH : 60
MD5 RESULT : fc1ad1c6f314a9bebd1765dd89fdee78

[KAsterisk1A*CLI>
[0KTx-Frame Retry[000] – OSeqno: 001 ISeqno: 002 Type: IAX Subclass: REGACK
Timestamp: 00019ms SCall: 11577 DCall: 32380 [192.168.1.7:4569]
USERNAME : 3001
DATE TIME : 2010-07-02 17:00:36
REFRESH : 180
APPARENT ADDRES : IPV4 192.168.1.7:4569 [/code]

I have to mention that I am using Asterisk from the SVN trunk (I need SRTP which is not in the mainline brunch). Thanx in advance for any response.