How to Set Up Bitcoin Core as a Tor Hidden Service: Complete Configuration Guide
Bitcoin Core operates as a Tor hidden service by routing P2P traffic through a SOCKS5 proxy and optionally creating an ephemeral onion address via the Tor control port, implemented in src/torcontrol.cpp and configured through startup flags like -proxy, -listen, and -torcontrol.
Running Bitcoin Core behind Tor enhances privacy by concealing your IP address and enabling connections to .onion peers exclusively. This guide explains how to configure the official bitcoin/bitcoin repository to set up Bitcoin Core as a Tor hidden service, covering both automatic service creation and manual persistent configuration.
Configuring the Tor Proxy for Outbound Connections
Before enabling inbound hidden service functionality, you must route Bitcoin Core's outbound traffic through Tor's SOCKS5 proxy. This allows the node to connect to .onion addresses and anonymize clearnet peer connections.
Use the -proxy flag to direct all network traffic through Tor:
bitcoind -proxy=127.0.0.1:9050
If you only want to proxy .onion traffic while using direct connections for IPv4/IPv6 peers, use -onion instead:
bitcoind -onion=127.0.0.1:9050
According to doc/tor.md, the default Tor SOCKS5 proxy listens on port 9050. If your Tor instance runs on a different port or host, adjust the value accordingly.
Enabling the Tor Hidden Service
To accept inbound connections as a hidden service, you must enable listening mode. Bitcoin Core supports two methods for creating onion services: automatic ephemeral creation via the control port (recommended for most users) or manual static configuration in your torrc file.
Automatic Ephemeral Hidden Service
When running with -listen, Bitcoin Core automatically contacts the Tor control port (default 9051) to create a temporary hidden service. This ephemeral service advertises a unique .onion address that persists only for the session duration.
Enable automatic hidden service creation with:
bitcoind -proxy=127.0.0.1:9050 -listen -debug=tor
The implementation in src/torcontrol.cpp (specifically lines 51-102) handles the protocol negotiation, authentication, and service registration with the Tor daemon. When successful, your node publishes a new onion address to the network and logs it via AddLocal messages.
Manual Persistent Hidden Service
For operators requiring a static .onion address across restarts, configure a persistent hidden service directly in torrc:
- Edit your Tor configuration file (typically
/etc/tor/torrc):
HiddenServiceDir /var/lib/tor/bitcoin-service/
HiddenServicePort 8333 127.0.0.1:8333
- Restart Tor to generate the hostname file.
- Retrieve your
.onionaddress from/var/lib/tor/bitcoin-service/hostname. - Launch Bitcoin Core with the static address:
bitcoind -proxy=127.0.0.1:9050 -externalip=youraddress.onion -listen
As documented in doc/tor.md (lines 77-88), the -externalip flag explicitly advertises your manual service address to peers.
Authenticating to the Tor Control Port
When using automatic hidden service creation, Bitcoin Core must authenticate to Tor's control port. The src/torcontrol.cpp module supports two authentication mechanisms.
Cookie Authentication (Recommended)
Tor generates a temporary cookie file (e.g., /run/tor/control.authcookie) that Bitcoin Core reads to authenticate. Ensure the user running bitcoind has read permissions for this file.
If you encounter permission errors in the debug log, add the Bitcoin Core user to the Tor group (commonly debian-tor on Debian-based systems):
sudo usermod -a -G debian-tor bitcoinuser
This method requires CookieAuthentication 1 in your torrc configuration.
Password Authentication
Alternatively, configure a hashed password in torrc:
- Generate a password hash:
tor --hash-password MySecretPassword
- Add the output to
torrc:
HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C
- Provide the cleartext password to Bitcoin Core:
bitcoind -torcontrol=127.0.0.1:9051 -torpassword=MySecretPassword -listen
Verifying Your Onion Address
After startup, confirm your hidden service is operational using several methods:
- Debug logs: Search for
AddLocalentries containing your.onionaddress - RPC interface: Query
getnetworkinfoand examine thelocaladdressesarray - Network statistics: Use
-addrinfoto view counts of reachable.onionpeers
Example RPC verification:
bitcoin-cli getnetworkinfo | jq '.localaddresses'
The output displays your advertised onion address, port, and score metrics.
Privacy and Security Considerations
Operating Bitcoin Core as a Tor hidden service requires balancing network participation with privacy:
- Port isolation: The automatic service creates a single-port hidden service for P2P traffic only. If you run additional services (like a web interface), create separate hidden services to prevent traffic correlation.
- Dual-stack exposure: Running
-listenwithout-onlynet=onionadvertises your node on both clearnet and Tor, improving network robustness but potentially enabling cross-network fingerprinting. - Proxy verification: Ensure your firewall blocks direct outbound connections when using
-proxyto prevent accidental IP leakage.
Summary
- Tor proxy configuration: Route traffic through
127.0.0.1:9050using-proxy(all traffic) or-onion(onion-only). - Hidden service creation: Use
-listenfor automatic ephemeral services viasrc/torcontrol.cpp, or manually configureHiddenServicePortintorrcwith-externalip. - Authentication: Prefer cookie authentication; ensure file permissions allow Bitcoin Core to read Tor's auth cookie.
- Verification: Check
getnetworkinfoRPC or debug logs forAddLocalmessages confirming your.onionaddress. - Source references: Implementation resides in
src/torcontrol.cppandsrc/torcontrol.h, with documentation indoc/tor.md.
Frequently Asked Questions
How do I know if Bitcoin Core is successfully connected to the Tor control port?
Check the debug logs for tor: category messages using -debug=tor. Successful authentication shows tor: Connected to Tor version followed by tor: Got service ID when the hidden service registers. If authentication fails, you'll see tor: Authentication failed errors indicating cookie permission issues or password mismatches.
Can I run Bitcoin Core as a Tor hidden service without enabling listening mode?
No. The -listen flag is required because it enables inbound P2P connections, which is the foundational mechanism for hidden service operation. Without listening, Bitcoin Core only makes outbound connections through the SOCKS5 proxy and never attempts to register with the Tor control port for service creation.
What is the difference between -proxy and -onion configuration flags?
-proxy directs all network traffic (IPv4, IPv6, and onion) through the specified SOCKS5 proxy, ensuring complete traffic anonymization. -onion specifically proxies only .onion peer connections while allowing IPv4/IPv6 traffic to use direct connections. Use -proxy for maximum privacy; use -onion if you only need to reach Tor-exclusive peers while maintaining direct clearnet connectivity.
Why does my node show a different onion address after restarting?
If you use automatic hidden service creation (the default with -listen), Bitcoin Core generates an ephemeral service that exists only for the current session. According to the implementation in src/torcontrol.cpp, the node requests a new service ID from Tor on each startup. To maintain a persistent address across restarts, configure a static hidden service in torrc and use -externalip to advertise it.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →