I've now automated this whole process you can download a script to install core with TOR and I2P Via this link
So I know I’m not the first person to put out a how-to guide on running a Bitcoin
full node. There are lots out here, but I’m going to throw in my lot because I've been wanting to
do technical Bitcoin guides for a few reasons. First, writing actually helps me get a firmer grasp on
what I'm writing about. It's kind of a learning tool for me, so bare with me. Secondly,
I'm not sure if there is a guide that includes I2P yet.
This guide assumes a few things.
That you know what a Bitcoin node is. That you're sick of trying to run one via Umbrel or some
other node package for whatever reason, and you want a bit more control over how it operates. I’m going
to be using Bitcoin core. Specifically, this will focus on bitcoind and should be valid on newer Debian
based distributions (Ubuntu, Raspbian, etc.).
I want to touch on hardware quickly. It's still pretty common to see people
running nodes via Umbrel,Start9, MyNode or Rasblitz. All on Raspberry Pi’s, which for some applications
is fine. I run a few things on my home network that use a Raspberry Pi, they have great up-time and cost
little to run 24/7. But, at the end of the day, they are low powered computers.
A Raspberry Pi 4
Model B has a quad-core ARM v8 that clocks in at 1.8GHz and up to 8 gigs of RAM, and we are at a point
in Bitcoins history where the chain is starting to get big (~475GB at the time of writing) and if you
want to do more than just run core then you'll need at least a 1tb to 2tb SSD. In my experience,
they tend to bog down when you get too many things running on them at once. The CPU ends up being a bit
of a bottleneck, and it slows down your IBD significantly. You might or might not care about this. Low
time preference, right? Anyway...
Cost wise, in the current environment, assuming you can find a
Pi with 4 to 8 gigs of RAM. If you're starting from scratch, it's going to be more expensive
to buy the Pi plus the required hard drive than an old tower from some business trying to liquidate old
equipment. The old tower will be a much more robust node in the long run. So if you're building
from scratch, save some Sats and consider getting an older or refurbished computer. Plus, doing the IBD
in ~15 hours (over clearnet) is a lot better than the week or so that it takes the Pi to
sync.
Just my two Stats. End of the day, it's your choice.
You are going to want to do some prep before the actual installation. First things
first, update your box.
Run :
sudo apt update && sudo apt upgrade -y
To grab updates and make sure your system is up-to-date. For a more in depth overview of server setup check out this post
Depending on how you installed your OS, you're probably in a non-root account.
For security and organization, separating projects into different users is a decent idea; these users
are not admins and therefore can not edit configuration files. If you are not in a root account, you can
use your current account or make a new user. Just keep in mind the username you make because you will
use that going forward when setting things up.
Each line is a new command. Run :
sudo adduser “your user”
sudo passwd “your user”
sudo groupadd "your group"
sudo usermod -aG “your group” ”your user”
Bitcoin has several options when it comes to how you wish to relay data. You can
choose to relay Bitcoin data with any combo of these networks. Just be aware of the trade-offs. If you
want something more private, use Tor / I2P only, but it will slow down your initial block download.
First lets add the Tor repository you might not have to do this try running “apt install tor” if it asks to install you can skip to the next bit if not go ahead and run :
lsb_release -c
This will give you the code name of the OS you're running. In my case it
was “bullseye”. Remeber to replace “bullseye” in the next command if you got something
different.
Run :
echo "deb https://deb.torproject.org/torproject.org bullseye main" | sudo tee /etc/apt/sources.list.d/tor.list
Add the GPG key next with :
gpg --keyserver keys.gnupg.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
Now you can run “apt update” and “apt install tor”. After the installation is
done you'll need to edit a configuration file called “torrc” by default it should be in
etc/tor/torrc.
Run :
sudo nano /etc/tor/torrc
scroll to the bottom and copy and paste this :
ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1
Log notice stdout
SOCKSPort 9050
To make sure Tor is enabled at boot run :
sudo systemctl enable tor
Also make sure your user can run Tor with :
sudo usermod -aG debian-tor your-user
If you get an error saying that the group does not exist, you can find Tor’s
default group name with :
grep User /usr/share/tor/tor-service-defaults-torrc
And replace “debian-tor” with the group name. Tor should now be good to go. On
to I2P.
I2P support was added in Version 0.7.0. I won’t go into detail about it here,
but if you don’t know what it is and want a general overview, I wrote about it here. You can read that
here. Suffice to say it's another privacy network and the second most used to date. We will be
using the I2Pd implementation of I2p. It is more suitable for servers.
Make sure you have the
“apt-transport-https” package installed with :
sudo apt install apt-transport-https
Then add the repository. I2P makes it easy with :
wget -q -O - https://repo.i2pd.xyz/.help/add_repo | sudo bash -s -
Then install it like you would any other package with :
sudo apt update
sudo apt install i2pd
enable it on boot with :
sudo systemctl enable i2pd
This is all the configuration you need to do to I2P. Before moving on you can
check if Tor and I2P are up and running and listening on the right ports with :
sudo netstat -tulpn | egrep 'i2pd|tor' | grep LISTEN
You should see the Tor ports 9050, 9051 and I2P ports 4444, 7070, 4447, 6668,
7656 open as well as the random port that I2P chooses. Open ports depend on your configuration, but
these are the default. Now is also a good time to reboot your box to make sure some of the changes we
have made so far take hold.
Note:
Port 7070 is a web dashboard for I2PD if you want to make it visible on your local network, you can edit the configuration file with :
sudo nano /etc/i2pd/i2pd.conf
Look for the [http] section and change the IP address to your machine's IP. It's a good idea to uncomment the auth options as well. Fill those in and save and exit with ctl+s and ctl+x.
Restart I2P with :
systemctl restart i2pd
You should be able to browse to “yourIP:7070” and log into the web GUI with the user and password you set.
Finally on to installing Bitcoin Core. Make sure that all the necessary
dependencies are installed. These are included in most modern Linux distributions but just to make sure
run :
sudo apt install git build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev libboost-all-dev libzmq3-dev
If there are no errors, then you are good to move on. Navigate into a directory
that you want to pull your copy of Core into. You can make a folder with :
mkdir “your folder”
cd “your folder”
wget https://bitcoincore.org/bin/bitcoin-core-26.0.0/bitcoin-26.0.0.tar.gz
Grab a signer PGP key with :
gpg --keyserver keyserver.ubuntu.com –recv-keys E777299FC265DD04793070EB944D35F9AC3DB76A
gpg --export E777299FC265DD04793070EB944D35F9AC3DB76A | sudo apt-key add -
Then run :
wget https://bitcoincore.org/bin/bitcoin-core-26.0.0/SHA256SUMS
sha256sum --ignore-missing --check SHA256SUMS
you should see “bitcoin-26.0.0.tar.gz: OK” If that passes extract Cor with
:
tar -xzvf bitcoin-26.0.0.tar.gz
cd bitcoin-26.0.0
Build Core with :
./autogen.sh
./configure
make
This last command will take some time to play out, so after running go touch
grass or have some lunch while this plays out. On my test laptop, it took about an hour and a half to
compile.
sudo make install
Almost there! Bitcoin by default makes its data directory in a folder called
.bitcoin in the home folder of the user that runs it. Core will make these folders once you start
running core with some default settings, but if you're trying to be private, we need to configure
Core first so it will start up with our Tor and I2P proxies we set up above. Keep in mind you can set
anywhere you want to be your data directory but using the default is fine.
In the directory that
you want to the data folder to be run :
mkdir .bitcoin
cd .bitcoin
nano bitcoin.conf
There are a lot of settings you can flip here, below will be a bare minimum
configuration file. This file assumes you are installing with the plan to use Lightning Network at some
point and want to connect other apps like an electrum server to your node.
# [core]
# Maintain coinstats index used by the gettxoutsetinfo RPC.
coinstatsindex=1
# Run in the background as a daemon and accept commands.
daemon=1
# Wait for initialization to be finished before exiting. This implies -daemon.
daemonwait=1
# Set database cache size in megabytes; machines sync faster with a larger cache. Recommend setting as high as possible based upon machine's available RAM. Adjust as needed.
dbcache=600
# This is the ammount of RAM used for your mempool. This is set rather high so adjust as needed. Set in megabytes
maxmempool=800
# Maintain a full transaction index, used by the getrawtransaction rpc call.
txindex=1
# Turn off serving SPV nodes
nopeerbloomfilters=1
peerbloomfilters=0
# Don't accept deprecated multi-sig style
permitbaremultisig=0
# Reduce the log file size on restarts
shrinkdebuglog=1
#Add visibility into mempool and RPC calls for potential LND debugging
debug=mempool
debug=rpc
debug=tor
debug=i2p
#[NETWORK]
# This allows only Tor and I2P connections remove to allow IPv4
onlynet=onion,i2p
# Connect to Tor proxy
proxy=127.0.0.1:9050
# I2PD Proxy
i2psam=127.0.0.1:7656
Save and exit with CTL-S and CTL-X. A few notes on the config file. Lopp has a
great config maker on GitHub. It's a good way to explore the options available to you. You can see that
here. Also, if you are having a hard time finding peers, you can use this list to add Tor and I2P peers manually.
This is a last optional step, but it makes managing Core really easy. To plug
Core into systemd you need to make a system file run :
nano /etc/systemd/system/bitcoind.service
Then copy and paste the following. Keep in mind, you'll need to change the
folders that are being used if you changed any of the defaults and to make sure your user can access
those files or else this won't work.
[Unit]
Description=Bitcoin Core Daemon
After=network-online.target
Wants=network-online.target
[Service]
User=your user
Group=your user
Type=forking
ExecStart=/usr/local/bin/bitcoind \
-conf=/path/to/conf/file/.bitcoin/bitcoin.conf\
-pid=/run/bitcoind.pid
Restart=always
PrivateTmp=true
TimeoutStopSec=480s
TimeoutStartSec=480s
StartLimitInterval=480s
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
Finally, you need to enable and start Core. Run :
sudo systemctl enable bitcoind
sudo systemctl start bitcoind
There you have it, if everything is in order you should be able to run
"systemctl status bitcoind" and see that it's up and running.
If you want to see
core syncing, you can run "bitcoin-cli -getinfo" to see your progress.
I hope this
helps, and congrats getting your Bitcoin full node up and running! This lays the base for any additions
that you want to make to your local bitcoin infrastructure.