Search code examples
erlangerlang-otp

Node naming problems


There are two machines: M1 with two ip addresses 192.168.5.47, 192.168.1.250. And M2 with ip 192.168.5.250.

I launch an erlang node on M1:

nik@nik-PC:~/erlsrc/test_mk$ erl -name 'test@127.0.0.1' -setcookie cook
Erlang/OTP 22 [erts-10.6.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V10.6.2  (abort with ^G)
(test@127.0.0.1)1> 

Then, I'm making another node on M2 and try to ping M1:

nik2@nik2-PC:~$ erl -name 'test2@127.0.0.1' -setcookie cook
Erlang/OTP 22 [erts-10.6.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V10.6.2  (abort with ^G)
(test2@127.0.0.1)1> 
(test2@127.0.0.1)1> net_adm:ping('test@192.168.5.47').
pang
(test2@127.0.0.1)2> 

How to make a communication between nodes on remote machines if one of them has several ip addresses and launched as 'name@localhost' or 'name@127.0.0.1'? Or it's better to use domain names?


Solution

  • If nodes is running in one LAN Network but one different computers, you can try detect your IP on each of computer, eg run:

    $ hostname -I
    

    Let's pretend that machine 1 has IP 192.168.5.47 and machine 2 has IP 192.168.5.250. Now you ou need run node on machine 1 with flag name what include the IP - machine #1:

    $ erl -name 'test@192.168.5.47' -setcookie cook
    

    Now do the same in machine 2, but use IP of machine 2 - machine #2:

    $ erl -name 'test@192.168.5.250' -setcookie cook
    

    Now you can try send ping from test@192.168.5.47 to test@192.168.5.250 - machine #1:

    (test@192.168.5.47)1> net_adm:ping('test@192.168.5.250').
    pong