<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>For the records, I added a modparam to corex module which allows
      adding A/AAAA records in the internal dns cache at startup. It
      could be useful in this case as alternative for /etc/hostname
      entries, but also at least for some testing scenarios to avoid
      updating records on dns server, which may take time to propagate.</p>
    <p>  * <a
href="https://www.kamailio.org/docs/modules/devel/modules/corex.html#corex.p.dns_cache">https://www.kamailio.org/docs/modules/devel/modules/corex.html#corex.p.dns_cache</a></p>
    <p>During runtime, there are rpc commands to add/remove records in
      the dns cache.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 20.05.20 20:56, Daniel-Constantin
      Mierla wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:8d4b76a6-190d-deaa-8ff5-8945d7afb5ee@gmail.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p>Hello,</p>
      <p>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.<br>
      </p>
      <p>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.</p>
      <p>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:</p>
      <p>kamctl rpc dns.add_a domain ttl ipaddr flags</p>
      <p>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.<br>
      </p>
      <p>Actually I am now thinking to add the possibility to add to dns
        cache via modparam of ipops module, to make it easier overall.</p>
      <p>Cheers,<br>
        Daniel<br>
      </p>
      <div class="moz-cite-prefix">On 20.05.20 19:35, George
        Diamantopoulos wrote:<br>
      </div>
      <blockquote type="cite"
