[Ethereum] How to connect two peers on different machines in a private network

go-ethereumpeersprivate-blockchain

Just to preface this, I'm a little new to networking and Ethereum in general, but after looking through some tutorials, I decided that I would like to create a private network/blockchain for my own use and smart contracts. But while I can connect 2 peer nodes on the same machine, I have difficulty connecting 2 peer nodes on different machines.

METHOD 1: The below is one way I've tried this (which works for 2 peers on the same machine; one tutorial I saw had the last 3 flags missing but I decided to include them anyway)

geth –datadir /path/to/genesis –networkid 111 –maxpeers 2 –rpc –rpccorsdomain "*" –nodiscover –ipcdisable –rpcport 30001 –port 8081 console //machine 1

geth –datadir /different/path/to/genesis –networkid 111 –maxpeers 2 –rpc –rpccorsdomain "*" –nodiscover –ipcdisable –rpcport 30002 –port 8082 console //machine 2

And then on machine 1 obtain admin.nodeInfo.enode (which is"enode://d677…b4c5@[::]:8081?discport=0"), and enter on machine 2 admin.addPeer("enode://d677…b4c5@my.ip.address?discport=0).

This returns true but admin.peers remains empty.

METHOD 2: Another way is to do the same thing for machine 1, but instead on machine 2 type:

geth –datadir /different/path/to/genesis –networkid 111 –maxpeers 2 –rpc –rpccorsdomain "*" –nodiscover –ipcdisable –rpcport 30002 –port 8082 –bootnodes enode://d677…b4c5@my.ip.address?discport=0 console

And then do the same admin.addPeer process. Same results happen, however.

I'm really torn as to what is the problem here. The genesis blocks are the same (hashes are the same), and I've tried various types of flags after initializing on both machines. I suppose my hunch is that my clocks are not synced on both machines (although I'm not sure how to do so other than sudo timedatectl set-ntp on), or that I'm not entering the right IP address (although I've tried almost all of them), so maybe some direction in these areas would be nice.

I've tried having –verbosity 6 also, and the error returned is 'discovery is disabled' and 'dial tcp my.ip.address:8081: getsockopt: connection refused'. Which is strange since I had no problem doing this using the same machines, but when I did the same thing without –nodiscover it still didn't work: errors were 'dial tcp my.ip.addresss:8081: i/o timeout' and 'no discv4 seed nodes found' and 'resolving node failed'.

I'm really sorry if this is really long-winded but it's just I'm really unsure of what's the real problem and I've been just iterating through much of these changes that I'm sure about. To make matters worse I think Ethereum and geth are constantly updating so I'm not sure if the information I'm seeing on this site and elsewhere are relevant or accurate. I'd really, really appreciate some help here because I'm really desperate for some help and clarification.

Best Answer

1) Just confirm whether both genesis are the same...(use eth.getBlock(0) on both nodes)

2) Try and use admin.addPeer("enode....@IP of the other node:Port") in your console.

You can check the port using admin.nodeInfo

admin.addPeer("enode://93a29e6d51e58c8a313a295fc3b246b59cd2c8c4f9aa833ac351584882f7c23ac24f38ebc76213a23f8c84aeb8a2e7d46a504a3110775ad12f36b1fe1938cbad@YOUR_IP_2:30303")

3) Check peers using net.peerCount

Related Topic