2 SIP trunks with the same provider [solved]

Hello
I have 2 SIP trunks configured with my provider.
Trunk_1 - is my main two-way trunk. Let’s name it a private line.
Trunk_8 - is a copy of Trunk_1, but uses the different account (username/password). I need this 2nd account for dialout only. Let’s name it a business line.

[trunk_1]
; this is my private line
secret = password
provider =
trunkstyle = customvoip
username = 1234567
trunkname = incoming
callerid =
hasexten = no
hassip = yes
hasiax = no
registeriax =
registersip = yes
host = provider.tld
dialformat = ${EXTEN:1}
context = provider_in
group =
insecure = invite
contact = 1234567
fromuser = 1234567
fromdomain = provider.tld
nat = yes
canreinvite = no

[trunk_8]
; this is my business line
secret = password
provider =
trunkstyle = customvoip
username = 7654321
trunkname = outgoing
callerid = "my business line" <7654321>
hasexten = no
hassip = yes
hasiax = no
registeriax =
registersip = no
host = provider.tld
dialformat = ${EXTEN:1}
context = incoming ; was 'outgoing'
group =
insecure = invite
fromuser = 7654321
fromdomain = provider.tld
nat = yes
canreinvite = no

My system works pretty good without Trunk_8 configured.
As soon as I added that line I faced the following problem.
All the calls coming to my 1st account 1234567 are recognized by Asterisk as calls on Trunk_8 !!! (Found peer ‘trunk_8’ for …) Probably because both trunks have the same host= configured, but I expected that some other parameters should be taken into account as well!

Initially I had different contexts configured for both trunks, so all my calls were dropped because I had no incoming call routing configured for Trunk_8 as soon as it was created for dialing out only. Then I changed the 2nd trunk to use the same context as the 1st (I don’t like it). Now I can receive calls, but now my internal SIP phones are showing the caller ID from Trunk_8 (“my business line” <7654321>) for on incoming calls!

In simple words I just want Asterisk to treat the calls to my 1st trunk account as calls to Trunk_1, not Trunk_8.

Any ideas how to fix this?
Thanks!

Maybe you can post relavant portions of your dial plan(s). From the description it’s not clear what exactly happened before your merged the two trunk contexts and after.

If all your incoming calls (presumably all from trunk_1) get dropped in trunk_8’s original context, it also means that the calls are delivered as from trunk_8. You may need to set up sip debug and review headers to see if your provider is doing something funky.

As you may see from the configuration example there is no SIP registration configured for trunk_8 so it’s theoretically impossible to receive a call over this trunk.

<--- SIP read from {proxy address here}:5060 --->
INVITE sip:1234567@{my address here} SIP/2.0

From: "xxx" <sip:1111111@.......>;tag=336162816-281081
To: <sip:1234567@provider.tld>

<------------->
--- (14 headers 11 lines) ---
Sending to {proxy address here}: 5060 (NAT)
Using INVITE request as basis request - IWF-E20231B0-BED2-11DB-ADEF-BAE788E3E8D2@.....
No user '1111111' in SIP users list
Found peer 'trunk_8' for '1111111' from {proxy address here}:5060

There is a clear indication that call comes from the host configured for both trunks, but the account name from trunk_1 configuration is present in INVITE and To:

I see that the provider doesn’t register in your system, so Asterisk can only match incoming based on URI.

Because you only have two, you can play with ordering. Try change the order in which the two appear in sip.conf. If unsuccessful, try use include file to force ordering (a trick for extensions.conf not sure if works for sip.conf). Try change trunk names if Asterisk base ordering on alphabetics.

I’ve tryed most of the tricks you suggested, but…
Finally I moved the main trunk (trunk_1) to the end of users.conf and problem is gone. I think I did it before without result.
Thank you, valley!