TechEarl

torrc Cheat Sheet: Complete Tor Configuration Reference

Every torrc directive worth knowing in 2026, grouped by what you're trying to do: SOCKS and control ports, circuit construction, country pinning, hidden services, bridges, logging, and performance tuning, plus routing curl, Python, and Node through the SOCKS proxy without DNS leaks and forcing a new circuit with NEWNYM over the control port.

Ishan KarunaratnePublished ⏱️ 14 min readUpdated
Share thisCopied
torrc cheat sheet: SOCKS ports, control port auth, circuits, country pinning, v3 hidden services, bridges, logging, and performance directives with examples.

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.

Network and SOCKS

SocksPort 9050Open a SOCKS5 proxy for applications on the given port. Default 9050. Tor Browser uses 9150 to coexist with a system tor on 9050.
SocksPort 0.0.0.0:9050Bind SOCKS to all interfaces (exposes the proxy on the network). Default is localhost only; only do this on a trusted LAN.
SocksPort 9050 IsolateDestAddr IsolateDestPortIsolate streams by destination, a separate circuit per host:port. Improves anonymity when one app talks to many destinations.
DNSPort 5353Run a Tor-internal DNS resolver on the given port. Use with `iptables` to force all DNS through Tor and prevent leaks.
AutomapHostsOnResolve 1Auto-map .onion and .exit lookups to virtual IPs so legacy apps that can't talk SOCKS5h still reach onion sites.
VirtualAddrNetworkIPv4 10.192.0.0/10The IP range used for AutomapHostsOnResolve. Defaults are fine; change only if it clashes with a real LAN range.
TransPort 9040Transparent proxy port. With `iptables`, force all TCP through Tor without per-app config. The Whonix gateway is the canonical use.

Control port and authentication

ControlPort 9051Open the control port, lets external programs (nyx, stem, your scripts) send signals like NEWNYM or query circuit state.
ControlSocket /var/run/tor/controlUnix-domain socket alternative to ControlPort. Preferred locally because filesystem permissions handle auth.
CookieAuthentication 1Authenticate to the control port using a cookie file Tor writes at start. Combined with `CookieAuthFileGroupReadable 1`, the cleanest local auth.
HashedControlPassword 16:...Password auth for the control port. Generate the hash with `tor --hash-password 'yourpass'` and paste the output here.
ControlPortWriteToFile /var/run/tor/control.txtWrite the bound port number to a file (useful when ControlPort is `auto`). Lets wrappers discover the chosen port.

Circuit construction

CircuitBuildTimeout 10Seconds to wait for a circuit to build before discarding it. Lower = faster failover, higher = more patient on slow links.
MaxCircuitDirtiness 600How long (seconds) a circuit may keep taking new streams after its first use. Lower means more circuit churn and less linkability between requests; it does not cut connections that are already open.
NewCircuitPeriod 30How often (seconds) Tor considers building a new clean circuit. Don't lower without good reason, circuit churn hurts performance.
NumEntryGuards 1Number of long-lived primary guard relays to use. With the default value 0, Tor learns this from the `guard-n-primary-guards-to-use` consensus parameter and falls back to 1 if it is unset. Higher = more entry-point exposure.
EnforceDistinctSubnets 1Refuse to build a circuit that includes two relays in the same /16. On by default. Disable only for testing.
UseEntryGuards 1Use the guard set rather than a fresh entry per circuit. Default. Disable only for research; defeats important security properties.

Country pinning

ExitNodes {us},{de},{nl}Allowed exit countries (last hop). Two-letter ISO codes in braces. See the full country-code table for every code Tor accepts.
EntryNodes {se},{ch}Allowed entry guard countries (first hop). Most users should leave this alone, guard pinning weakens long-term security properties.
ExcludeNodes {cn},{ru},{ir},{kp}Banned countries for any hop in the circuit. Combined with `StrictNodes 1`, it becomes a hard ban; without it, Tor may still use an excluded relay for things like directory fetches and onion-service connections.
ExcludeExitNodes {us},{gb},{ca},{au},{nz}Ban countries only from being the exit. Useful when you want to avoid a jurisdiction terminating the connection but don't mind it in the middle.
StrictNodes 1Make ExcludeNodes a hard rule, even if it breaks connections. It applies only to ExcludeNodes: ExitNodes, ExcludeExitNodes and EntryNodes are unaffected.
GeoIPFile /usr/share/tor/geoipPath to the IPv4 GeoIP database Tor uses to map relays to countries. Override if you maintain your own.
GeoIPv6File /usr/share/tor/geoip6Path to the IPv6 GeoIP database. Same idea, separate file.

