node connections

Sebastian Strollo <>
Wed Apr 21 09:46:38 CEST 2004


Hi Dustin

The shortest answer is: Before trying net_adm:ping() try executing
"inet_db:set_lookup([dns])." on both your nodes. If you want to know
why, read on below. :-)

Dustin Sallings <> writes:

[...]
> 	I got it working between two nodes on the same machine.
> 
> Here's what I've got:
> 
> 	Both systems are Darwin 7.3 (MacOS X 10.3.3).  I grabbed the
> latest erlang/OTP from source.  The machines are on the same subnet
> (I'm on one of them and sshed into the other).


The next place to look then is name resolving, which is in a, well
shall we just say that it can easily cause confusion...

The Erlang system needs to be able to resolve the host names of the
nodes (in your case "dustinti.west.spy.net" and "rubik.west.spy.net")
in order to connect to them. And it doesn't just call gethostbyname(3)
to get these names, instead Erlang has a built in resolver.... More
about that below, but first I'd say that a lot of times the easiest
way to avoid problems with resolving names is to use "short" names and
have them in your /etc/hosts file, here is an example from my machine:

    albatross> erl -sname bar
    Erlang (BEAM) emulator version 5.3.b1 [source]
    Eshell V5.3.b1  (abort with ^G)
    ()1> 

And in another window:

    albatross> uname -a
    FreeBSD albatross.bluetail.com 5.1-RELEASE FreeBSD 5.1-RELEASE #0: Thu Oct  2 13:18:30 CEST 2003     :/usr/src/sys/i386/compile/ALBATROSS  i386
    albatross> erl -sname foo
    Erlang (BEAM) emulator version 5.3.b1 [source]
    Eshell V5.3.b1  (abort with ^G)
    ()1> net_adm:ping().
    pong

Now to the fullname part and the resolver issues... If I try to use on
my machines it actually doesn't work either:

    albatross> erl -name bar
    Erlang (BEAM) emulator version 5.3.b1 [source]
    Eshell V5.3.b1  (abort with ^G)
    ()1> 

And then

    albatross> erl -name foo
    Erlang (BEAM) emulator version 5.3.b1 [source]

    Eshell V5.3.b1  (abort with ^G)
    ()1> net_adm:ping('').
    pang

Hmm, so let's see if Erlang can resolve "albatross.bluetail.com"

   ()2> inet:gethostbyname("albatross.bluetail.com").
   {error,nxdomain}

Nope - that's the problem then (resolving "albatross" works just fine
though, I have that in my /etc/hosts). In my case the reason is
discussed in this thread:

    http://www.erlang.org/ml-archive/erlang-questions/200310/msg00164.html

(Aside: the detail of why it isn't working is that FreeBSD went from
using /etc/host.conf to /etc/nsswitch.conf in version 5.x. In your
case I think it is that darwin doesn't have an entry in the
inet_config.erl at all and so Erlang will only look in the /etc/hosts
file.)

Okay, so how do you fix it? First you can verify that what I'm saying
is actually the problem, by trying inet:gethostbyname/1 and then by
querying Erlang on how it resolves host names:

    ()4> inet_db:res_option(lookup).
    [file]

The return value is a list of how Erlang will resolv names; 'file'
means look in the /etc/hosts file. (And I just fired up my MacOS X
machine, and it is the same there). So let's tell it to use dns
instead:

    ()5> inet_db:set_lookup([dns]).     
    ok

You can also tell it to first use files and then dns, by giving
[files, dns] as arguments to inet_db:set_lookup/1. To verify that the
DNS settings look right:

    ()6> inet_db:get_rc().
    [{domain,"bluetail.com"},
     {nameserver,{127,0,0,1}},
     {search,["bluetail.com",
              "lab.bluetail.com",
              "us.nortel.com"]}]

Which in my case is right (I am running a local name server on my
machine). So let's see if we now can resolve the name now:

   ()7> inet:gethostbyname("albatross.bluetail.com").
   {ok,{hostent,"albatross.bluetail.com",[],inet,4,[{192,168,128,60}]}}

Good, let's fix the other machine too:

    ()1> inet_db:set_lookup([dns]). 
    ok

And now

    ()8> net_adm:ping('').
    pong

Voila. :-)

In the above mentioned erlang-list archive thread I recall that Raimo
(from the OTP group at Ericsson) said they were working on (or wanted
to work on:-) the Erlang resolver - exactly because of these
problems... :-) Oh, and reading that thread again I see that Raimo
actually suggests using inet_db:set_lookup([native]) - which seems to
work fine on both my FreeBSD and my MacOS X machines.

Cheers,

/Sebastian

PS. You can e.g. add the inet_db:set_lookup/1 call to your ".erlang"
file (which is read at startup).



More information about the erlang-questions mailing list