Let’s see how we can connect multiple nodes on the same machine:

$ iex --sname foo
iex(foo@yosriady)> Node.list
$ iex --sname bar
iex(bar@yosriady)> Node.list

We have two nodes, both unaware of each other. Let’s connect them:

iex(foo@yosriady)> Node.ping :"bar@yosriady"
:pong # returns :pang if ping failed
iex(foo@yosriady)> Node.list
iex(bar@yosriady)> Node.list

Both nodes are now aware of each other!

Now let’s see how we can connect multiple nodes on different machines over the network. You’ll need to get the two machines’ IP addresses via ifconfig:

$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
	inet6 ::1 prefixlen 128
	inet netmask 0xff000000
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
	nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
	ether 34:36:3b:d4:fc:dc
	inet6 fe80::3636:3bff:fed4:fcdc%en0 prefixlen 64 scopeid 0x4
	inet netmask 0xfffffe00 broadcast
	nd6 options=1<PERFORMNUD>
	media: autoselect
	status: active

From the above, my IP address is My other machine has IP

$ iex --name foo@ --cookie chocolate
iex(foo@> Node.ping :"bar@"
iex(foo@> Node.list
$ iex --name bar@ --cookie chocolate
iex(bar@> Node.list