cite="mid:CAPcKEYMmrLxoLvS1_hw_kKXFA7JGt5ohEk9_Pf5z5it94e0Mxg@mail.gmail.com">
        <meta http-equiv="content-type" content="text/html;
          charset=UTF-8">
        <div dir="ltr">
          <div>Hello all,</div>
          <div><br>
          </div>
          <div>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>
          </div>
          <div><br>
          </div>
          <div>BR.</div>
          <div>George<br>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Tue, 19 May 2020 at
              19:44, Daniel-Constantin Mierla <<a
                href="mailto:miconda@gmail.com" moz-do-not-send="true">miconda@gmail.com</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">A quick follow up as I
              found quite interesting that nowadays *BSDs allow<br>
              specifying order of lookup in resolv.conf to include the
              hosts file, but<br>
              that doesn't seem to be in Linux:<br>
              <br>
                * <a
                href="https://man.openbsd.org/resolv.conf.5#lookup"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://man.openbsd.org/resolv.conf.5#lookup</a><br>
              <br>
              Cheers,<br>
              Daniel<br>
              <br>
              <br>
              On 19.05.20 17:48, Daniel-Constantin Mierla wrote:<br>
              > Hello,<br>
              ><br>
              > worth to clarify that Kamailio doesn't implement a
              dns resolver from<br>
              > scratch, it still uses the functions from libc. It
              only does caching and<br>
              > try to use cashing records first.<br>
              ><br>
              > By default, the following dns functions are used
              internally when the<br>
              > cache doesn't have the record already -- they are set
              in the dns_func<br>
              > structure:<br>
              ><br>
              > struct dns_func_t dns_func = {<br>
              >     res_init,<br>
              >     res_search,<br>
              >     gethostbyname,<br>
              > #ifdef HAVE_GETHOSTBYNAME2<br>
              >     gethostbyname2<br>
              > #else<br>
              >     NULL<br>
              > #endif<br>
              > };<br>
              ><br>
              > So practically by leveraging res_init()/res_search()
              is relying on<br>
              > /etc/resolv.conf to do DNS queries, which is not
              using the /etc/hosts<br>
              > (iirc). For more see:<br>
              ><br>
              >   * <a href="https://linux.die.net/man/3/res_search"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://linux.die.net/man/3/res_search</a><br>
              ><br>
              > Cheers,<br>
              > Daniel<br>
              ><br>
              > On 19.05.20 17:23, Alex Balashov wrote:<br>
              >> You are correct that Kamailio does not use the
              libc resolver /<br>
              >> libresolv, but rather its own resolver, which
              ignores /etc/hosts.<br>
              >><br>
              >> -- Alex<br>
              >><br>
              >> On 5/19/20 10:42 AM, George Diamantopoulos wrote:<br>
              >>> Hello all,<br>
              >>><br>
              >>> I've come across this today when trying to
              setup DMQ replication:<br>
              >>><br>
              >>> root@sbcpub0-stage-lhe0-cn1:/root# systemctl
              restart kamailio<br>
              >>> root@sbcpub0-stage-lhe0-cn1:/root# kamcmd
              dmq.list_nodes<br>
              >>> {<br>
              >>>          host: 172.30.154.189<br>
              >>>          port: 5090<br>
              >>>          resolved_ip: 172.30.154.189<br>
              >>>          status: active<br>
              >>>          last_notification: 0<br>
              >>>          local: 1<br>
              >>> }<br>
              >>> root@sbcpub0-stage-lhe0-cn1:/root# getent
              hosts<br>
              >>> <a href="http://dmq-ng.services.domain.com"
                rel="noreferrer" target="_blank" moz-do-not-send="true">dmq-ng.services.domain.com</a>
              <<a href="http://dmq-ng.services.domain.com"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://dmq-ng.services.domain.com</a>><br>
              >>> 172.30.154.189 <a
                href="http://dmq-ng.services.domain.com"
                rel="noreferrer" target="_blank" moz-do-not-send="true">dmq-ng.services.domain.com</a><br>
              >>> <<a
                href="http://dmq-ng.services.domain.com"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://dmq-ng.services.domain.com</a>><br>
              >>> 172.17.130.13 <a
                href="http://dmq-ng.services.domain.com"
                rel="noreferrer" target="_blank" moz-do-not-send="true">dmq-ng.services.domain.com</a><br>
              >>> <<a
                href="http://dmq-ng.services.domain.com"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://dmq-ng.services.domain.com</a>><br>
              >>><br>
              >>> root@sbcpub0-stage-lhe0-cn1:/root# grep
              dmq-ng /etc/kamailio/*<br>
              >>>
              /etc/kamailio/kamailio-module-params.cfg:modparam("dmq",<br>
              >>> "notification_address", "sip:<a
                href="http://dmq-ng.services.domain.com:5090"
                rel="noreferrer" target="_blank" moz-do-not-send="true">dmq-ng.services.domain.com:5090</a><br>
              >>> <<a
                href="http://dmq-ng.services.domain.com:5090"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://dmq-ng.services.domain.com:5090</a>>")<br>
              >>><br>
              >>> In another case, where the resolving IPs for
              the DMQ service hostname<br>
              >>> were listed as A records in DNS, this worked
              as expected.<br>
              >>> In this case, the second host of the DMQ
              group is not listed in<br>
              >>> dmq.list_nodes, despite its being set in
              /etc/hosts, as shown by the<br>
              >>> getent command.<br>
              >>><br>
              >>> Doesn't kamailio use nss for hostname
              resolution? Am I missing<br>
              >>> something else? Thanks!<br>
              >>><br>
              >>> BR,<br>
              >>> George<br>
              >>><br>
              >>><br>
              >>>
              _______________________________________________<br>
              >>> Kamailio (SER) - Users Mailing List<br>
              >>> <a href="mailto:sr-users@lists.kamailio.org"
                target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a><br>
              >>> <a
                href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
              >>><br>
              >> -- <br>
              >> Alex Balashov | Principal | Evariste Systems LLC<br>
              >><br>
              >> Tel: +1-706-510-6800 / +1-800-250-5920
              (toll-free)<br>
              >> Web: <a href="http://www.evaristesys.com/"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://www.evaristesys.com/</a>,
              <a href="http://www.csrpswitch.com/" rel="noreferrer"
                target="_blank" moz-do-not-send="true">http://www.csrpswitch.com/</a><br>
              >><br>
              >> _______________________________________________<br>
              >> Kamailio (SER) - Users Mailing List<br>
              >> <a href="mailto:sr-users@lists.kamailio.org"
                target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a><br>
              >> <a
                href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
              > -- <br>
              > Daniel-Constantin Mierla -- <a
                href="http://www.asipto.com" rel="noreferrer"
                target="_blank" moz-do-not-send="true">www.asipto.com</a><br>
              > <a href="http://www.twitter.com/miconda"
                rel="noreferrer" target="_blank" moz-do-not-send="true">www.twitter.com/miconda</a>
              -- <a href="http://www.linkedin.com/in/miconda"
                rel="noreferrer" target="_blank" moz-do-not-send="true">www.linkedin.com/in/miconda</a><br>
              > Funding: <a href="https://www.paypal.me/dcmierla"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://www.paypal.me/dcmierla</a><br>
              ><br>
              -- <br>
              Daniel-Constantin Mierla -- <a
                href="http://www.asipto.com" rel="noreferrer"
                target="_blank" moz-do-not-send="true">www.asipto.com</a><br>
              <a href="http://www.twitter.com/miconda" rel="noreferrer"
                target="_blank" moz-do-not-send="true">www.twitter.com/miconda</a>
              -- <a href="http://www.linkedin.com/in/miconda"
                rel="noreferrer" target="_blank" moz-do-not-send="true">www.linkedin.com/in/miconda</a><br>
              Funding: <a href="https://www.paypal.me/dcmierla"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://www.paypal.me/dcmierla</a><br>
              <br>
              <br>
              _______________________________________________<br>
              Kamailio (SER) - Users Mailing List<br>
              <a href="mailto:sr-users@lists.kamailio.org"
                target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a><br>
              <a
                href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
            </blockquote>
          </div>
        </div>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <pre class="moz-quote-pre" wrap="">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" moz-do-not-send="true">sr-users@lists.kamailio.org</a>
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
      </blockquote>
      <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com" moz-do-not-send="true">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" moz-do-not-send="true">www.linkedin.com/in/miconda</a>
Funding: <a class="moz-txt-link-freetext" href="https://www.paypal.me/dcmierla" moz-do-not-send="true">https://www.paypal.me/dcmierla</a></pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Funding: <a class="moz-txt-link-freetext" href="https://www.paypal.me/dcmierla">https://www.paypal.me/dcmierla</a></pre>
  </body>
</html>