[erlang-questions] detection of hostname

Vlad Dumitrescu <>
Wed Oct 24 10:58:14 CEST 2012


Thank you Raimo for the explanation!

My problem is that people will fiddle with the settings when getting
started with Erlang programming, until it works. But when starting
Eclipse, we have to be able to handle many different cases of
misconfiguration (legitimate or not), with no good way to let the user
configure anyhting. Hopefully, it is fixed now, in the latest erlide
nightly builds. Fortunately, this won't be a problem anymore in the
near future.

I am considering writing (and publishing) a script that would detect
what kind of Erlang communication is possible on a certain machine.
The script could say "Sorry buddy, you can't use long names on this
machine at all" or "Please add 'foo' to /etc/hosts to let short names
work". Whenever people discover some new edge case on their machines,
they can update the script. Maybe it would be useful to distribute
with OTP?

best regards,
Vlad

On Wed, Oct 24, 2012 at 9:21 AM, Raimo Niskanen
<> wrote:
> On Tue, Oct 23, 2012 at 08:32:57AM +0200, Vlad Dumitrescu wrote:
>> Thank you all for the advice! I will use some of it to improve the detection.
>>
>> I would still want to know how is it possible to run "erl -name foo"
>> and "erl -name bar" and these nodes can connect to each other all
>> right (the hostname erlang assigns being "desktop.domain.com"), but on
>> the same machine "ping desktop.domain.com" can't resolve the name...
>
> This problem of yours is a mess, and there is no simple answer.
>
> The hostname is a property of the operating system. On Unixes it can
> be retreived with the gethostname(2) syscall. That is what
> inet:gethostname/0 does, also removing the domain name
> if it is contained in the hostname. On BSD it is customary to
> configure the fully qualified domain name as the hostname,
> but not necessary. Therefore inet:gethostname/0 returns the
> short hostname as it is more portable.
>
> When a node starts it reads the hostname and uses it as a
> base for the node name if neded. If the hostname contains
> a domain name that is used as the domain name for the node,
> if needed. If the node starts distributed with long names
> some system configuration files (e.g. /etc/resolv.conf)
> are parsed to try to find a domain name. On Unix, if the
> domain name still is unknown, the short hostname is looked up
> using the native lookup method (per default) to try to find
> the domain name.
>
> The process is also customizable through the inetrc file and
> some environment variables. It is all in inet_config:init/0,
> if the documentation (ERTS User's Guide, Inet configuration)
> is not enough.
>
> Erlang tries to do it's best to find the hostname and domain name,
> but there are so many ways to misconfigure a system, some perfectly
> valid. For instance the FQDN the machine thinks it has may be invalid
> from the Internet because company policy want to hide network topology
> and individual machines.
>
> So, the short hostname returned by inet:gethostname() is the best guess.
> The domain name returned by inet_db:res_option(domain) is the best
> that can be guessed without knowing which interface and which IP address
> that is supposed to be external. The default name lookup method (native)
> is the one most likely to work since it is the same as the OS uses
> and the one the system administrator has configured and is responsible for.
>
>>
>> The conclusion I draw is that the only way to know is to start a node
>> and try to connect to it.
>>
>> best regards,
>> Vlad
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>
> --
>
> / Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list