A middle relay is the easiest useful thing you can do for the Tor network. It never acts as the source of anyone's traffic on the open internet, so you won't get abuse complaints, and a cheap VPS with a decent unmetered connection is enough. This guide covers a non-exit relay on Debian or Ubuntu, which is what most operators run. If you want to run an exit, read Middle Relays, Exit Relays and Exit Policies first and talk to your provider.

Before you start

You need a server that stays up. A relay that drops off for hours every few days won't get the Stable or Guard flags and will be less useful. You also need bandwidth you're willing to give away, in both directions, since relays forward what they receive. A relay with a few megabits per second barely registers; the Tor Project's relay requirements page lists the current minimums, and they're worth checking because they change as the network grows.

Read your hosting provider's terms of service. Most VPS providers allow non-exit relays; a few ban Tor entirely. It's also good for the network if you avoid the very largest hosting providers, since too many relays in one company's data centres concentrate risk. Relay Search on Tor Metrics shows which providers are already crowded.

Install tor from the Tor Project's repository

Distribution packages of tor are often behind. For a relay, use the Tor Project's own Debian repository so you get security fixes promptly. The steps are on the official repository page; compare the key fingerprint there with what you download. On a current Debian it looks like this:

sudo apt install apt-transport-https gpg wget
wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc \
  | gpg --dearmor | sudo tee /usr/share/keyrings/deb.torproject.org-keyring.gpg >/dev/null

echo "deb [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org $(lsb_release -cs) main" \
  | sudo tee /etc/apt/sources.list.d/tor.list

sudo apt update
sudo apt install tor deb.torproject.org-keyring nyx

Set up unattended security upgrades while you're at it. An outdated relay eventually gets dropped from the consensus when its version stops being recommended, and before that it's just a liability.

A minimal torrc

Replace the contents of /etc/tor/torrc with something like this:

Nickname      quietmiddle01
ContactInfo   relays AT example DOT org
ORPort        443
ORPort        [2001:db8::10]:443
ExitRelay     0
SocksPort     0

# Optional: limit bandwidth
RelayBandwidthRate  20 MBytes
RelayBandwidthBurst 40 MBytes

# Optional: monthly cap
#AccountingMax   4 TBytes
#AccountingStart month 1 00:00

# For nyx
ControlPort 9051
CookieAuthentication 1

Some notes on those lines. The nickname is public and limited to 19 alphanumeric characters. ContactInfo should be a real way to reach you; obfuscating the email is fine and normal. Port 443 gets through more restrictive client firewalls than the traditional 9001, but if something else on the box already uses 443, pick another. The IPv6 line is optional, and you'll need to replace the documentation address with yours. ExitRelay 0 is the default these days, but writing it down makes your intent obvious to future you. SocksPort 0 stops the relay from also acting as a client proxy.

Bandwidth values are in bytes, not bits, which trips up nearly everyone once. 20 MBytes is about 160 Mbit/s. If your provider meters traffic, use AccountingMax instead of or as well as a rate limit: the relay will hibernate once it hits the cap for the period. Note that AccountingMax counts each direction separately against the limit, so read the torrc options article or the man page before relying on it for a hard billing cap.

If you run more than one relay, declare them as a family so clients never use two of yours in one circuit. Traditionally that's a MyFamily line listing every relay's fingerprint, on every relay. Newer tor versions add a simpler family key mechanism; check the current docs for your version.

Start it and check the logs

sudo systemctl restart tor@default
sudo journalctl -u tor@default -f

Within a minute or two you want to see a line like:

Self-testing indicates your ORPort is reachable from the outside. Excellent. Publishing server descriptor.

If you get a warning that the ORPort isn't reachable, it's almost always a firewall: the provider's, then your own. Open the port for inbound TCP and restart. Your relay's fingerprint is in /var/lib/tor/fingerprint. Paste it into Relay Search; after a few hours (once the authorities have voted it in) it should show up as Running.

What the first weeks look like

Don't panic when nothing happens. A brand new relay goes through stages. For the first few days it's unmeasured and gets very little traffic. Then the bandwidth authorities measure it and traffic climbs. After about a week or more of good uptime it may earn the Guard flag, at which point you'll often see traffic dip, because the relay is now used less as a middle and clients only slowly adopt new guards. Over the next weeks and months it settles. The Tor Project described these stages years ago in a blog post on the lifecycle of a new relay, and it's still broadly how things go.

Run sudo -u debian-tor nyx to watch live bandwidth, flags, connections and log messages. It's the quickest way to check the relay is healthy without trawling journalctl.

Ongoing care

Keep the server patched, and keep the keys. The directory /var/lib/tor/keys holds your relay's identity. If you move to a new server, copy that directory across (with the right ownership, debian-tor:debian-tor) and the relay keeps its reputation and flags. Lose it and you start from zero.

Subscribe to the tor-relays mailing list, at least for a while. Most operational problems people hit have been discussed there, and important announcements about deprecated versions or new requirements show up there first.

One thing operators sometimes don't expect: some services block all known Tor relay IPs, not just exits, because they download the full relay list rather than the exit list. If you run a relay on an IP that you also use for something else, like a mail server or your home connection, that something else may get blocked. Give the relay its own address if you can.

If your connection is too modest for a relay, a bridge or a Snowflake proxy might fit better, and both help people in censored countries directly. See Running a Snowflake Proxy, or set BridgeRelay 1 with an obfs4 transport for a private bridge.

#tor-relay #torrc #linux #volunteering #sysadmin