Thanks Shawn. I think also that it is quite logical. So I had already tried it, among many other things in sip.conf. Unfortunately no help at all. In fact, setting registertimeout less than 20 gives more troubles. The nonce key comes back with “401 Unauthorized” message would get timeout while Asterisk is taking the 20 seconds pause.
One thing is verified: No matter how long registertimeout is set to, Asterisk is taking these 20 seconds pauses anyway.
It might be something else forcing Asterisk to take those pauses, but it is not DNS. My installation has no problem to resolve DNS, and at the first SIP registration attempt the DNS name was already resolved. I don’t believe that Asterisk makes no cache of DNS resolutions.
I’ll try to make another fresh installation of Ubuntu and Asterisk, maybe version 1.6, just to see whether the problem still exists.
OK, David. It was because of DNS. Although not really “wait for a timeout on the first choice server”, in fact for a timeout on SRV record!
Asterisk makes absolutely NO cache of DNS resolutions! In a “register – 401 unauthorized with challenge nonce – register with credential – 200 OK” dialog, Asterisk resolves actually the same DNS name twice within 0.1 second! Stupid or what?
In my copy-paste generated sip.conf file, I happened to take “srvlookup=yes” along with many other things. Then Asterisk always tried to resolve SRV record for involved DNS names first and waited to get timeout before asking the real DNS names. This cost exactly 20 seconds in my normal DNS configuration.
After setting it to no, the whole thing works now.