Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# TOR SUPPORT IN BITCOIN3It is possible to run Bitcoin Core as a Tor onion service, and connect to such services.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.6## Compatibility8- Starting with version 22.0, Bitcoin Core only supports Tor version 3 hidden9services (Tor v3). Tor v2 addresses are ignored by Bitcoin Core and neither10relayed nor stored.12- Tor removed v2 support beginning with version 0.4.6.14- Bitcoin Core 31.0 removed `tor` as a network name. Use `onion` instead,15as in `-onlynet=onion` or `-proxy=addr:port=onion`16([#34031](https://github.com/bitcoin/bitcoin/pull/34031)).17The `-debug=tor` logging category is unaffected.19## How to see information about your Tor configuration via Bitcoin Core21There are several ways to see your local onion address in Bitcoin Core:22- in the "Local addresses" output of CLI `-netinfo`23- in the "localaddresses" output of RPC `getnetworkinfo`24- in the debug log (grep for "AddLocal"; the Tor address ends in `.onion`)26You may set the `-debug=tor` config logging option to have additional27information in the debug log about your Tor configuration.29CLI `-addrinfo` returns the number of addresses known to your node per30network. This can be useful to see how many onion peers your node knows,31e.g. for `-onlynet=onion`.33You can use the `getnodeaddresses` RPC to fetch a number of onion peers known to your node; run `bitcoin-cli help getnodeaddresses` for details.35`bitcoin rpc` can also be substituted for `bitcoin-cli`.37## 1. Run Bitcoin Core behind a Tor proxy39The first step is running Bitcoin Core behind a Tor proxy. This will already anonymize all40outgoing connections, but more is possible.42-proxy=ip[:port]43Set the proxy server. It will be used to try to reach .onion addresses44as well. You need to use -noonion or -onion=0 to explicitly disable45outbound access to onion services.47-proxy=ip[:port]=onion48or49-onion=ip[:port]50Set the proxy server for reaching .onion addresses. You do not need to51set this if it's the same as the generic -proxy. You can use -onion=0 to52explicitly disable access to onion services.53------------------------------------------------------------------------54Note: The proxy for DNS requests is taken from55-proxy=addr:port or56-proxy=addr:port=ipv4 or57-proxy=addr:port=ipv658(last one if multiple options are given). It is not taken from59-proxy=addr:port=onion or60-onion=addr:port.61If no proxy for DNS requests is configured, then they will be done using62the functions provided by the operating system, most likely resulting in63them being done over the clearnet to the DNS servers of the internet64service provider.65------------------------------------------------------------------------67If -proxy or -onion is specified multiple times, later occurrences override68earlier ones and command line overrides the config file. UNIX domain sockets may69be used for proxy connections. Set `-onion` or `-proxy` to the local socket path70with the prefix `unix:` (e.g. `-onion=unix:/home/me/torsocket`).72-listen73When using -proxy, listening is disabled by default. If you want to74manually configure an onion service (see section 3), you'll need to75enable it explicitly.77-connect=X78-addnode=X79-seednode=X80When behind a Tor proxy, you can specify .onion addresses instead of IP81addresses or hostnames in these parameters. Such addresses can also be82exchanged with other P2P nodes.84-onlynet=onion85Make automatic outbound connections only to .onion addresses. Inbound86and manual connections are not affected by this option. It can be87specified multiple times to allow multiple networks, e.g. onlynet=onion,88onlynet=i2p, onlynet=cjdns.90In a typical situation, this suffices to run behind a Tor proxy:92bitcoind -proxy=127.0.0.1:905094`bitcoin node` or `bitcoin gui` can also be substituted for `bitcoind`.96## 2. Automatically create a Bitcoin Core onion service98Bitcoin Core makes use of Tor's control socket API to create and destroy99ephemeral onion services programmatically. This means that if Tor is running and100proper authentication has been configured, Bitcoin Core automatically creates an101onion service to listen on. The goal is to increase the number of available102onion nodes.104This feature is enabled by default if Bitcoin Core is listening (`-listen`) and105it requires a Tor connection to work. It can be explicitly disabled with106`-listenonion=0`. If it is not disabled, it can be configured using the107`-torcontrol` and `-torpassword` settings.109To see verbose Tor information in the bitcoind debug log, pass `-debug=tor`.111### Control Port113You may need to set up the Tor Control Port. On Linux distributions there may be114some or all of the following settings in `/etc/tor/torrc`, generally commented115out by default (if not, add them):117```118ControlPort 9051119CookieAuthentication 1120CookieAuthFileGroupReadable 1121DataDirectoryGroupReadable 1122```124Add or uncomment those, save, and restart Tor (usually `systemctl restart tor`125or `sudo systemctl restart tor` on most systemd-based systems, including recent126Debian and Ubuntu, or just restart the computer).128### Authentication130Connecting to Tor's control socket API requires one of two authentication131methods to be configured: cookie authentication or bitcoind's `-torpassword`132configuration option.134#### Cookie authentication136For cookie authentication, the user running bitcoind must have read access to137the `CookieAuthFile` specified in the Tor configuration. In some cases this is138preconfigured and the creation of an onion service is automatic. Don't forget to139use the `-debug=tor` bitcoind configuration option to enable Tor debug logging.141If a permissions problem is seen in the debug log, e.g. `tor: Authentication142cookie /run/tor/control.authcookie could not be opened (check permissions)`, it143can be resolved by adding both the user running Tor and the user running144bitcoind to the same Tor group and setting permissions appropriately.146On Debian-derived systems, the Tor group will likely be `debian-tor` and one way147to verify could be to list the groups and grep for a "tor" group name:149```150getent group | cut -d: -f1 | grep -i tor151```153You can also check the group of the cookie file. On most Linux systems, the Tor154auth cookie will usually be `/run/tor/control.authcookie`:156```157TORGROUP=$(stat -c '%G' /run/tor/control.authcookie)158```160Once you have determined the `${TORGROUP}` and selected the `${USER}` that will161run bitcoind, run this as root:163```164usermod -a -G ${TORGROUP} ${USER}165```167Then restart the computer (or log out) and log in as the `${USER}` that will run168bitcoind.170#### `torpassword` authentication172For the `-torpassword=password` option, the password is the clear text form that173was used when generating the hashed password for the `HashedControlPassword`174option in the Tor configuration file.176The hashed password can be obtained with the command `tor --hash-password177password` (refer to the [Tor Dev178Manual](https://2019.www.torproject.org/docs/tor-manual.html.en) for more179details).182## 3. Manually create a Bitcoin Core onion service184You can also manually configure your node to be reachable from the Tor network.185Add these lines to your `/etc/tor/torrc` (or equivalent config file):187HiddenServiceDir /var/lib/tor/bitcoin-service/188HiddenServicePort 8333 127.0.0.1:8334189# If `tor --list-modules` shows "pow: yes", then enable PoW protection.190# It is available in tor-0.4.8.1-alpha and newer when configured with191# `./configure --enable-gpl`.192HiddenServicePoWDefensesEnabled 1194The directory can be different of course, but virtual port numbers should be equal to195your bitcoind's P2P listen port (8333 by default), and target addresses and ports196should be equal to binding address and port for inbound Tor connections (127.0.0.1:8334 by default).198-externalip=X You can tell bitcoin about its publicly reachable addresses using199this option, and this can be an onion address. Given the above200configuration, you can find your onion address in201/var/lib/tor/bitcoin-service/hostname. For connections202coming from unroutable addresses (such as 127.0.0.1, where the203Tor proxy typically runs), onion addresses are given204preference for your node to advertise itself with.206You can set multiple local addresses with -externalip. The207one that will be rumoured to a particular peer is the most208compatible one and also using heuristics, e.g. the address209with the most incoming connections, etc.211-listen You'll need to enable listening for incoming connections, as this212is off by default behind a proxy.214-discover When -externalip is specified, no attempt is made to discover local215IPv4 or IPv6 addresses. If you want to run a dual stack, reachable216from both Tor and IPv4 (or IPv6), you'll need to either pass your217other addresses using -externalip, or explicitly enable -discover.218Note that both addresses of a dual-stack system may be easily219linkable using traffic analysis.221In a typical situation, where you're only reachable via Tor, this should suffice:223bitcoind -proxy=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -listen225(obviously, replace the .onion address with your own). It should be noted that you still226listen on all devices and another node could establish a clearnet connection, when knowing227your address. To mitigate this, additionally bind the address of your Tor proxy:229bitcoind ... -bind=127.0.0.1:8334=onion231If you don't care too much about hiding your node, and want to be reachable on IPv4232as well, use `discover` instead:234bitcoind ... -discover236and open port 8333 on your firewall (or use port mapping, i.e., `-natpmp`).238If you only want to use Tor to reach .onion addresses, but not use it as a proxy239for normal IPv4/IPv6 communication, use:241bitcoind -onion=127.0.0.1:9050 -externalip=7zvj7a2imdgkdbg4f2dryd5rgtrn7upivr5eeij4cicjh65pooxeshid.onion -discover243## 4. Privacy recommendations245- Do not add anything but Bitcoin Core ports to the onion service created in section 3.246If you run a web service too, create a new onion service for that.247Otherwise it is trivial to link them, which may reduce privacy. Onion248services created automatically (as in section 2) always have only one port249open.250- Operating a node that listens on multiple networks (e.g. IPv4 and Tor) can help
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.