The torrc file is Tor's configuration, at /etc/tor/torrc on Debian and Ubuntu. The directives you reach for most: SocksPort 9050 for the SOCKS proxy, ControlPort 9051 with CookieAuthentication 1 for scripted control, ExitNodes for country pinning (with ExcludeNodes plus StrictNodes 1 when an exclusion must be absolute), and HiddenServiceDir plus HiddenServicePort for an onion service.
A torrc cheat sheet is a single-page reference of the configuration directives the Tor daemon accepts, grouped by what you are trying to do: open a SOCKS proxy for applications, lock down the control port, build longer or shorter circuits, pin entry or exit countries, run a hidden service, route through bridges, tune logging, or squeeze out more performance. After the reference, Use Tor as a SOCKS5 proxy puts SocksPort to work from curl, Python, Node, and torsocks without leaking DNS. This covers Tor 0.4.x through the current stable in 2026, with the "as of which version" notes added where a directive changed behavior recently. The last section puts the control-port directives to work: forcing a new circuit on demand with the NEWNYM signal, from a raw socket, Python stem, or nyx, and the 10-second rate limit that catches everyone.
Cheat sheet
torrc Cheat Sheet
Reference for every common torrc directive in Tor 0.4.x, grouped by use case. Includes SOCKS and control ports, country pinning, hidden services, bridges, performance tuning, and logging.
Where torrc lives
The Tor daemon reads its config from a single text file. Locations vary by how you installed it.
| Install | Path |
|---|---|
| Linux (Debian/Ubuntu, Fedora, Arch packages) | /etc/tor/torrc |
| Linux (compiled from source) | /usr/local/etc/tor/torrc |
| macOS (Homebrew) | /opt/homebrew/etc/tor/torrc (Apple Silicon) or /usr/local/etc/tor/torrc (Intel) |
| Tor Browser (Windows, Linux) | Browser/TorBrowser/Data/Tor/torrc inside the browser folder |
| Tor Browser (macOS) | ~/Library/Application Support/TorBrowser-Data/Tor/torrc |
| Tails / Whonix | /etc/tor/torrc (managed by the distro; user changes get overwritten on shutdown) |
After editing, reload (don't restart unless you need to):
# systemd-managed
sudo systemctl reload tor
# everything else (sends SIGHUP)
sudo pkill -HUP torA SIGHUP tells the daemon to re-read torrc without dropping current circuits.
Complete example: client-only torrc
A reasonable starting torrc for using Tor as a SOCKS proxy from a laptop:
# Listen for SOCKS5 from local apps
SocksPort 9050 IsolateDestAddr IsolateDestPort
# Local DNS resolver so I can iptables-route DNS through Tor
DNSPort 5353
AutomapHostsOnResolve 1
# Control port for nyx and per-script NEWNYM
ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1
# Reasonable circuit settings
MaxCircuitDirtiness 600
NumEntryGuards 3
# Quiet-ish logging
Log notice file /var/log/tor/notices.log
DataDirectory /var/lib/tor
# Never be an exit
ExitPolicy reject *:*Complete example: hidden service operator
# Keep client-side knobs
SocksPort 9050
ControlPort 9051
CookieAuthentication 1
# The hidden service itself
HiddenServiceDir /var/lib/tor/myservice/
HiddenServicePort 80 127.0.0.1:8080
HiddenServicePort 443 127.0.0.1:8443
# Resilience tuning
HiddenServiceNumIntroductionPoints 6
HiddenServiceMaxStreams 50
HiddenServiceMaxStreamsCloseCircuit 1
Log notice file /var/log/tor/notices.logThe directory at HiddenServiceDir is created automatically on first start. Tor writes the public hostname to hostname and the private key to hs_ed25519_secret_key inside it. Back up the secret key, losing it means losing the .onion address forever.
Complete example: bridge user behind ISP block
UseBridges 1
ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy
# Replace with bridge lines from https://bridges.torproject.org/options
Bridge obfs4 192.0.2.1:443 0123456789ABCDEF0123456789ABCDEF01234567 cert=AAAA... iat-mode=0
Bridge obfs4 192.0.2.2:443 9876543210FEDCBA9876543210FEDCBA98765432 cert=BBBB... iat-mode=0
SocksPort 9050
Log notice file /var/log/tor/notices.logThree bridges is the sweet spot, enough redundancy that one going down doesn't cut you off, not so many that you're hammering volunteer-run infrastructure.
Use Tor as a SOCKS5 proxy
With SocksPort 9050 set, any program that speaks SOCKS5 can use 127.0.0.1:9050 (or 9150 for Tor Browser) as its transport. The part people get wrong is DNS: the client must send the hostname to the proxy and let Tor resolve it. A plain curl --socks5 127.0.0.1:9050 https://example.com resolves example.com locally first, which leaks the hostname to your ISP and defeats the point of using Tor.
Start the daemon and confirm it is listening and working before you debug any client:
sudo systemctl start tor
ss -ltn | grep 9050
# LISTEN 0 4096 127.0.0.1:9050 0.0.0.0:*
curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip
# {"IsTor":true,"IP":"151.115.X.X"}On macOS Homebrew it is brew services start tor. If IsTor is false, the daemon is not on the port you expect.
curl: --socks5-hostname, not --socks5
# DNS-safe: the hostname is resolved at the SOCKS hop (Tor)
curl --socks5-hostname 127.0.0.1:9050 https://example.com
curl -x socks5h://127.0.0.1:9050 https://example.com
# DNS-leaky: curl resolves locally and sends Tor a raw IP
curl --socks5 127.0.0.1:9050 https://example.com
curl -x socks5://127.0.0.1:9050 https://example.comThe h in socks5h stands for "hostname", meaning resolve at the SOCKS hop, not here. To see which exit country a circuit landed in, DNS Checker's IP endpoint returns the ISO country_code alongside the geo block in one call:
curl --socks5-hostname 127.0.0.1:9050 https://dnschkr.com/api/ip
# {"ip":"151.115.X.X","success":true,
# "geo":{"country":"United States","country_code":"US","flag_emoji":"🇺🇸", ...}}Python requests and httpx
Install the SOCKS extra once (pip install 'requests[socks]', which pulls in PySocks), then use the socks5h:// scheme. Forgetting the h is the single most common Python and Tor bug:
import requests
session = requests.Session()
session.proxies = {
"http": "socks5h://127.0.0.1:9050",
"https": "socks5h://127.0.0.1:9050",
}
r = session.get("https://check.torproject.org/api/ip", timeout=30)
print(r.json())
# {'IsTor': True, 'IP': '151.115.X.X'}A session reuses the connection across many URLs. httpx takes the same scheme after pip install 'httpx[socks]', and httpx.AsyncClient works the same way:
import httpx
with httpx.Client(proxy="socks5h://127.0.0.1:9050", timeout=30) as client:
print(client.get("https://check.torproject.org/api/ip").json())Node: fetch-socks and socks-proxy-agent
Node's built-in fetch has no SOCKS option of its own; it needs a SOCKS-capable undici dispatcher. Current undici ships Socks5ProxyAgent; the fetch-socks package shown here also works, which provides an undici-compatible dispatcher and resolves the hostname at the SOCKS hop (the socks5h behaviour):
npm install undici fetch-socksimport { fetch } from "undici";
import { socksDispatcher } from "fetch-socks";
const dispatcher = socksDispatcher({
type: 5, // SOCKS5
host: "127.0.0.1",
port: 9050,
});
const res = await fetch("https://check.torproject.org/api/ip", { dispatcher });
console.log(await res.json());
// { IsTor: true, IP: '151.115.X.X' }socks-proxy-agent is an https.Agent, not an undici Dispatcher, so it does not go into undici.fetch. It is the right tool for the agent-based APIs, axios and node:https. It accepts socks5:// or socks5h://; pick the second:
import axios from "axios";
import { SocksProxyAgent } from "socks-proxy-agent";
const agent = new SocksProxyAgent("socks5h://127.0.0.1:9050");
const r = await axios.get("https://check.torproject.org/api/ip", {
httpAgent: agent,
httpsAgent: agent,
});
console.log(r.data);With node:https, pass the same agent: https.get(url, { agent }, callback).
torsocks for programs without a proxy flag
When a program is not yours and does not speak SOCKS5, torsocks (and its older alias torify) routes its connections, DNS included, through Tor's SOCKS port:
torsocks curl https://check.torproject.org/api/ip
torsocks git clone https://github.com/user/repo.git
torsocks ssh user@example.comIt works by preloading a library (LD_PRELOAD on Linux, DYLD_INSERT_LIBRARIES on macOS) that hooks the process's socket calls, so it covers wget, git, ssh, nmap -sT, and most compiled binaries. It does not work for programs that bypass libc: Go binaries that use net directly, raw sockets, or anything statically linked. Those need their own SOCKS setting.
Spot a DNS leak
Watch your local resolver while the client runs:
# Terminal 1
sudo tcpdump -i any -n port 53 -A
# Terminal 2: the wrong flag, on purpose
curl --socks5 127.0.0.1:9050 https://example.comDNS packets asking for example.com mean the client is leaking. Switch to --socks5-hostname, rerun, and tcpdump should stay silent for the same request. A leak can be invisible from inside the box and obvious from the network, so test from a clean network namespace before trusting a setup. SafeSocks 1 and TestSocks 1 from the cheat sheet reject or log clients that resolve DNS locally.
Force a new Tor circuit with NEWNYM
NEWNYM is the control-port signal that tells the daemon to stop using current circuits for new streams and build fresh ones. New requests then go over fresh circuits instead of the old ones (Tor can keep the same entry guard), without disturbing in-flight streams. In practice that usually means a different middle and exit relay, but the control spec only promises clean circuits, not a different exit IP. That is what you want when scraping behind Tor and you have hit a rate limit. It needs the ControlPort block from the cheat sheet above, with one auth method:
# /etc/tor/torrc
ControlPort 9051
# Option A: cookie auth (preferred locally)
CookieAuthentication 1
CookieAuthFileGroupReadable 1
# Option B: password auth (use if controller runs elsewhere)
# HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4CCookie auth is cleaner on the same host because filesystem permissions handle who can read the cookie. Password auth is the right answer when the controller process runs as a different user, or on a different machine over an SSH tunnel. Generate the hash with Tor itself, paste the whole 16:... string into HashedControlPassword, then reload as shown in Where torrc lives:
tor --hash-password 'yourpassword'
# 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4CSend NEWNYM from a raw socket
No dependencies. With HashedControlPassword set, the password goes in plaintext over the local socket (it is localhost, that is fine):
{
echo "AUTHENTICATE \"yourpassword\""
echo "SIGNAL NEWNYM"
echo "QUIT"
} | nc 127.0.0.1 9051Expected output:
250 OK
250 OK
250 closing connection
Three 250s mean: authenticated, signal accepted, clean disconnect. Anything else is a problem. For cookie auth, read the cookie file and pass it hex-encoded:
COOKIE=$(xxd -c 256 -p /var/lib/tor/control_auth_cookie)
{
echo "AUTHENTICATE $COOKIE"
echo "SIGNAL NEWNYM"
echo "QUIT"
} | nc 127.0.0.1 9051The cookie path follows your DataDirectory: /var/lib/tor/control_auth_cookie on most Debian and Ubuntu installs, /opt/homebrew/var/lib/tor/control_auth_cookie on Apple Silicon Homebrew.
Send NEWNYM with Python stem
stem is the official Python controller for Tor (pip install stem). It gives cleaner error messages and type-safe signal names, and handles cookie auth transparently:
from stem import Signal
from stem.control import Controller
with Controller.from_port(port=9051) as controller:
controller.authenticate() # cookie or no auth; pass password=... for HashedControlPassword
controller.signal(Signal.NEWNYM)
print("New circuit signalled.")For password auth, call controller.authenticate(password="yourpassword"); stem does not read a password from anywhere else, and without one it skips password auth and raises MissingPassword if that was the only option. With ControlSocket set in torrc, swap Controller.from_port(port=9051) for Controller.from_socket_file("/var/run/tor/control"); the rest of the API is the same.
Interactively, nyx (the terminal Tor monitor, formerly arm, apt install nyx or brew install nyx) sends NEWNYM when you press m and choose "new identity", and lets you watch the circuit list update in real time.
Verify the circuit rotated
NEWNYM is fire-and-forget: Tor returns 250 OK whether or not new circuits build. Check the exit IP before and after:
# Before
torsocks curl https://check.torproject.org/api/ip
# {"IsTor":true,"IP":"185.X.X.X"}
# Send NEWNYM
echo -e "AUTHENTICATE \"yourpass\"\nSIGNAL NEWNYM\nQUIT" | nc 127.0.0.1 9051
# Wait at least 10 seconds (see rate limit below), then check
sleep 12
torsocks curl https://check.torproject.org/api/ip
# {"IsTor":true,"IP":"94.X.X.X"}A different IP confirms the rotation. Sometimes the new circuit picks the same exit by chance, so try a couple of NEWNYMs before concluding it failed.
The 10-second NEWNYM rate limit
The limit is purely client-side: Tor compiles in a MAX_SIGNEWNYM_RATE constant of 10 seconds, so at most one NEWNYM every 10 seconds actually rotates your circuits. Extra signals inside that window are not dropped by relays; your own Tor process coalesces and defers them. Fire ten in a tight loop and only the first takes effect now; the rest collapse into one delayed rotation.
For faster rotation, run multiple Tor instances on different SOCKS and control ports and round-robin across them:
# /etc/tor/torrc-a
SocksPort 9050
ControlPort 9051
CookieAuthentication 1
DataDirectory /var/lib/tor-a
# /etc/tor/torrc-b
SocksPort 9060
ControlPort 9061
CookieAuthentication 1
DataDirectory /var/lib/tor-btor -f /etc/tor/torrc-a &
tor -f /etc/tor/torrc-b &Alternate which SOCKS port your scraper hits per request and rotate each instance on its own ten-second cadence.
What NEWNYM does not change
NEWNYM marks all current circuits dirty, so new streams get fresh circuits (normally through different middle and exit relays, though a repeat exit is possible), and returns immediately while construction happens in the background. It does not:
- Change your entry guard. Long-lived guards are deliberate; rotating them on every NEWNYM would defeat their security properties. Forcing a new guard means deleting the
statefile in theDataDirectoryand restarting, which is slow and rarely what you want. - Close existing streams. An open TCP connection keeps its circuit until the application closes it.
- Affect hidden-service circuits, which rotate on their own schedule.
Stream isolation instead of NEWNYM
When you want a different circuit right now for one request, stream isolation is the lever, not NEWNYM. IsolateSOCKSAuth gives every unique SOCKS username/password pair its own circuit:
SocksPort 9050 IsolateDestAddr IsolateDestPort IsolateSOCKSAuthimport requests
def fetch(url, isolation_tag):
proxies = {
"http": f"socks5h://{isolation_tag}:x@127.0.0.1:9050",
"https": f"socks5h://{isolation_tag}:x@127.0.0.1:9050",
}
return requests.get(url, proxies=proxies, timeout=30)
# Each unique isolation_tag gets a separate circuit
r1 = fetch("https://check.torproject.org/api/ip", "request-1")
r2 = fetch("https://check.torproject.org/api/ip", "request-2")
print(r1.json()["IP"], r2.json()["IP"])
# Two different exit IPsIsolation suits high-throughput scraping; NEWNYM suits starting over with a fresh circuit pool for everything. The two compose.
FAQ
The path depends on how Tor was installed. On Debian/Ubuntu and most Linux distros it's /etc/tor/torrc. On macOS Homebrew it's /opt/homebrew/etc/tor/torrc on Apple Silicon and /usr/local/etc/tor/torrc on Intel. Tor Browser keeps its own at Browser/TorBrowser/Data/Tor/torrc inside the bundle.
You can also pass tor -f /path/to/torrc to run with an arbitrary config file, which is how multi-instance setups work.
No. Send SIGHUP and Tor re-reads the file in place: sudo systemctl reload tor on systemd, or sudo pkill -HUP tor elsewhere. Existing circuits keep working; new circuits use the new settings.
A few directives (port changes, DataDirectory moves) need a full restart because they affect bound sockets or on-disk layout.
None functionally. 9050 is the default for the standalone Tor daemon you install from your package manager; 9150 is what Tor Browser ships with so it doesn't collide with a system-wide tor on 9050. If both are running, point your scripts at one or the other consciously.
Two clean options. With CookieAuthentication 1, Tor writes a binary cookie file at $DataDirectory/control_auth_cookie on startup; your script reads it and sends AUTHENTICATE <hex-cookie>. With HashedControlPassword, you set the hash in torrc and your script sends AUTHENTICATE "yourpassword".
Cookie auth is preferred locally because filesystem permissions handle access control. Use a password when the controller runs on a different host. Worked examples of both are in the NEWNYM section.
At most one effective NEWNYM every 10 seconds (the compiled-in MAX_SIGNEWNYM_RATE). Extra signals inside that window still get 250 OK, but your Tor process coalesces them into one deferred rotation instead of rotating again immediately.
For higher rotation rates, run multiple Tor instances on different SOCKS and control ports and round-robin, or use IsolateSOCKSAuth stream isolation for per-request circuits.
NEWNYM marks current circuits dirty and builds new ones, but keeps the same guard relays and persistent state. Restarting Tor re-reads torrc, may rebuild the consensus, and (if state was deleted) selects new guards. Restart only when you've changed something that needs it or genuinely want a clean slate.
Tor Browser's "New Identity" button does roughly what NEWNYM does, plus it clears cookies, closes tabs, and rebuilds the SOCKS isolation. Programmatically you can connect to Tor Browser's bundled control port (default 9151, not 9051) and send the same signal, but only the network layer rotates; the browser's session state stays where it is.
Authentication failure. Either the password doesn't match HashedControlPassword, or the cookie bytes are wrong (often a hex-encoding mistake: the cookie is 32 raw bytes that need xxd -p conversion, not cat). stem handles the encoding automatically, so it is a quick way to rule out client-side bugs.
Yes. Each instance needs its own SocksPort, ControlPort, and DataDirectory. Start each with tor -f /etc/tor/torrc-foo and they coexist happily. This is the standard pattern for switching exit countries per command, one daemon per country, each on a different SOCKS port.
Don't, unless you have to. The control port can rotate circuits, read your guard list, and dump the descriptor cache. If you must, set HashedControlPassword, bind ControlPort to 127.0.0.1 only (the default), and SSH-tunnel from your client: ssh -L 9051:127.0.0.1:9051 user@host. Never bind ControlPort 0.0.0.0:9051.
The h stands for "hostname". With socks5h:// the client sends the hostname to the SOCKS proxy and Tor does the DNS lookup. With socks5:// the client resolves the name locally and sends a raw IP, so your ISP still sees the DNS query even though the TCP stream went through Tor. For Tor, always use socks5h:// (in curl, --socks5-hostname).
Anything TCP-based works: SSH, IMAP, IRC. UDP support is limited to some clients and specific Tor builds, so for practical purposes treat Tor as TCP-only.
Not directly. The built-in fetch does not take an agent. Use undici.fetch with a SOCKS dispatcher such as fetch-socks, or use axios or node:https, which accept a SocksProxyAgent.
Go's net/http ignores HTTP_PROXY for HTTPS unless HTTPS_PROXY is set too, and it does its own DNS resolution by default. For SOCKS5, give the standard http.Transport a proxy URL: Proxy: http.ProxyURL(&url.URL{Scheme: "socks5", Host: "127.0.0.1:9050"}). Go treats socks5 the same as socks5h, so the hostname is resolved by Tor, not locally. golang.org/x/net/proxy is only needed for a custom dialer. torsocks will not help, because Go bypasses libc.
The canonical reference is man tor on a host that has Tor installed, every directive has its earliest-version note. The web copy at torproject.org's manual page is the same content. If a directive isn't in your installed man page, your Tor is older than the directive.
See also
- Set Tor exit nodes by country (ExitNodes, ExcludeNodes): the country-pinning directives explained with worked torrc snippets, plus Five/Nine/14 Eyes blocks
- Tor Bridges Explained: obfs4, Snowflake, and meek: bridge directives and how to add them to torrc
- Host a v3 .onion Hidden Service with Tor: the hidden-service directives applied to a real onion site
Sources
Authoritative references this article was fact-checked against.
- Tor Project issue tracker #17688gitlab.torproject.org
- HiddenServiceSingleHopMode discussion, Tor Forumforum.torproject.org
- v2 onion service deprecation timeline, Tor blogblog.torproject.org
- The Tor Projectspec.torproject.org
- stem connection.py: authenticate() (Tor Project, GitHub)github.com
- curl man page (--socks5-hostname), curl.securl.se
- socks-proxy-agent, npmnpmjs.com
- fetch-socks (undici SOCKS dispatcher), npmnpmjs.com
- undici documentation, Node.jsundici.nodejs.org





