Pawan
Pawan

Reputation: 17

Connecting two peers on different machines in a private network

I am using geth to create a Private blockchain in my system which is connected to my office network.

I want to add another peer(different PC) to my blockchain network which is connected to the same network.

How can I do that??

Any suggestions on, creating an app which indeed does solve the above requirement.

Upvotes: 0

Views: 2121

Answers (2)

Arshad Sarfarz
Arshad Sarfarz

Reputation: 71

The key change that would be needed is to start geth nodes on those machines using rpc mode

For example start geth node on Machine 1 and Machine 2 using the commands:

  1. Machine 1 : geth --datadir "C:\ethereum\geth\data\01" --networkid 1234 --rpc --rpcport "8545" --rpcaddr "127.198.216.197" --rpccorsdomain "*"
  2. Machine 2 : geth --datadir "C:\ethereum\geth\data\01" --networkid 1234 --rpc --rpcport "8545" --rpcaddr "127.198.216.198" --rpccorsdomain "*"

Now add Machine 2 as a peer to Machine 1 if you want to do it manually or use a Bootnode and start Geth using Bootnode. You can refer to the link if you want to use Boot nodes: https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster

Then you should be able to attach your console using the command: geth attach http://127.198.216.197:8545

One caveat: You need to open respective ports if they are blocked by your office network

Upvotes: 2

Fuzzybear
Fuzzybear

Reputation: 1418

When running the client daemon you can add the 'connect' parameter to specify the IP:Port of the computer you want to try to connect to when starting.

bitcoind --daemon -connect=127.0.0.1:9090

This usually has to be done when the ip's of nodes hard coded into your blockchain codebase have not been updated to the IP's where you have nodes running. Thus peers.dat does not know where to look for a connection to the blockchain.

You can also specify these in the config file with the addnode parameter. e.g.

server=1
rpcport=9090
rpcuser=bitcoinrpc
rpcpassword=3QtnxrB7P5y4EpBdad1MkCeB2RHmArvcarw7udgXsAce

addnode=10.0.0.2:8333

Upvotes: -1

Related Questions