Can Elixir DNS resolve .internal hostnames?

I am able to ssh into a machine running in the app “geo-demo”. I am trying to resolve “geo-db2.internal” which is in the app “geo-db2”. Are there issues connecting across apps?

Resolves OK using ping:

$ ping geo-db2.internal
PING geo-db2.internal(e2860759ae4286.vm.geo-db2.internal (fdaa:0:797a:a7b:4b7:11b9:5b03:2)) 56 data bytes

Does not work in iex:

:inet_res.gethostbyname('geo-db2.internal')
warning: using single-quoted strings to represent charlists is deprecated.
Use ~c"" if you indeed want a charlist or use "" instead.
You may run "mix format --migrate" to change all single-quoted
strings to use the ~c sigil and fix this warning.
└─ iex:1:25

{:error, :nxdomain}

Not sure what’s happening there, but also try dig or nslookup.

Oh, hold up, you’ve posted an Elixir error. I assume this is just a type issue; can you try double quotes, as suggested?

The part about strings is just a warning actually, although given the size disparity it does look at a glance like it’s the main problem.

Elixir has two kinds of strings: normal ones (with double quotes), and backward-compatibility inefficient ones (with single quotes or the ~c sigil).

(The name charlist will give you a hint about where the inefficiency comes from, :dragon:.)

In general, Elixir and Erlang require you to opt-in to IPv6, which is kind of a pain. In this context, that could be done ad hoc as…

:inet_res.gethostbyname('geo-db2.internal', :inet6)
                                            ^^^^^^
1 Like

Adding the :inet6 atom works. However, Ecto / Postgres client is not using it. Is there an option somewhere in the database connection config?

:inet_res.gethostbyname('geo-demo-db.internal', :inet6)
warning: using single-quoted strings to represent charlists is deprecated.
Use ~c"" if you indeed want a charlist or use "" instead.
You may run "mix format --migrate" to change all single-quoted
strings to use the ~c sigil and fix this warning.
└─ iex:2:25

{:ok,
 {:hostent, ~c"geo-demo-db.internal", [], :inet6, 16,
  [{64938, 0, 31098, 2683, 1212, 34122, 15906, 2}]}}

Just to show it doesn’t work without the atom…

:inet_res.gethostbyname('geo-demo-db.internal')
warning: using single-quoted strings to represent charlists is deprecated.
Use ~c"" if you indeed want a charlist or use "" instead.
You may run "mix format --migrate" to change all single-quoted
strings to use the ~c sigil and fix this warning.
└─ iex:4:25

{:error, :nxdomain}

Double quoted strings don’t work. I have no idea why. Definitely not an Elixir selling point.

:inet_res.gethostbyname("geo-demo-db.internal", :inet6)
{:error, :formerr}

The solution for Elixir apps is to set the ECTO_IPV6 environment variable to true.

2 Likes