1# TOR SUPPORT IN BITCOIN
2
3It is possible to run Bitcoin Core as a Tor onion service, and connect to such services.
4
5The following directions assume you have a Tor proxy running on port 9050. Many distributions default to having a SOCKS proxy listening on port 9050, but others may not. In particular, the Tor Browser Bundle defaults to listening on port 9150. See [Tor Project FAQ:TBBSocksPort](https://www.torproject.org/docs/faq.html.en#TBBSocksPort) for how to properly
6configure Tor.
7
8## How to see information about your Tor configuration via Bitcoin Core
9
10There are several ways to see your local onion address in Bitcoin Core:
11- in the debug log (grep for "tor:" or "AddLocal")
12- in the output of RPC `getnetworkinfo` in the "localaddresses" section
13- in the output of the CLI `-netinfo` peer connections dashboard
14
15You may set the `-debug=tor` config logging option to have additional
16information in the debug log about your Tor configuration.
17
18
19## 1. Run Bitcoin Core behind a Tor proxy
20
21The first step is running Bitcoin Core behind a Tor proxy. This will already anonymize all
22outgoing connections, but more is possible.
23
24	-proxy=ip:port  Set the proxy server. If SOCKS5 is selected (default), this proxy
25	                server will be used to try to reach .onion addresses as well.
26
27	-onion=ip:port  Set the proxy server to use for Tor onion services. You do not
28	                need to set this if it's the same as -proxy. You can use -noonion
29	                to explicitly disable access to onion services.
30
31	-listen         When using -proxy, listening is disabled by default. If you want
32	                to run an onion service (see next section), you'll need to enable
33	                it explicitly.
34
35	-connect=X      When behind a Tor proxy, you can specify .onion addresses instead
36	-addnode=X      of IP addresses or hostnames in these parameters. It requires
37	-seednode=X     SOCKS5. In Tor mode, such addresses can also be exchanged with
38	                other P2P nodes.
39
40	-onlynet=onion  Make outgoing connections only to .onion addresses. Incoming
41	                connections are not affected by this option. This option can be
42	                specified multiple times to allow multiple network types, e.g.
43	                ipv4, ipv6, or onion.
44
45In a typical situation, this suffices to run behind a Tor proxy:
46
47	./bitcoind -proxy=127.0.0.1:9050
48
49
50## 2. Run a Bitcoin Core hidden server
51
52If you configure your Tor system accordingly, it is possible to make your node also
53reachable from the Tor network. Add these lines to your /etc/tor/torrc (or equivalent
54config file): *Needed for Tor version 0.2.7.0 and older versions of Tor only. For newer
55versions of Tor see [Section 3](#3-automatically-listen-on-tor).*
56
57	HiddenServiceDir /var/lib/tor/bitcoin-service/
58	HiddenServicePort 8333 127.0.0.1:8334
59	HiddenServicePort 18333 127.0.0.1:18334
60
61The directory can be different of course, but virtual port numbers should be equal to
62your bitcoind's P2P listen port (8333 by default), and target addresses and ports
63should be equal to binding address and port for inbound Tor connections (127.0.0.1:8334 by default).
64
65	-externalip=X   You can tell bitcoin about its publicly reachable addresses using
66	                this option, and this can be an onion address. Given the above
67	                configuration, you can find your onion address in
68	                /var/lib/tor/bitcoin-service/hostname. For connections
69	                coming from unroutable addresses (such as 127.0.0.1, where the
70	                Tor proxy typically runs), onion addresses are given
71	                preference for your node to advertise itself with.
72
73	                You can set multiple local addresses with -externalip. The
74	                one that will be rumoured to a particular peer is the most
75	                compatible one and also using heuristics, e.g. the address
76	                with the most incoming connections, etc.
77
78	-listen         You'll need to enable listening for incoming connections, as this
79	                is off by default behind a proxy.
80
81	-discover       When -externalip is specified, no attempt is made to discover local
82	                IPv4 or IPv6 addresses. If you want to run a dual stack, reachable
83	                from both Tor and IPv4 (or IPv6), you'll need to either pass your
84	                other addresses using -externalip, or explicitly enable -discover.
85	                Note that both addresses of a dual-stack system may be easily
86	                linkable using traffic analysis.
87
88In a typical situation, where you're only reachable via Tor, this should suffice:
89
90	./bitcoind -proxy=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -listen
91
92(obviously, replace the .onion address with your own). It should be noted that you still
93listen on all devices and another node could establish a clearnet connection, when knowing
94your address. To mitigate this, additionally bind the address of your Tor proxy:
95
96	./bitcoind ... -bind=127.0.0.1
97
98If you don't care too much about hiding your node, and want to be reachable on IPv4
99as well, use `discover` instead:
100
101	./bitcoind ... -discover
102
103and open port 8333 on your firewall (or use -upnp).
104
105If you only want to use Tor to reach .onion addresses, but not use it as a proxy
106for normal IPv4/IPv6 communication, use:
107
108	./bitcoind -onion=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -discover
109
110## 3. Automatically listen on Tor
111
112Starting with Tor version 0.2.7.1 it is possible, through Tor's control socket
113API, to create and destroy 'ephemeral' onion services programmatically.
114Bitcoin Core has been updated to make use of this.
115
116This means that if Tor is running (and proper authentication has been configured),
117Bitcoin Core automatically creates an onion service to listen on. This will positively
118affect the number of available .onion nodes.
119
120This new feature is enabled by default if Bitcoin Core is listening (`-listen`), and
121requires a Tor connection to work. It can be explicitly disabled with `-listenonion=0`
122and, if not disabled, configured using the `-torcontrol` and `-torpassword` settings.
123To show verbose debugging information, pass `-debug=tor`.
124
125Connecting to Tor's control socket API requires one of two authentication methods to be
126configured. It also requires the control socket to be enabled, e.g. put `ControlPort 9051`
127in `torrc` config file. For cookie authentication the user running bitcoind must have read
128access to the `CookieAuthFile` specified in Tor configuration. In some cases this is
129preconfigured and the creation of an onion service is automatic. If permission problems
130are seen with `-debug=tor` they can be resolved by adding both the user running Tor and
131the user running bitcoind to the same group and setting permissions appropriately. On
132Debian-based systems the user running bitcoind can be added to the debian-tor group,
133which has the appropriate permissions. Before starting bitcoind you will need to re-login
134to allow debian-tor group to be applied. Otherwise you will see the following notice: "tor:
135Authentication cookie /run/tor/control.authcookie could not be opened (check permissions)"
136on debug.log.
137
138An alternative authentication method is the use
139of the `-torpassword=password` option. The `password` is the clear text form that
140was used when generating the hashed password for the `HashedControlPassword` option
141in the tor configuration file. The hashed password can be obtained with the command
142`tor --hash-password password` (read the tor manual for more details).
143
144## 4. Privacy recommendations
145
146- Do not add anything but Bitcoin Core ports to the onion service created in section 2.
147  If you run a web service too, create a new onion service for that.
148  Otherwise it is trivial to link them, which may reduce privacy. Hidden
149  services created automatically (as in section 3) always have only one port
150  open.
151