Can not resolve IP from the DNS provider of my choice

Hello,

I’m trying to create a service to watch DNS record changes through multiple DNS providers like Google, CF, Q9, etc. I needed a function/module to query my resolver of choice for this. I stumbled onto :inet_res.resolve/4 but I’m having difficulties providing it the :nameservers option.

When I do, :inet_res.resolve(~c"google.com", :in, :a, []) or :inet_res.resolve(~c"google.com", :in, :a, [{:verbose, true}]) it works. But whenever I try to pass,

opts = [
  {:nameservers, nameservers},
  {:verbose, true}
]

I get the following error:

** (ArgumentError) argument error
    (kernel 10.0) inet_res.erl:557: :inet_res.make_options([nameservers: [{1, 1, 1, 1}], verbose: true], [:nameservers, :nxdomain_reply, :recurse, :retry, :servfail_retry_timeout, :timeout, :udp_payload_size, :usevc, :verbose])
    (kernel 10.0) inet_res.erl:565: :inet_res.make_options/2
    (kernel 10.0) inet_res.erl:555: :inet_res.make_options/2
    (kernel 10.0) inet_res.erl:539: :inet_res.make_options/1
    (kernel 10.0) inet_res.erl:940: :inet_res.make_query/4
    (kernel 10.0) inet_res.erl:916: :inet_res.res_query/5
    (kernel 10.0) inet_res.erl:346: :inet_res.resolve/5
    #cell:xnk2qwn5ih4huzqe:8: (file)

Here is the code snippet that I’m playing with:

nameservers = [{1, 1, 1, 1}] # 1.1.1.1 is Cloudflare's DNS

opts = [
  {:nameservers, nameservers},
  {:verbose, true}
]

:inet_res.resolve(~c"google.com", :in, :a, opts, 5000)

Elixir Version info:

iex --version
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

IEx 1.17.2 (compiled with Erlang/OTP 27)

Any clues as to why this is not working? Thanks!

If you look at the nameserver type, you will see that it is:

-type nameserver() :: {inet:ip_address(), Port :: 1..65535}.

So you will have to define your opts accordingly:

# This assumes cloudflare nameserver receives requests on port 853
opts = [
  nameservers: [{{1, 1, 1, 1}, 853}],
  verbose: true
]
3 Likes

Thanks a lot, @D4no0. It fixed the issue.