I am new to Ethereum and tried everything to connect testnet from two local machine nodes.i tried with running two consoles in single machine by admin.addPeers(nodeUrl) and could connect. when i tried with the same for different machines using same network id it is showing peer count as zero. please help to solve this. thanks in advance

6 Answers 6


Since you're running two nodes on two different machines, you need to mention the IP address of the node while connecting through addPeer(enodeURI).

Detailed walkthrough:

  • You need to have the same genesis file in every machine you wish to start a node.

  • All the nodes should have the same --networkid

  • The --rpcport and --port should be different for every geth instance.

  • If working on the same machine, each geth instance should have different --datadir.

Starting geth instances:

Node 1:

geth --genesis path/to/genesis.json --datadir path/to/directory --networkid 1234 --port 30301 --rpcport 8101 console

Node 2:

geth --genesis path/to/genesis.json --datadir path/to/directory --networkid 1234 --port 30302 --rpcport 8102 console

You might add commands like --maxpeers and --nodiscover if you wish.

After starting these instances, check for a similar message on the console:

I0829 13:30:07.347738   3987 backend.go:303] Successfully wrote genesis block. New genesis hash = 82b6159155c00fb0b420046012a02257a176ad5dcfce4be4a15da39c166518e2

If this is the case, you successfully started the nodes with a private blockchain. If you see a message similar to Warning: Wrote default ethereum genesis block, then there's something wrong.

Connecting nodes:

Node 1: (on the JavaScript console)


The output will be something like:


Observe that the port number in the end of URI is 30301.

Node 2:

Execute the same command on Node 2 and you'll get a similar output with 30302 in the end:


To connect these nodes, find out the IP address of Node 2. Since this is a local network, each machine should have a unique private IP address. While using the addPeer(enodeURI) function, the [::] in the enodeURI should be replaced with the IP address of the machine on which the node is running. Now, on Node 1:


After this command returns true, the net.peerCount should return 1 and admin.peers should return the details of the node which is added/connected. Before connecting, check if net.listening returns true on both nodes.


Setting up private network or local cluster

Connecting to the network

How To Create A Private Ethereum Chain

  • --genesis is no longer valid Commented Aug 5, 2017 at 3:55
  • @galahad, thank you for detailed answer. I know this is last year's answer and things have changed. Still I am asking you about the third step i.e. addPeer. Do we have to mention the ip the machine if we are trying to run on same machine? And does both nodes have to mine even if they are same network? Commented Oct 7, 2017 at 16:32

Roland's answer is good but you should keep in mind that geth (and all ethereum as of yet) bind to the same default ports meaning that you have to change them from their defaults when running multiple instances on the same host (i.e.

It's pretty easy to just increment the default ports for each instance and then create a (bash) script to run them independently (as background processes).

If you want more independence between the geth instances consider creating a separate data directory for each (modify the --datadir command line argument from the other answer):

--datadir "~/privethnet/geth_client"
--datadir "~/privethnet/geth_bootstrap"
  • bud he said two machines... Commented Jul 12, 2016 at 15:43
  • Two local machines can also refer to virtual hosts. Perhaps he can clarify?
    – Sebi
    Commented Jul 12, 2016 at 15:53
  • Thanks guys.. two local machines means two laptops lets say.. Commented Jul 13, 2016 at 14:53

An example setup for a private network

Create a file named genesis.json with following content:

    "nonce": "0xdeadbeefdeadbeef",
    "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x0",
    "gasLimit": "0x8000000",
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",
    "alloc": {

Run the following: geth --datadir ./ init genesis.json

geth --identity "nodeA" --rpc --rpcport "8000" --rpccorsdomain "*" --datadir "~/privethnet/" --port "30303" --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3" --autodag --networkid 1900 --nat "any" console

geth --identity "nodeB" --rpc --rpcport "8000" --rpccorsdomain "*" --datadir "~/privethnet/" --port "30303" --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3" --autodag --networkid 1900 --nat "any" console

Add the peer using the peer’s URL:
Find the peernode form the geth startup log 0712 13:34:00.865021 p2p/discover/udp.go:217] Listening, enode:...


Check if peer node was added: admin.peers

Examples of nodeURLS are: Node A nodeURL:


Node B nodeURL:

  • Thank you .. i had tried this and i could get the peer count as well.. but when i do transaction and mining that will not get transferred.. lets say i have two accounts in first machine and i transfered money from acc1 to acc2 in first machine and run mining from second machine it will not get transfered .. i am not getting what is the mistake .. Commented Jul 13, 2016 at 15:04

A user on Github named FleetingCloud has put together a nice command-style UI script for setting up Ethereum on a private network. I highly recommend it.



After cloning the repo, just run the initializeEthereumPrivateNetwork.sh script. It will then ask you what you would like to name your network, the directories of the geth on root and client nodes, etc.

  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – q9f
    Commented Aug 26, 2016 at 12:55

--genesis is no longer valid. Need to use init instead. Here is my code I replaced with step 1:

geth --identity "MyTestNode" --nodiscover --networkid 1999 --port 30301 -- rpcport 8101 --datadir /home/appo/geth/  init /home/appo/.json console

You can set whatever flags and ports you want, this is just the code I ran on my machine.


Here's some more up to date scripts on connecting both execution clients and consensus clients in a local setup.


It includes the bootnode discovery for both clients, and allows you to configure how many clients you want to run locally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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