Erlang built-in distribution follows a Mesh topology where each node in the cluster are connected to each other. For a node want to join an existing cluster it needs a secret cookie which could be passed to the cookie flag using the erl tool . It's a secret which every node must have to connect to each other or an existing cluster.
Lets create a three node Erlang cluster connect them to each other
Using the erl cli tool we are creating three Erlang nodes called foo, bar, and baz in different terminal instances.
- Create the first node called foo
$ erl -sname foo --cookie foobarbaz
2. Create the second node called bar
$ erl -sname bar --cookie foobarbaz
3. Create the third node called baz
$ erl -sname baz --cookie foobarbaz
Initially, nodes are not connected to each other. If you want check in that case you can execute the function erlang:nodes() which list all the nodes that the node is foo is connected to but in this case it will be empty .
(foo@earth) 1> erlang:nodes(). --> 
Ping the bar@earth and baz@earth from the node foo@earth this will connect the both node to each other.
(foo@earth) 2> net:ping(bar@earth). --> pong
(foo@earth) 3> net:ping(baz@earth). --> pong
(foo@earth) 4> erlang:nodes(). --> [foo@earth, bar@earth]
(bar@earth) 1> erlang:nodes(). --> [foo@earth, baz@earth]