Posted by Someone 2025.01.09 10:49  •  Comments (64)  • 

Open in app

Sign up

Sign in

Write

Sign up

Sign in

Setting up an Ethereum Virtual Private Network

Paul Neilson

·

Follow

8 min read · Oct 2, 2017

--

1

Listen

Share

There have been several excellent articles here about setting up a local ethereum network, but they did not quite match my needs.

The goal of this document is to set up a local, virtual Ethereum private network based on Ubuntu primarily to be used for testing. This will involve the set up of a minimum of 2 nodes, but potentially 3 (or more), which is within the capabilities of modern desktops and laptops.

My environment…

Lenovo Laptop i7 8GB RAM 256GB Windows 10 VirtualBox 5.1.18 Ubuntu 16.04, 16.10 or 17.04 Virtual Machine

I suggest that you make a standard guest virtual machine which includes your favourite edit environments, tools etc. and with VirtualBox Guest Additions Installed. Then you can clone that as required (using a linked clone to save disc space).

Most nodes will only require 1GB RAM (except Node A — see below). All virtual nodes can survive with 8GB Hard drive (most tests involve less than 7GB), however I have used 16GB hard drive because that was the size of my “standard” ubuntu virtual machine.

Ubuntu 16.10 is now deprecated so I would suggest with to 17.04 (or 16.04 LTS) or your favourite Linux distribution.

The blockchain on each node will be initialised with the same genesis.json file so that they can communicate correctly. Nodes will be connected manually to the “root” node in order to avoid unnecessary difficult in creating a self-discovering P2P network from scratch.

VirtualBox Network Configuration

When the Ethereum wallet is invoked it expects access to the internet to check versions etc. In addition, the point of this exercise is to allow multiple virtual machines to communicate with each other.

Therefore, the only practical VirtualBox network configuration is either Bridged or NAT Network. I used the latter to somewhat restrict the possibility of Ethereum traffic to and from the internet. I have only used IPV4 for this set up.

I have seen a few problems with VirtualBox networking, so these should probably be checked first if you suspect a network issue…

Loss IP address. Perhaps the DHCP lease times out and it is not granted a new one. Request a new lease usually works. Loss of connectivity to the outside world. Reboot.

Installation & Configuration

Node A

This node will be the primary node in our network. Other nodes in the network will be manually connected to this node in order to create the P2P network.

This node will be the mining node so it is suggested that this virtual machine be set up with 2GB of RAM.

Step 1 Install Ethereum

Here are the commands that will install Ethereum.

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

I recommend that you include this install in your “standard” Virtual machine so that you don’t need to reinstall in every instance.

Step 2 Prepare the Genesis File

After some trial & error I have landed on the following genesis.json file…

{
“config”: {
“chainId”: 637,
“homesteadBlock”: 0,
“eip155Block”: 0,
“eip158Block”: 0
},
“nonce”: “0x4242424242424242”,
“difficulty”: “0x400”,
“gasLimit”: “6000000”,
“alloc”: {
“0xc0c1710502e816aa903072367d1d856b34ffe84c”:
{ “balance”: “25000000000000000000” }
}
}

Some of the interesting points which you may choose to custom configure..

chainID Custom Id for your network Nonce Difficulty — try increasing this to slow down block generation gasLimit — try increasing or decreasing this to look at the impact of gas on transactions. alloc Since we can mine local Ether quickly, we don’t use this option. More below.

Using your favourite editor create the genesis.json file with the above text.

nano ~/genesis.json

I recommend that you include this install in your “standard” Virtual machine so that you don’t need to reinstall in every instance.

Step 4 Install the Mist Graphical Wallet

Download the latest ethereum wallet from here . Download a zip version (linux 64-bit) and unpack to the home directory which ends up in ~/linux-unpacked

Version 9.0 has just been released and I have not tested it fully yet. This latest version has a number of significant changes including separating the Ethereum wallet from mist browser and inbuilt support for local single node test networks.

For convenience, create a link to the mist &/or wallet executable

In version 9, this would be

ln -s ~/linux-unpacked-ethereumwallet090/ethereumwallet Wallet ln -s ~/linux-unpacked-mist090/mist Mist

In earlier versions, this would be

ln -s ~/linux-unpacked/mist Wallet

I recommend that you include this install in your “standard” Virtual machine so that you don’t need to reinstall in every instance.

