3

Connecting 2 nodes on different machines on different network from terminal in ethereum.

I have 3 nodes running on my ubuntu machine say A, i have preallocated them with some amount and they can transfer that amount within each other using node addresses.

I want to transfer / communicate from another machine say B which is also running 3 nodes on it. how can nodes on machine A connect to nodes on machine B. I want to setup a private network between A and B without connecting to the main blockchain so as A and B start communicating with each other,

On first node i am running this:

geth --genesis /home/cgen.json --datadir '/home/jedi/Desktop/node1' --networkid 12588 --port 30305 --verbosity 0 console

and on 2nd terminal:

geth --genesis /home/customgen.json --datadir '/home/jedi/Desktop/node1' --networkid 12345 --nodiscover --port 30311 --verbosity 0 console --bootnodes "enode://5675641adc6106447d9741c48ce382aca7becddd6da99881e8c98ef26f73bf4a63252fb‌​e5ec29ddec6960cb78c7d69d39c181c6ca83e38d39670be6742f76d94@1.39.47.145:30311" 

Not sure of which geth version.

  • You are using network ids 12588 and 12345, make sure they match. – Waqar Lim Jun 21 '16 at 10:36
  • tried that aswell still my net.peercount is 0 after it runs – jassu Jun 21 '16 at 11:08
  • Are you using the same genesis file? The names in your commands are different. If these nodes are on the same machine, their datadirs cannot be the same. Check this for more details. – galahad Jun 21 '16 at 12:53
  • @varm these are on separate machines i have kept network id same – jassu Jun 21 '16 at 13:18
  • @5chdn when i run the command on 2 machine to connect with the machine 1 it runs shows no error but geth console is not open and simultaneusly if i check the peer count on machine 1 it comes 1 just for fractions of second and then returns to 0 – jassu Jun 21 '16 at 13:20
2

Generate some random ID, e.g. using random dot org, let's use 88259. On the first machine your run the client like that (note I also changed the network port and datadir to avoid conflicts with the main network):

geth --datadir "/home/user/.eth-private" --port 30259 --networkid 88259

This will run a new instance of a private ethereum network on your first machine.

I0621 10:19:02.655014 ethdb/database.go:82] Alloted 128MB cache and 1024 file handles to /home/user/.eth-private/chaindata
I0621 10:19:02.827145 ethdb/database.go:169] closed db:/home/user/.eth-private/chaindata
I0621 10:19:02.827243 cmd/utils/flags.go:601] WARNING: No etherbase set and no accounts found as default
I0621 10:19:02.827886 ethdb/database.go:82] Alloted 128MB cache and 1024 file handles to /home/user/.eth-private/chaindata
I0621 10:19:02.840042 ethdb/database.go:82] Alloted 16MB cache and 16 file handles to /home/user/.eth-private/dapp
I0621 10:19:02.841749 eth/backend.go:172] Protocol Versions: [63 62 61], Network Id: 88259
I0621 10:19:02.841907 eth/backend.go:201] Blockchain DB Version: 3
I0621 10:19:02.842241 core/blockchain.go:206] Last header: #0 [d4e56740…] TD=17179869184
I0621 10:19:02.842260 core/blockchain.go:207] Last block: #0 [d4e56740…] TD=17179869184
I0621 10:19:02.842271 core/blockchain.go:208] Fast block: #0 [d4e56740…] TD=17179869184
I0621 10:19:02.842952 p2p/server.go:313] Starting Server
I0621 10:19:04.844709 p2p/discover/udp.go:217] Listening, enode://6179e58bb512415a76e4169dd25ae5a171e34069660b233cf79dabd3581d8dd1221a7f3a5e5d64251aa7e8ac20eda5430e42eed161e68cb05d05e6c3cab68a6e@[::]:30259
I0621 10:19:04.845128 p2p/server.go:556] Listening on [::]:30259
I0621 10:19:04.848679 node/node.go:296] IPC endpoint opened: /home/user/.eth-private/geth.ipc

Now, you extract the enode uri from the first node and replace the IP with the ID of your local area network (LAN, or use the public IP if the nodes are distributed), like that:

enode://6179e58bb512415a76e4169dd25ae5a171e34069660b233cf79dabd3581d8dd1221a7f3a5e5d64251aa7e8ac20eda5430e42eed161e68cb05d05e6c3cab68a6e@192.168.1.159:30259

Now, you can pass this node as boot node to the 2nd and 3rd node, like that:

geth --datadir "/home/user/.eth-private" --port 30259 --networkid 88259 --bootnodes "enode://6179e58bb512415a76e4169dd25ae5a171e34069660b233cf79dabd3581d8dd1221a7f3a5e5d64251aa7e8ac20eda5430e42eed161e68cb05d05e6c3cab68a6e@192.168.1.159:30259"

Note the network ID has to be the same on all clients. It will try to connect to your first node.

If you have multiple nodes running, you can also add more nodes to the bootnodes parameter, just separate them by comma.

  • while running on 2 geth console getting error flag provided but not defined : - bootnodes – jassu Jun 21 '16 at 9:04
  • Please, add some more details to your question: which geth version, what is your exact command line, etc. pp. – Waqar Lim Jun 21 '16 at 9:06
2

To make the node peers, you need three parameters same on both node :

  • Nonce
  • Network Id
  • Genesis File

After that use the enode value provided by running the command admin.nodeInfo .At the place of {::} put the IP of other machine.Hope it will resolve your issue.

  • Please read my comments above let me know if any changes are to be made – jassu Jun 21 '16 at 13:29
  • Try it with using 12345 as network id at both end – Aniket Jun 21 '16 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.