How To Run a Bitcoin Full Node over Tor on an Ubuntu (Linux) Virtual Machine (updated 2021)

A step-by-step guide to getting a Bitcoin Full Node running on your computer — no previous experience required!

Full Nodes are Bitcoin’s nervous system!

This article updated in February 2021 with latest info and corrections, including VirtualBox 6.1.18, Ubuntu Server 20.04.2LTS, and Bitcoin Core 0.21.0

Have you thought about experimenting with a full bitcoin node but are concerned about privacy or messing up your main OS? Then read on… This article will walk you through all the steps needed to run a Bitcoin node over the TOR security protocol in a virtual machine. You needn’t worry about corrupting your main/host OS, and you’ll have a low-risk Bitcoin node for experimenting. This guide is made with the Microsoft Windows version of VirtualBox, but the process is nearly identical on MacOS and Linux once you’ve installed VirtualBox for your platform.

Part Zero — Overview

In this guide, we will be accomplishing four main tasks:

  1. Installing and configuring the latest stable, long-term-support version of Ubuntu Server within that virtual machine host
  2. Installing and configuring a Bitcoin Core (bitcoind) Full Node
  3. Configuring bitcoind to run over the Tor network (this protects your privacy while conveniently avoiding the need to modify any home router settings to allow incoming Bitcoin network traffic)

Part One — Prerequisites

Because a true full node requires downloading and storing the entire history of the Bitcoin blockchain, you will need to ensure you have approximately 330GB (as of Feb 2021) of free hard disk space, ideally closer to 350–400GB. While you can perform what’s known as “pruning” to trim the amount of disk space used after the initial blockchain download, I will not be covering that here.

Part Two— Setting up the VirtualBox platform

VirtualBox is a free, open source program for running virtual machines on your computer. To download, visit https://www.virtualbox.org/

Part Three — Configuring our Ubuntu Linux server virtual machine

Ubuntu is one of the most popular distributions of the Linux operating system and is free to download and use. In this guide, I’ll be using what’s known as the LTS (Long-term Support) version, which is supported for five years.

  • Give the VM a name, such as Ubuntu Server
  • In Type select Linux
  • In Version select Ubuntu (64-bit) — Click Next >
  • In the Memory size dialog, choose as much memory as you can without negatively impacting your ability to otherwise use your computer while VirtualBox is running. I have 32GB of RAM on my host computer, so I will choose ~8GB here. The more memory you can allocate, the better, as the initial Bitcoin blockchain download/sync is memory intensive. You can always scale this back (or up) later as needed. — Click Next >
  • On the Hard disk dialog, select Create a virtual hard disk now — Click Create
  • On the Hard disk file type dialog, leave VDI selected — Click Next >
  • On the Storage on physical hard disk dialog, leave Dynamically allocated selected — Click Next >
  • On the File location and size dialog, you’ll want to choose at least 350GB, preferably 400GB. Note that VirtualBox won’t consume this space immediately, but will grow the virtual disk in size as needed, up to that limit. — Click Create

Part Four — Installing Ubuntu Linux on our new virtual machine disk

  • Right-click the new Virtual Machine in the left column and Choose Start →Normal Start from the main VirtualBox menu. Alternatively, click the large green Start button on the main button bar.
  • You will be prompted for a start-up disk. Choose the Ubuntu .iso file we downloaded earlier, then click Start.
sudo apt update && sudo apt upgrade

Part Five — Installing the Bitcoin Core server (bitcoind)

To install bitcoind, we’ll be downloading and compiling the source code for both bitcoin and the Berkeley Database it uses to store wallet info. Before we can do so, we’ll need to install some prerequisite software.

sudo add-apt-repository universe
sudo apt install build-essential autoconf libtool pkg-config libboost-all-dev libssl-dev libevent-dev doxygen libzmq3-dev libdb++-dev libsqlite3-dev
cd ~
git clone https://github.com/bitcoin/bitcoin.git 
cd bitcoin./contrib/install_db4.sh `pwd`
git checkout v0.21.0git status
./autogen.sh
export BDB_PREFIX="$HOME/bitcoin/db4"./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include" --with-gui=no --with-miniupnpc=no
makemake checksudo make install

Part Six — Configuring Bitcoin to use Tor

Before we launch the Bitcoin Core server (bitcoind), we’ll need to create its configuration file to ensure that it downloads the full blockchain history (so we can directly inspect any transaction) and uses only Tor connections. By default, even if you have Tor installed and configured, bitcoind will still communicate with nodes over TCP — we have to explicitly tell it to only use TOR to protect our privacy:

cd ~mkdir .bitcointouch .bitcoin/bitcoin.confecho "txindex=1" >> .bitcoin/bitcoin.confecho "onlynet=onion" >> .bitcoin/bitcoin.conf
echo "maxconnections=20" >> .bitcoin/bitcoin.conf
sudo apt install tor
less /usr/share/tor/tor-service-defaults-torrc
sudo sh -c "echo 'ControlPort 9051' >> /etc/tor/torrc"
sudo systemctl restart tor
journalctl -f | grep tor -i
sudo usermod -a -G debian-tor username

Part Seven— Bitcoin Lives!!!

Once logged back in, you are finally ready to launch Bitcoin over Tor!

bitcoind -daemon -debug=tor
tail -f ~/.bitcoin/debug.log
bitcoin-cli getnetworkinfo
"networks": [
{
"name": "ipv4",
"limited": true,
"reachable": false,
... (and the same for the ipv6 entry) ... "name": "onion",
"limited": false;
"reachable": true,
...
bitcoin-cli getpeerinfo | grep true
bitcoin-cli getpeerinfo | grep addr

Part Eight—The End

I hope you’ve found this guide useful. Feel free to ask any questions or note any problems in the comments. Thanks for reading!

References

https://medium.com/@lopp/how-to-run-bitcoin-as-a-tor-hidden-service-on-ubuntu-cff52d543756

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store