Connecting erlang nodes
Tuesday, 17th May, 2011
In order to connect to each other, erlang nodes each need a name, they need to share a secret cookie, and if they’re to communicate over the internet, they need access to ports.
The secret cookie can be either set at runtime (as in the examples below), or in each user’s .erlang.cookie file.
For local connection
On the same machine or subnet, each node just needs a short name:
$ erl -sname chico -setcookie marx ... (chico@localhost)1>
For internet connection
Each node must have the following ports available:
- port 4369, used by epmd (the Erlang Port Mapper Daemon, not Erick and Parrish Making Dollars), must be open for both TCP and UDP (n.b.: this is a default).
- another port or range of ports for the erlang nodes themselves. These nodes can be set at run time using the -kernel, inet_dist_listen_min and inet_dist_listen_max flags.
Each node must also use a full name, with either a domain or an IP address:
$ erl -name firstname.lastname@example.org -setcookie longrandomstring -kernel inet_dist_listen_min 9000 inet_dist_listen_max 9005 (email@example.com)1>
Erlang nodes are gregarious: as soon as nodes find out about each other, they connect. An easy way to say hello is "ping":
(chico@localhost)1> nodes().  (chico@localhost)2> net_adm:ping(groucho@localhost). pong (chico@localhost)3> nodes(). [groucho@localhost] (chico@localhost)4> ^g User switch command --> r groucho@localhost --> c Eshell V5.7.2 (abort with ^G) (groucho@localhost)1>
You can skip the connection palaver by using the -remsh flag at startup:
$ erl -sname chico -setcookie marx -remsh groucho@localhost ... (groucho@localhost)1>
Introspection GUIs like AppMon and Pman can access any connected node (see the Nodes menu in the toolbar).