Hello,

having use_dns_cache=no is not that bad if you have a local dns cache application pointed by /etc/resolv.conf, provided that you do not need srv based load balancing.

Not being the developer of dns resolving part in kamailio and the dns cache, I investigated a bit and practically the /etc/hosts is the pre-dns way of associating domains to ip addresses, without ttl and other attributes specific to dns records. That seems the reason the libc dns related functions do not use it implicitly, thus also not reflected inside kamailio dns caching.

Now, you can add records to kamailio dns cache via rpc commands, which can be done also from config using jsonrpc_exec() from jsonrpcs module (e.g., using event_route[htable:mod-init] before sip traffic is handled). The command should be liked:

kamctl rpc dns.add_a domain ttl ipaddr flags

The flags can be 1 to add it as a bad record (blacklisted domain) or 2 to add it as permanent record (do not expire). You can use dns.add_aaaa for ipv6.

Actually I am now thinking to add the possibility to add to dns cache via modparam of ipops module, to make it easier overall.

Cheers,
Daniel

On 20.05.20 19:35, George Diamantopoulos wrote:
Hello all,

Thank you for your enlightening answers. I ended up creating DNS entries anyway, so it's all good now. use_dns_cache=no sounded a little scary :-).

BR.
George

On Tue, 19 May 2020 at 19:44, Daniel-Constantin Mierla <miconda@gmail.com> wrote:
A quick follow up as I found quite interesting that nowadays *BSDs allow
specifying order of lookup in resolv.conf to include the hosts file, but
that doesn't seem to be in Linux:

  * https://man.openbsd.org/resolv.conf.5#lookup

Cheers,
Daniel


On 19.05.20 17:48, Daniel-Constantin Mierla wrote:
> Hello,
>
> worth to clarify that Kamailio doesn't implement a dns resolver from
> scratch, it still uses the functions from libc. It only does caching and
> try to use cashing records first.
>
> By default, the following dns functions are used internally when the
> cache doesn't have the record already -- they are set in the dns_func
> structure:
>
> struct dns_func_t dns_func = {
>     res_init,
>     res_search,
>     gethostbyname,
> #ifdef HAVE_GETHOSTBYNAME2
>     gethostbyname2
> #else
>     NULL
> #endif
> };
>
> So practically by leveraging res_init()/res_search() is relying on
> /etc/resolv.conf to do DNS queries, which is not using the /etc/hosts
> (iirc). For more see:
>
>   * https://linux.die.net/man/3/res_search
>
> Cheers,
> Daniel
>
> On 19.05.20 17:23, Alex Balashov wrote:
>> You are correct that Kamailio does not use the libc resolver /
>> libresolv, but rather its own resolver, which ignores /etc/hosts.
>>
>> -- Alex
>>
>> On 5/19/20 10:42 AM, George Diamantopoulos wrote:
>>> Hello all,
>>>
>>> I've come across this today when trying to setup DMQ replication:
>>>
>>> root@sbcpub0-stage-lhe0-cn1:/root# systemctl restart kamailio
>>> root@sbcpub0-stage-lhe0-cn1:/root# kamcmd dmq.list_nodes
>>> {
>>>          host: 172.30.154.189
>>>          port: 5090
>>>          resolved_ip: 172.30.154.189
>>>          status: active
>>>          last_notification: 0
>>>          local: 1
>>> }
>>> root@sbcpub0-stage-lhe0-cn1:/root# getent hosts
>>> dmq-ng.services.domain.com <http://dmq-ng.services.domain.com>
>>> 172.30.154.189 dmq-ng.services.domain.com
>>> <http://dmq-ng.services.domain.com>
>>> 172.17.130.13 dmq-ng.services.domain.com
>>> <http://dmq-ng.services.domain.com>
>>>
>>> root@sbcpub0-stage-lhe0-cn1:/root# grep dmq-ng /etc/kamailio/*
>>> /etc/kamailio/kamailio-module-params.cfg:modparam("dmq",
>>> "notification_address", "sip:dmq-ng.services.domain.com:5090
>>> <http://dmq-ng.services.domain.com:5090>")
>>>
>>> In another case, where the resolving IPs for the DMQ service hostname
>>> were listed as A records in DNS, this worked as expected.
>>> In this case, the second host of the DMQ group is not listed in
>>> dmq.list_nodes, despite its being set in /etc/hosts, as shown by the
>>> getent command.
>>>
>>> Doesn't kamailio use nss for hostname resolution? Am I missing
>>> something else? Thanks!
>>>
>>> BR,
>>> George
>>>
>>>
>>> _______________________________________________
>>> Kamailio (SER) - Users Mailing List
>>> sr-users@lists.kamailio.org
>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>
>> -- 
>> Alex Balashov | Principal | Evariste Systems LLC
>>
>> Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free)
>> Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
>>
>> _______________________________________________
>> Kamailio (SER) - Users Mailing List
>> sr-users@lists.kamailio.org
>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
> --
> Daniel-Constantin Mierla -- www.asipto.com
> www.twitter.com/miconda -- www.linkedin.com/in/miconda
> Funding: https://www.paypal.me/dcmierla
>
--
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Funding: https://www.paypal.me/dcmierla


_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Funding: https://www.paypal.me/dcmierla