Search code examples
blockchaingo-ethereumgeth

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.


Solution

  • 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