Step 5 Initialise the Blockchain

Create a directory which will hold the local copy of the blockchain ( ~/ethchain/geth ) and the keystore ( ~/ethchain/keystore ) and a few other things. Then initialise the blockchain..

mkdir ~/ethchain
geth init ~/genesis.json — datadir ~/ethchain

Do not include this install in your “standard” Virtual machine as it is machine specific.

Step 6 Running the node

Once all nodes are setup, I like to run up to three separate terminals in order to run the following three actions..

Geth Node Tail the log file (mainly useful for the mining node) Mist

However to get started, run the following command in order to start the blockchain node..

geth — datadir ~/ethchain — networkid 637 — nodiscover console 2 eth.log

The output will look something like this…

Welcome to the Geth JavaScript console! instance: Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1 datadir: /home/slender/ethchain modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

In order for the wallet to operate correctly you need to create a default Ethereum address (the “coinbase”). The following command in the Geth Javascript console will create the default address with the specified password. In future any mining proceeds on this node will go to this address (but that can be changed is needed). The address that is generated is returned (only an example address is shown here) — take a note of it.

personal.newAccount(“SuitablePassword”);
“0x260c1e7e0048dfdca2649a964f91215d41b403b2”

If you were to restart geth now, the output would look like this (with the coinbase address shown)..

Welcome to the Geth JavaScript console! instance: Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1 coinbase: 0x0f16806037e95a197fb8b637f771a4574aa4220d at block: 1458 (Fri, 28 Jul 2017 16:19:15 AEST) datadir: /home/slender/ethchain modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

Step 7 Mining

In order to get some useful Ether, start mining. You only need one node to perform mining in this test network. At the Geth JavaScript console…

miner.start()

The first time you start mining, geth creates a DAG file in ~/.ethash which is a 1GB file used in the mining process (only on a mining node). This process takes a long time, e.g. 1 hour, so start mining an go drink some coffee. More information is located here . You can check the progess of the DAG creation by tailing the log file in another terminal.

tail -F eth.log

Once the DAG file has been created, you will be able to see the mining events in your log file and/or check to see that your balance is increasing in your coinbase address at the Geth JavaScript console …

eth.getBalance(eth.accounts[0])

or

eth.getBalance(“0x260c1e7e0048dfdca2649a964f91215d41b403b2”)

If you are not going to continue testing , stop mining to conserve your CPU time and disc space.

miner.stop()

Node B and above

Complete steps 1 to 6 inclusive above (that is all steps except for mining).

Running the Network

Run up to three separate terminals on each node in order to run the following three actions..

· Geth Node
Same as above…

geth — datadir ~/ethchain — networkid 637 — nodiscover console 2 eth.log

· Tail the log file (mainly useful for the mining node)

tail -F eth.log

· Mist &/or Ethereum Wallet

./Wallet — rpc ~/ethchain/geth.ipc

In order to create the P2P network, the most basic step is to ensure that your nodes have connectivity with each. Therefore use ifconfig (to obtain IP addresses) and ping to verify connectivity.

Node A will be the hub of the network, so we need to first obtain the enode Identifier for Node A. The other nodes will refer to this in their process of connection.

admin.nodeInfo

You can verify that initially there are no peers attached to Node as yet…

admin.peers

The output will look something like the following, but it is the enode setting that is of interest now..

