[erlang-questions] reliably figure out hostname

JD Bothma jbothma@REDACTED
Thu Aug 2 22:21:07 CEST 2012


I like insurmountable problems :)

So I know you have various different environments and setups, but I
still think if it's actually set up in a decent way on each machine,
it should work. At the end of the day if you want things to guess
correctly you need to be sure they're really set up correctly - you
didn't say how you checked so you might have it really correct
already.

For us it was that ubuntu didn't give useful FQDNs unless we set it
properly according to
http://www.leonardoborda.com/blog/127-0-1-1-ubuntu-debian/

The bits to take from it are:
"some applications like GNOME expects that the hostname to be resolved
to an ip address with a canonical fully qualified domain name"
(context is that ubuntu uses a hack with FQDN pointing to 127.0.1.1 in
/etc/hosts)

and

"In order to support that software, it is necessary to ensure that the
system hostname can be resolved. Most often this is done by putting a
line in /etc/hosts containing some IP address and the system hostname.
If your system has a permanent IP address then use that; otherwise use
the address 127.0.1.1."

and a bit more help

"To see whether your system hostname can be resolved to an IP address
with a fully qualified domain name, use the hostname –fqdn command.

Also it could be any ip address in the 127.0.0.1/8 address block since
according to the RFC 1700 , 127.0.0.0/8 addresses are reserved for
loopback purposes."

I think this made things work properly when looking up the domain name
for tests that depended on automatically knowing the FQDN of the
machine as suggested by others in the thread, but I might be totally
on the wrong track :)

{ok, Hostname} = inet:gethostname(),
    {ok,{hostent,FullHostname,[],inet,_,[_]}} = inet:gethostbyname(Hostname),

What the article about ubuntu suggests I think is that localhost can
still be 127.0.0.1 and you can have dynamic ips and whatever while the
machine has a hardcoded FQDN that it should call itself (e.g. when
sending a message that need's a hostname for return path). If you want
a machine to automatically pick up the hostname pointing to it (a la
hostname.local), I think that's tricky feature of your DHCP or name
server or something, and then the machines have to play along.

Hope that helps !

JD

On 2 August 2012 18:58, Tim Watson <watson.timothy@REDACTED> wrote:
> On 2 August 2012 17:42, JD Bothma <jbothma@REDACTED> wrote:
>> I remember having to add something to the hosts file of a recent
>> ubuntu release before erlang would find out its own hostname properly.
>> Not sure if that's related. I'll see if I can dig up more info.
>>
>
> Thanks, I appreciate that.
>
>> Does a machine necessarily have a FQDN? Is this necessarily exactly
>> one? Perhaps you'll have to work out what erlang does to get some
>> hostname and then set the appropriate setting (once) on each relevant
>> machine to make sure it gets what you expect it to.
>>
>
> Well, the issue is that the testing framework knows nothing about this
> issue, but at the moment it does 2 things:
>
> 1. on startup, it uses net_kernel:start/1 to become a distributed erlang node
> 2. when (optionally) connecting to remote nodes (i.e., test subjects)
> it uses net_kernel:hidden_connect_node/1
>
> This all works fine for long and short names, as long as the machine
> configuration is correct, but there's another catch. When you specify
> the test nodes you're going to start, you can optionally provide them
> as [{localhost, [node1, node2]}] etc. In *this* case, localhost must
> be converted to the correct machine name, and as I said that works
> *fine* for shortnames, but for longnames it appears to depend on the
> configuration of the machine.
>
> Perhaps as Vlad suggested, this is an insurmountable problem because
> of the varying configurations that could exist in different
> environments.



More information about the erlang-questions mailing list