Hidden services (v3 onion)

HiddenServiceDir /var/lib/tor/myservice/Directory where Tor stores the .onion private key and hostname for this service. Permissions must be 700 and owned by the tor user.
HiddenServicePort 80 127.0.0.1:8080Map public onion port 80 to a local service at 127.0.0.1:8080. Add one line per port you want to expose.
HiddenServiceVersion 3Use the modern v3 onion address format (56 chars + .onion). v2 was removed in Tor 0.4.6, so this is implicit, but spelling it out makes the config explicit.
HiddenServiceNumIntroductionPoints 6Number of introduction points the service advertises. More = more resilience under load, more rendezvous traffic.
HiddenServiceMaxStreams 0Per-circuit stream cap. 0 means unlimited. Set a low value (e.g., 10) for services that don't need many concurrent connections to mitigate burst abuse.
HiddenServiceSingleHopMode 1Single-onion service: skip the rendezvous on the service side. Has no effect on its own. It also requires `HiddenServiceNonAnonymousMode 1`, and with single-hop mode enabled Tor refuses to start unless `SocksPort 0` is also set. Faster, but no anonymity for the service operator.

Bridges and pluggable transports

UseBridges 1Route entry traffic through bridges instead of the public guard set. Required when your ISP blocks the public Tor relays.
Bridge obfs4 192.0.2.1:443 FINGERPRINT cert=... iat-mode=0An obfs4 bridge line. Get the full line from bridges.torproject.org or by emailing bridges@torproject.org.
Bridge snowflake 192.0.2.3:1 2B280B23E1107BB62...Snowflake bridge. The exact IP is fake (Snowflake hops via WebRTC volunteers), but the line is still required for the daemon.
ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxyTell Tor where the obfs4 transport binary lives. Path varies by distro: `/usr/bin/obfs4proxy` on Debian, `/opt/homebrew/bin/obfs4proxy` on macOS Homebrew.
ClientTransportPlugin snowflake exec /usr/bin/snowflake-clientSame idea for Snowflake. The client opens a WebRTC tunnel to a volunteer browser before reaching the actual relay.

Performance and bandwidth

RelayBandwidthRate 1 MBytesWhen running a relay, soft cap on average bandwidth. Use `KB`, `MB`, `GB` suffixes.
RelayBandwidthBurst 2 MBytesAllowed burst on top of `RelayBandwidthRate`. Tor smooths to the rate over time.
BandwidthRate 200 KBytesClient-side bandwidth cap. Affects both relay and client traffic if you're running both.
BandwidthBurst 400 KBytesClient-side burst cap, same pattern as relay version.
KeepalivePeriod 60Seconds between keepalive cells on connections. Lower if NAT is dropping idle connections.
AvoidDiskWrites 1Write to disk less often than usual. Meant for flash storage with limited write cycles; state is still saved, just less frequently.

Logging

Log notice file /var/log/tor/notices.logSend notice-level and above to a file. `notice` is the default; raise to `warn` or `err` to quiet a noisy daemon.
Log info file /var/log/tor/info.logVerbose logging, useful while debugging circuit issues, very chatty otherwise.
Log debug file /var/log/tor/debug.logFull firehose. Will fill a disk if left on. Set a logrotate policy if you must keep it on.
Log notice syslogSend notice-level logs to syslog instead of a file. Plays nicely with journalctl on systemd hosts.
DataDirectory /var/lib/torWhere Tor keeps its descriptor cache, state file, and (with `AvoidDiskWrites 0`) any persistent state. Permissions matter, must be owned by the tor user.
PidFile /run/tor/tor.pidPath Tor writes its PID to. systemd usually handles this; only set manually for non-systemd setups.

Safety and policy

ExitPolicy reject *:*Refuse to act as an exit. A relay is not an exit by default (ExitRelay is auto, which means off unless you set an exit policy), but setting this makes the intent explicit.
ExitPolicy accept *:80,accept *:443,reject *:*Allow exits only to web ports. Every comma-separated entry needs its own accept or reject; without the second accept, tor 0.4.9 rejects the config. Setting any ExitPolicy turns the relay into an exit.
SafeLogging 1Scrub log lines of potentially sensitive data (IP addresses, .onion names). On by default since Tor 0.2.x.
SafeSocks 1Reject SOCKS connections that don't use SOCKS5 with hostname resolution (i.e., reject DNS-leaking apps). Worth enabling for any public proxy.
TestSocks 1Log a warning for every SOCKS connection that resolves DNS locally rather than through Tor. Useful while auditing apps for DNS leaks.

Where torrc lives

The Tor daemon reads its config from a single text file. Locations vary by how you installed it.

InstallPath
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):

bash
# systemd-managed
sudo systemctl reload tor

# everything else (sends SIGHUP)
sudo pkill -HUP tor

A 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:

text
# 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

text
# 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.log

The 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

text
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.log

Three 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:

bash
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

bash
# 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.com

The 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:

bash
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:

python
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:

python
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):

bash
npm install undici fetch-socks
javascript
import { 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:

javascript
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:

bash
torsocks curl https://check.torproject.org/api/ip
torsocks git clone https://github.com/user/repo.git
torsocks ssh user@example.com

It 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:

bash
# 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.com

DNS 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:

text
# /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:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C

Cookie 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:

bash
tor --hash-password 'yourpassword'
# 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C

Send 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):

bash
{
  echo "AUTHENTICATE \"yourpassword\""
  echo "SIGNAL NEWNYM"
  echo "QUIT"
} | nc 127.0.0.1 9051

Expected output:

code
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:

bash
COOKIE=$(xxd -c 256 -p /var/lib/tor/control_auth_cookie)
{
  echo "AUTHENTICATE $COOKIE"
  echo "SIGNAL NEWNYM"
  echo "QUIT"
} | nc 127.0.0.1 9051

The 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:

python
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:

bash
# 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:

text
# /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-b
bash
tor -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 state file in the DataDirectory and 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:

text
SocksPort 9050 IsolateDestAddr IsolateDestPort IsolateSOCKSAuth
python
import 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 IPs

Isolation 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

Sources

Authoritative references this article was fact-checked against.

TagsTORtorrcNEWNYMControl PortstemNetworkingPrivacyCheat SheetSOCKS5

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Systems and Network Architect · Chief Technology Officer

Systems and network architect and Chief Technology Officer with more than two decades designing, building, and running production software, cloud and network architecture, Linux systems, and the bare metal underneath them, and lately working AI into the stack. A US Army veteran who served in Operation Iraqi Freedom. What I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

grep cheat sheet with examples: -i, -w, -v, multiple patterns, recursive search, counting and unique counts, awk columns, BRE vs ERE vs PCRE, BSD vs GNU.

grep Cheat Sheet: Examples, Regex Flags, and macOS BSD Differences

A grep reference with working examples for every everyday task: case-insensitive and whole-word search, multiple patterns, inverting, counting lines vs occurrences, unique counts, printing a column with awk, and BRE vs ERE vs PCRE, the macOS BSD differences, PowerShell equivalents, and grep vs ripgrep vs ag.

docker run cheat sheet: every flag by job, core Docker commands, and run recipes for MySQL, MariaDB, PostgreSQL, Redis, Nginx, PHP, WordPress and more.

docker run Cheat Sheet: Flags and Common Patterns

Every docker run flag I actually use, grouped by job, the rest of the Docker CLI on one cheat sheet, and copy-paste recipes for Nginx, Apache, PHP, MySQL, MariaDB, PostgreSQL, MongoDB, Redis, Elasticsearch, MinIO, WordPress, Adminer and a plain Linux shell.