How to Protect a Tor Hidden Service IP Address

Operating a Tor onion service requires strict security practices to ensure the hosting server’s real IP address is never exposed to the public. Because Tor is designed to obscure routing, IP leaks almost always originate from misconfigurations within the operating system, web server software, or backend applications. This guide details the essential technical measures needed to prevent identity leaks, harden server architecture, and keep your Tor hidden service entirely anonymous.

1. Bind Services Exclusively to Localhost

Web servers and backend applications must never listen on public IP addresses (0.0.0.0). Configure your server software (such as Nginx or Apache) to listen exclusively on 127.0.0.1 or, preferably, a UNIX domain socket.

For Nginx, configure your site configuration file to use local sockets:

listen unix:/var/run/tor-service.sock;

For Apache, specify the loopback interface:

Listen 127.0.0.1:8080

The Tor daemon can then forward incoming onion traffic directly to this local interface, preventing any direct clearnet connections to the application.

2. Block All Inbound Clearnet Traffic

A Tor hidden service does not require any inbound ports open on the public network interface. Tor establishes outbound connections to the Tor network to build rendezvous circuits.

Use iptables or nftables to drop all inbound traffic on external interfaces: * Set default incoming policy to DROP. * Allow loopback traffic on lo. * Allow established and related outbound connections. * Restrict direct management access (such as SSH) strictly through a dedicated Tor onion service or an encrypted, IP-whitelisted VPN.

3. Implement Network Isolation with Whonix or Multi-VM Architecture

The most effective way to eliminate IP leaks is architectural isolation. Running the Tor daemon and the application server on the same operating system creates a single point of failure.

4. Sanitize Application Responses and Server Headers

Web applications and server software often leak system details that allow attackers to correlate an onion service with a public clearnet server.

5. Prevent Outbound Information Leaks (SSRF)

Server-Side Request Forgery (SSRF) vulnerabilities allow attackers to force your server to make external requests to attacker-controlled clearnet endpoints, instantly exposing the server’s public IP address.

6. Eliminate Clearnet DNS Requests

Standard DNS resolution bypasses Tor by default and communicates with clearnet DNS resolvers configured in /etc/resolv.conf, which leaks queries and reveals the host server’s location.

DNSPort 5353
AutomapHostsOnResolve 1