Configurating Outbound and inbound routes. Need some help

Hi everyone. I have not so much experience in working with Asterisk, but i am loving it. I need to make a simple task, but have some problems with it. It would be great if you could help me with advice and at least show me the right direction to go))) Main for me is understand the logic and your help would be very appreciated. So lets start -

Task - To receive calls from virtual mobile number than transfer it to asterisk server # 1 than to asterisk server # 2 and than on my sofphone. Somethink like this -

Virtual mobile number => sip provider => asterisk server # 1 => asterisk server # 2 => softphone.

After configuration i managed to receive calls on my asterisk server # 1 (if i connect a softphone there) but have problems with transfering to server # 2.

I have made 2 trunks on server # 1 ( 1 trunk of sip operator and 2 trunk to connect and register on server 2) and 1 trunk on server # 2 to connect to the first server.

Here is trunk configuration -

Server # 1

Trunk of sip operator -
Outgoing Settings
type=friend
username=02301 (my sip id, which is given by sip operator)
secret=****
insecure=invite
host=sipde.zadarma.com
fromuser=02301
fromdomain=sip.zadarma.com
canreinvite=no
dtmfmode=rfc2833
disallow=all

Incoming Settings
USER Context?: 02301
type=friend
username=02301
secret=******
insecure=invite
host=sipde.zadarma.com
fromuser=02301
fromdomain=sip.zadarma.com
canreinvite=no
dtmfmode=rfc2833
disallow=all
allow=alaw

Register string 02301:*******@sip.zadarma.com/02301

Trunk to connect to server # 2

type=friend
username=filialsip
secret=welcome1One
context=from-internal
host=dynamic
disallow=all
allow=speex,alaw,gsm
nat=yes
insecure=invite,port
canreinvite=no
Register string - officesip:welcome1One@109.120.165.116/filialsip

Server # 2
type=friend
username=officesip
secret=welcome1One
context=from-internal
host=dynamic
disallow=all
allow=speex,alaw,gsm
nat=yes
insecure=invite,port
canreinvite=no
Register string - filialsip:welcome1One@109.120.164.175/officesip

All trunks register and seems to be working ok.

As i understand my problem is in the outbound and inbound routes -
i tried differrent configuration and none of them is not working for me. As i understand these should work as -

server # 1
Inbound => trunk to connect to server # 2
Oubound => trunk of sip operator

Server # 2
Inbound => extension of my softphone
Outbound => trunk to connect to server # 1

As i need only to receive calls on my softphone i tried to delete outbound routes, but this also didnt help. I am also using amportal restart and sip reload commands after every configuration change. Maybe there is a problem with some dial plans, but i dont need to configure them as i need routing would be made for any call of any DID, etc.

Please, help me to uderstand the logic of this routing or at least give me some hint.

Hope, all of you would have a great day, and sorry for my bad English skills(((

Use static addresses for the internal trunk. You clearly know the addresses.

ok. would change it now.

As i understand if i use static than i should left the register string blank?

And what about outbound and inbound routes? Are they correct?

Should i also leave did and cid numbers with no info there if i would like to receive calls from any did and cid?

Thanks for help and advices. Wish you a good day)

I’ve never used separate inbound and outbound routes.

The section name is an important part of the information.

You have no outbound codecs, so you can delete the whole outbound section, as it is unusable to make calls.

insecure=invite was never needed on outbound entries and remotesecret is a better option on current Asterisks for inbound.

canreinvite is deprecated. (directmedia)

fromuser is deprecated, and only meaningful for outbound. Most people don’t need it, even then. (defaultuser)

Best practice for SIP is almost always to make everything type=peer. In any case, only inbound connections can make use of type=user.

USER context is not valid setting name.

nat=yes is probably unnecessary; you do not appear to have NAT anywhere in the system.

I assume server 1 is dual homed and the machine itself has a public IP address, as you have provided no means to discover such an address.