I just discover Asterisk and this is my first post on this forum. I have a few knowledge about VoIP. We have a VoIP LAN which integer 2 ATAs FXS gateways connected to an analogic park phones and for the moment we have a proprietary IPBX system and a BRI gateway connected to 3 T0 ISDN lines. We want to leave this IPBX to return to the source of the IPBX with Asterisk and we try to migrate softly.
Suppose a phone P1 on ATA1 at 192.168.0.1 and a phone P2 on ATA2 at 192.168.0.2. Suppose now both phones are registered on the same Asterisk server. If I want to call P2 from P1, extensions.conf must consider the P1 contacts the ATA2 at 192.168.0.2 and reversely to call P1 from P2, P2 contacts the ATA1 at 192.168.0.1, so the ATA contacted, its IP, is function of the callee.
I asked to my myself if there is a possibility to add a custom variable on the users.conf which is retrieved in the dial plan of extensions.conf but I do not find a way to do this. Too I supposed there is a special variable to use like in this command Dial(SIP/${EXTEN}@${CHANNEL(peerip)}), but I did not find it. I discovered in the extensions.conf the actions ExecIf, GotoIf, and other and I imagined I can define one variable to contain the correct ATA in function of the callee but it seems a very hassle task to perform and it seems very not easy-friendly to maintain.
How to do this in the most simpliest way as possible ?
I wouldnât use users.conf. My impression is that experienced users donât use it and there is little knowledge about it.
I wouldnât user chan_sip; the source code has been removed from the next version.
I too donât understand why how this differs from the trivial case, in which you call the peer by its peer name, and let the system take care of looking up the IP address.
Note cable is assuming that the authentication name and address of record are the same as the extension name, which, although common, is not best security practice. However, even:
exten => 101,1,DIal(PJSIP/ata1)
doesnât really need messing around with variables, and , while:
exten => 101,1,Dial(PJSIP/<MAC of ata1>)
may be more awkward to handle, it is not that complicated.
If using secure names, you could define the mapping in a hint extension and then look that up for use in Dial.
These examples would be the same, substitution SIP for PJSIP, with chan_sip, but use of that is discouraged.
You are completely right My bad ! I do not know how I missed it and do not tested it. I supposed the callee address was mandatory. I lost many hours to understand what was wrong ⌠what a shame !
Anyway thanks for your quick feedback
OK so what would be the best practices ? Where to define users/extensions phones ?
I follows a lot of tutorials (some are old but other not but often contradict each other) which indicate the old way to configure Asterisk with SIP.
Also I tried to migrate to PJSIP, but that is not working as the BRI gateway do not register with Asterisk (the indicator stay red) and here is my last SIP configuration file (sip.conf) :
And of course on the berofix BRI gateway there is an account berofix/berofix which worked from SIP config but which do not worked from PJSIP config furthermore the module chan_sip.so is unloaded and res_pjsip.so is loaded.
Also I do not find some documentation about the peersâ username which is detected as âsâ as follows for extension 152 :
root@asterisk:~# asterisk -x "sip show peers"
Name/username Host Dyn Forcerport Comedia ACL Port Status Description
141/141 192.168.0.1 D Yes Yes 5060 Unmonitored
152/s 192.168.0.2 D Yes Yes 5060 Unmonitored
222/222 192.168.0.199 D Yes Yes 5060 Unmonitored
3 sip peers [Monitored: 0 online, 0 offline Unmonitored: 3 online, 0 offline]
I mention this because, I can not reach 152 (P2) from 141 (P1) and 222 (a SIP Phone jitsi desktop on a Debian system), but from 152 I can reach 141 and 222. I looked on the two ATAâs configurations but I do not notice a difference.
Here is the verbose activity when I try to call from 141 to 152 which gives a regular bip-bip-bip :
root@asterisk:~# asterisk -vvvvvvvvvvvvvvvrd
...
=========================================================================
Running as user 'asterisk'
Running under group 'asterisk'
Connected to Asterisk 18.17.0 currently running on asterisk (pid = 381)
Parsing /etc/asterisk/logger.conf
Core debug is still 1.
== Using SIP RTP CoS mark 5
> 0x7fd71c044820 -- Strict RTP learning after remote address set to: 192.168.0.1:31638
-- Executing [152@from-sip:1] Dial("SIP/141-00000016", "SIP/152") in new stack
== Using SIP RTP CoS mark 5
-- Called SIP/152
== Everyone is busy/congested at this time (1:0/0/1)
-- Executing [152@from-sip:2] Hangup("SIP/141-00000016", "") in new stack
== Spawn extension (from-sip, 152, 2) exited non-zero on 'SIP/141-00000016'
I dug into but I do not find a notable difference between 152 and 141 registration appart the âsâ :
So I removed the BRI and phones from respectively sip.conf and users.conf. Too I disabled the load of chan_sip.so from modules.conf and I configured as below.
...
[berofix]
type = endpoint
disallow = all
allow = ulaw
aors = berofix
auth = authberofix
[berofix]
type=aor
max_contacts=1
[authberofix]
type=auth
auth_type=userpass
username=berofix
password=berofix
; phones
[152]
type = endpoint
context = from-sip
aors = 152
auth = auth152
[152]
type=aor
max_contacts=1
; Necessary in particular "match" which needs explicitly its IP ?
; with or without => nothing change
;[152]
;type=identify
;endpoint=152
;match=192.168.0.2
[auth152]
type=auth
auth_type=userpass
username=152
password=1234
... the same for other phones
Too the phones are registered as this command indicates :
root@asterisk:~# asterisk -x "pjsip show endpoints"
Endpoint: <Endpoint/CID.....................................> <State.....> <Channels.>
I/OAuth: <AuthId/UserName...........................................................>
Aor: <Aor............................................> <MaxContact>
Contact: <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
Transport: <TransportId........> <Type> <cos> <tos> <BindAddress..................>
Identify: <Identify/Endpoint.........................................................>
Match: <criteria.........................>
Channel: <ChannelId......................................> <State.....> <Time.....>
Exten: <DialedExten...........> CLCID: <ConnectedLineCID.......>
==========================================================================================
...
Endpoint: 152 Not in use 0 of inf
InAuth: auth152/152
Aor: 152 1
Contact: 152/sip:152@192.168.0.2:5060 64779118ed NonQual nan
Identify: 152/152
Match: 192.168.0.2/32
Endpoint: berofix Not in use 0 of inf
InAuth: authberofix/berofix
Aor: berofix 1
Contact: berofix/sip:berofix@192.168.0.100:5060 add887a2f0 NonQual nan
Objects found: 4
But that do not working yet, the call is initiated then I hear a bip-bip-bip⌠repetedly without success ! Too I do not see any actiivity with verbose or debug (core set {verbose|debug} 4)
So I wanted to back to SIP and as nothing worked I discovered 2 things :
as one ATA gateway indicated that the phone was not registered no more => reboot the Asteriskâs server on this gateway resolved the problem
if I load the SIP (chan_sip.so) in modules.conf I have to unload explicitly the PJSIP (chan_pjsip.so and res_pjsip.so) and as the problem of bad username âsâ above disappeared, I suppose this is the explication
After applying the actions of above, SIP worked perfectly, but I guess in the future that if the configuration is not migrated in PJSIP it could arises other problems.
So what I missed for PJSIP works ?
Too is the âidentifyâ section of pjsip.conf for phones is mandatory ?
I feel like I am searching in the dark with a flashlight
You donât need identify if you are matching only by From user, and, in any case, it is only relevant for incoming requests, which are working, as the registration seems to have succeeded. If you know the IP address of the phone, there is no need to configure it to register, and you should specify the address, in the AOR section, as a contact, and not use max_contacts.
The phones need to have codecs set. I think the default is all, which can cause problems.
You should see the diaplan executing in verbose lines. If you donât the incoming side is broken⌠You need to use the CLI command âpjsip set logger onâ to see what is going over the wire.
Asterisk would not do that, unless you had explicit dialplan to do it, which would show on the verbose log. I suppose you phone might, but it seems more likely that you have a call up to the ATA and it is coming from the ATA, or further afield.
You are right ! The problem was effectively that I did not defined an available codec (here allow = ulaw). I am surprised that the codec is not defined to a default value.
OK I missed that.
Here is my actual working Asterisk configuration files :
root@asterisk:~# grep -E "^(astetcdir|runuser|rungroup)" /etc/asterisk/asterisk.conf
astetcdir => /etc/asterisk
runuser = asterisk ; The user to run as.
rungroup = asterisk ; The group to run as.
root@asterisk:~# grep -Ev "^([[:space:]]*;|$)" /etc/asterisk/extensions.conf
[general]
static=yes
writeprotect=no
clearglobalvars=no
[globals]
CONSOLE=Console/dsp ; Console interface for demo
IAXINFO=guest ; IAXtel username/password
TRUNK=DAHDI/G2 ; Trunk interface
TRUNKMSD=1 ; MSD digits to strip (usually 1 or 0)
...
[bri]
exten => _[349]XXX,1,Dial(PJSIP/${EXTEN}@berofix) ; Calls to our actual IPBX (our DIDs start with 3, 4 or 9 followed by 3 digits)
same => n,hangup
exten => _0.,1,Dial(PJSIP/${EXTEN}@berofix) ; Calls to external phones (0 to go out)
same => n,hangup
root@asterisk:~# grep -Ev "^([[:space:]]*;|$)" /etc/asterisk/pjsip.conf
[transport-udp]
type=transport
protocol=udp ;udp,tcp,tls,ws,wss,flow
bind=0.0.0.0
[general]
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
language=fr ; Default language setting for all users/peers
...
[berofix] ; Our BRI gateway
type = endpoint
disallow = all
allow = ulaw
aors = berofix
auth = authberofix
context = bri
[berofix]
type=aor
max_contacts=1
[authberofix]
type=auth
auth_type=userpass
username=berofix
password=berofix
[152] ; A physical analog phone
type = endpoint
context = bri
aors = 152
auth = auth152
disallow = all
allow = ulaw
[152]
type=aor
contact=sip:152@192.168.0.2:5060
[auth152]
type=auth
auth_type=userpass
username=152
password=1234
...
[222] ; A soft-phone
type = endpoint
context = bri
aors = 222
auth = auth222
disallow = all
allow = ulaw
[222]
type=aor
max_contacts=100 ; 'max_contacts' works but 'contact' NOT, why ?
;contact=sip:222@192.168.0.199:5060 ; KO
[auth222]
type=auth
auth_type=userpass
username=222
password=1234
Everything works great !
I can call between 2 Asterisks extensions (included between an analog phone and a SIP phone), from Asterisk to the actual IPBX, from Asterisk to external (example : to my smartphone).
2 latests questions :
Is there a solution to not specifying âcontactâ without its IP address which is redundant ?
Why with SIP phones âcontactâ do not working but âmax_contactsâ do ?