{ enode: “enode://ea5595a28d5134c97464ad3554a0801d7e7b24851bb99f1bf363e343bc4c45d9ee75579f6eda59b873accd6f9fe064980b974b2127b3c69629c6afe5a7436c5a@[::]:30303?discport=0”, id: “ea5595a28d5134c97464ad3554a0801d7e7b24851bb99f1bf363e343bc4c45d9ee75579f6eda59b873accd6f9fe064980b974b2127b3c69629c6afe5a7436c5a”, ip: “::”, listenAddr: “[::]:30303”, name: “Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1”, ports: { discovery: 0, listener: 30303 }, protocols: { eth: { difficulty: 178618773, genesis: “0xe852721fa34df458e7bc68746fa5522f811996e4833e5a340d5044e7e763df29”, head: “0x1036b6c176e96c55382a3f797de06544efa9cd61ec6a88ce90bf81001555cb43”, network: 637 } } }

On Node B and above connect to Node A with the following command (using the specified enode) but be sure to include the IP address of Node A, which is not otherwise included in the above output (10.0.2.6 in the following example)…

admin.addPeer(“enode://ea5595a28d5134c97464ad3554a0801d7e7b24851bb99f1bf363e343bc4c45d9ee75579f6eda59b873accd6f9fe064980b974b2127b3c69629c6afe5a7436c5a@10.0.2.6:30303?discport=0”)

You can verify that the peer connection has been made by running the command below on all nodes. If you have 3 or more nodes then it all nodes should be listed for Node A, but for all other nodes only Node A should be listed. This reflects the nature of the “star” configuration that we have just created.

admin.peers

You are now ready to simulate the real world Ethereum network.

Things to try

Send Ether from one Account to another Create a Wallet Contract within the Ethereum Wallet Set Coinbase for Mining to Wallet (or other) Contract Create a Contract

Maintenance

Re-Initialise Everything

If you want to start again, you can either re-clone your virtual machines or remove all of the relevant directories.

rm -r ~/ethchain/ rm -r ~/.ethash/

Re-Initialise the Blockchain

The blockchain is stored in ~/ethchain/geth/ and so deleting it will allow tests to start over, but keeping any defined accounts and balances.

rm -r ~/ethchain/geth

Re-Initialise Accounts

The accounts are stored in ~/ethchain/keychain/ and so deleting it will allow the creation of new accounts, while keeping the blockchain.

This is an exercise in futility, as I cannot see a reason why you want to keep a blockchain (with transactions and account balances) and remove an access to those. It is here for completeness only.

rm -r ~/ethchain/keychain/

DAG Disc Space

Several DAG files are created in ~/.ethash (I am not sure of the circumstances of the ongoing creation of new versions). For example…

ls ~/.ethash/ -lh total 2.3G -rw-r — r — 1 slender slender 1.0G Jul 21 10:29 full-R23–0000000000000000 -rw-r — r — 1 slender slender 1.1G Jul 21 16:13 full-R23–290decd9548b62a8 -rw-r — r — 1 slender slender 1.1G Jul 21 10:37 full-R23–290decd9548b62a8.3916589616287113937

It should be fine to delete all DAG files except the oldest, in order to conserve disc space.

rm .ethash/full-R23–0000000000000000 rm .ethash/full-R23–290decd9548b62a8.3916589616287113937

Pre-seeding accounts with allocation

You may wish to pre-seed your accounts. It is straight forward. When you create a new blockchain and a new coinbase account, take note of the address of the account created.

Exit out of geth and remove the geth directory from the ~/ethchain directory. Do not remove the ~/ethchain/keystore/ as that contains the keys (which you have already created):

rm -r ~/ethchain/geth

Update the alloc section of your genesis file in ~/ethchain/geneis.json, adding the new address to the alloc key:

“alloc”: { “0x260c1e7e0048dfdca2649a964f91215d41b403b2”: { “balance”: “100000000000000000000” } }

Re-initialise the blockchain and then run geth console (both show in step 5 above). If you now check the balance of your account, it will be pre-allocated with 100 ether.

Links & Acknowledgements

I have relied on the great work at these sites and hereby acknowledge their help in my efforts.

How To Create A Private Ethereum Chain

Short post on how to create a private ethereum blockchain for testing contracts or playing around with

web.archive.org

ethereum/go-ethereum

go-ethereum - Official Go implementation of the Ethereum protocol

github.com

Setup a Local Ethereum Test Blockchain

♦ Version: 2, 07/10/2015 ♦ License: Beerware Version 42++ This guide is continually updated on the wiki. Please see…

blog.carl.pro

Use Geth to Setup your Own Private Ethereum Blockchain

Before starting this tutorial you must have downloaded geth. This tutorial was originally published on the MLG…

medium.com

Use Go-Ethereum to Setup your Own Private Ethereum Blockchain | MLG Blockchain

Michael Gord | ethereum, blockchain, private blockchain, coinbase, development, go-thereum, geth For this tutorial to…

mlgblockchain.com

Linux Ethereum Virtualbox

--

--

1

Follow

Written by Paul Neilson

8 Followers · 2 Following Follow

Responses ( 1 )

See all responses

Help

Status

About

Careers

Press

Blog

Privacy

Terms

Text to speech

Teams