Raspberry Pi Tor Gateway – Anonymous Browsing with AnoPi
Anonymous browsing – not just on one device, but for everything that connects to a WiFi network: that’s exactly what a Tor gateway based on the Raspberry Pi delivers, also known as Onion Pi or AnoPi. The Raspberry Pi creates its own WiFi network and routes all traffic from connected devices through the Tor network – without installing anything on the devices themselves. That’s handy for guests, for test devices, or for any situation where you don’t want to reveal your IP address and location.
Update 08/2026: This tutorial has been completely reworked for current Raspberry Pi OS. NetworkManager (nmcli) replaces hostapd and dhcpcd.conf, dnsmasq now acts purely as a DHCP server, and the Tor configuration uses current syntax – the old options TransListenAddress and DNSListenAddress no longer exist in current Tor versions.
- Set the WiFi country code:
sudo raspi-config nonint do_wifi_country US - Create the access point via nmcli – with
ipv4.method manual, deliberately without NAT - Configure dnsmasq as a pure DHCP server (
port=0) - Install Tor, enable
TransPortandDNSPortin torrc - Install iptables, use it to redirect WiFi traffic to Tor and save the rules with
netfilter-persistent save
What Is Tor and How Does It Work?
Tor (“The Onion Router”) is free software for anonymous browsing and for bypassing internet censorship. The Tor network consists of thousands of volunteer-run nodes: your traffic is routed, encrypted, through at least three of these nodes until the last one (the exit node) decrypts it and passes it on to the actual destination. No single node knows both the sender and the destination at the same time – which is what conceals your location and activity.

How the Tor Gateway Works
The Raspberry Pi needs two network interfaces: the Ethernet port (eth0) connects to your home router and is the outbound path towards the internet. The built-in WiFi (wlan0) provides the access point your devices connect to. Tor sits in between: all TCP traffic from the WiFi network is redirected via iptables to Tor’s TransPort, and all DNS queries to the DNSPort – so name resolution is anonymised through Tor as well.
A key design principle of this guide: there is no NAT and no IP forwarding. Anything Tor doesn’t intercept (UDP packets, for example) is simply dropped instead of slipping past the Tor network onto the internet. In security terms this is called “fail closed” – when in doubt, no connection is better than an unanonymised one.

nmcli device wifi hotspot command is all it takes. But that command uses ipv4.method shared – NetworkManager automatically sets up NAT and would route any traffic Tor doesn’t intercept directly and unanonymised to the internet. For a Tor gateway, that’s a leak. That’s why we create the access point manually here, without NAT.
What You Need
- A Raspberry Pi with built-in WiFi – a Raspberry Pi 4* or Raspberry Pi 5* is ideal; a Pi 3 is fine for normal browsing speeds too
- A microSD card* (at least 8 GB, 32 GB recommended) for the OS
- A suitable power supply, e.g. the official 27W PSU* for the Pi 5
- An Ethernet cable* to connect to your router
- A router with a free LAN port
Preparation: Install Raspberry Pi OS
Install Raspberry Pi OS Lite (64-bit recommended) on the microSD card using the Raspberry Pi Imager. In the Imager’s customisation step, enable SSH and create a user with a strong password – current images no longer ship with a default “pi” user. The complete basic setup is covered in our guide Installing and setting up Raspberry Pi.
Connect the Raspberry Pi to your router via Ethernet cable, log in via SSH, and bring the system up to date:
sudo apt update && sudo apt full-upgrade -y
sudo reboot
Step 1: Set the WiFi Country Code
Before the access point is allowed to transmit, the WiFi country code must be set – otherwise the radio stays restricted for regulatory reasons and the access point won’t start:
iw reg get
# If it says "country 00", the country code is missing!
If it’s missing, set it with a single command (US for the United States, GB for the UK, DE for Germany):
sudo raspi-config nonint do_wifi_country US
Step 2: Create the Access Point with nmcli
Since Raspberry Pi OS moved to a Debian 12 base, NetworkManager handles all networking – you no longer need hostapd or entries in dhcpcd.conf. We create the access point with a static IP address in the 192.168.179.0/24 subnet (if your home network already uses this subnet, pick a different one):
sudo nmcli con add type wifi ifname wlan0 con-name TorGateway autoconnect yes \
ssid AnoPi 802-11-wireless.mode ap 802-11-wireless.band bg 802-11-wireless.channel 6 \
wifi-sec.key-mgmt wpa-psk wifi-sec.psk "YourSecurePassword" \
ipv4.method manual ipv4.addresses 192.168.179.1/24 ipv6.method disabled
sudo nmcli con up TorGateway
The key parameters explained:
802-11-wireless.mode ap– wlan0 operates as an access point with the SSID AnoPi and WPA2 encryption (password at least 8 characters)ipv4.method manual– the Pi gets the fixed address 192.168.179.1, but deliberately notshared: no automatic NAT, no leak around Toripv6.method disabled– our Tor redirect works with IPv4; with no IPv6 in the WiFi network, nothing can leak that way eitherautoconnect yes– the access point starts automatically after every boot
The “AnoPi” WiFi network is now visible. There’s no internet on it yet though – DHCP (step 3) and Tor (steps 4 and 5) are still missing.
Step 3: Set Up dnsmasq as DHCP Server
So that connected devices automatically receive an IP address, we install dnsmasq – but only as a DHCP server. We disable its DNS function completely with port=0, because DNS will later be answered by Tor itself on port 53:
sudo apt install dnsmasq -y
sudo nano /etc/dnsmasq.conf
Add the following block at the end of the file:
interface=wlan0
bind-dynamic
port=0
dhcp-range=192.168.179.10,192.168.179.150,255.255.255.0,12h
dhcp-option=option:router,192.168.179.1
dhcp-option=option:dns-server,192.168.179.1
bind-dynamic ensures dnsmasq finds wlan0 even if NetworkManager activates the interface slightly after dnsmasq during boot. The two dhcp-option lines hand out the Raspberry Pi as gateway and DNS server to all clients. Then restart the service:
sudo systemctl restart dnsmasq
sudo systemctl enable dnsmasq
Step 4: Install and Configure Tor
sudo apt install tor -y
sudo nano /etc/tor/torrc
Add the following lines at the end of the file:
VirtualAddrNetworkIPv4 10.192.0.0/10
AutomapHostsOnResolve 1
AutomapHostsSuffixes .onion,.exit
TransPort 0.0.0.0:9040
DNSPort 0.0.0.0:53
The TransPort is Tor’s transparent proxy entry point for TCP connections, and the DNSPort resolves DNS queries anonymously through Tor. Binding to 0.0.0.0 has a practical reason: Tor then starts cleanly even if wlan0 isn’t fully up yet during boot. On a trusted home network this is uncritical – if you prefer strict binding, use 192.168.179.1:9040 and 192.168.179.1:53 instead and restart Tor manually after boot if needed.
Enable Tor and check its status:
sudo systemctl enable --now tor
# Is Tor running and listening on its ports?
sudo ss -tlnp | grep tor
journalctl -u tor@default -e
You should see the line Bootstrapped 100% (done) in the log – Tor is then connected to the network.
Step 5: Redirect WiFi Traffic to Tor with iptables
Raspberry Pi OS Lite only ships with nftables – the iptables command isn’t there yet. So install it first, together with iptables-persistent, which keeps your rules across reboots later on. When the installer asks whether to save the current rules, say Yes for IPv4 and No for IPv6 – you’ll save the actual rules at the end of this step:
sudo apt install iptables iptables-persistent -y
Now for the redirection: everything coming from the WiFi network should end up at Tor. The four rules in detail: access to the Pi itself (e.g. SSH) stays untouched, DNS queries go to Tor’s DNSPort – including from devices with a hardcoded third-party DNS like 8.8.8.8 – and every TCP connection attempt lands on the TransPort:
sudo iptables -t nat -A PREROUTING -i wlan0 -d 192.168.179.1 -j RETURN
sudo iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j REDIRECT --to-ports 53
sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 53 -j REDIRECT --to-ports 53
sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports 9040
That’s all it takes: IP forwarding stays off, and there is no NAT rule. UDP traffic (other than DNS) is dropped as a result – that’s intentional, since Tor only transports TCP anyway. Browsers that first try QUIC (HTTP/3 over UDP) automatically fall back to TCP; you won’t notice a thing.
To make the rules survive every reboot, save them permanently:
sudo netfilter-persistent save
Step 6: Test the Tor Gateway
Connect a device to the “AnoPi” WiFi network and open the Tor Project’s official check page:
https://check.torproject.org
If it says “Congratulations. This browser is configured to use Tor”, your gateway is working. On the Raspberry Pi you can additionally verify that the redirection is active – the packet counters of the rules must increase while browsing:
sudo iptables -t nat -L PREROUTING -v -n
Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| “AnoPi” WiFi network not appearing | Country code missing or connection inactive | Check iw reg get (country 00?), then sudo nmcli con up TorGateway |
| Connected but no IP address | dnsmasq not running or not binding wlan0 | sudo systemctl status dnsmasq; check that bind-dynamic is in the config |
| Got an IP, but no page loads | Tor not running or not connected | journalctl -u tor@default -e – wait for “Bootstrapped 100%”, or sudo systemctl restart tor |
| check.torproject.org says “not using Tor” | iptables rules missing or wrong interface | sudo iptables -t nat -L PREROUTING -v -n – are the REDIRECT counters increasing? |
| Everything gone after reboot | iptables rules not saved | Run sudo netfilter-persistent save after every rule change |
| Very slow connection | Normal Tor latency or a slow circuit | Tor is inherently slower; sudo systemctl restart tor builds new circuits |
Security: What the Tor Gateway Does – and What It Doesn’t
The gateway anonymises at the network level: your IP address and location stay hidden, and your ISP only sees encrypted Tor traffic. What it cannot do is protect you at the application level. If you log in to Google, Amazon, or social media accounts, those services can obviously still identify you – cookies and browser fingerprinting work right through Tor.
Important: The Tor Project itself strongly discourages running Tor as a transparent proxy – and that is exactly what this gateway is. The apps on your devices have no idea they are going through Tor: they keep sending identifiers, logins and cookies, and they share the same Tor connections, so your activity can be linked together. For real anonymity, use the Tor Browser or a system built for it such as Whonix. The gateway is better suited to hiding the IP address and location of devices that can’t run the Tor Browser.
- For serious anonymity, additionally use the Tor Browser – it also protects against fingerprinting and isolates websites into separate circuits
- Don’t use logins or email addresses over the gateway that could reveal your identity
- The connection is encrypted up to the exit node – beyond that, the website’s normal transport encryption takes over. As always, look for HTTPS, which fortunately is the standard today
- Tor is also used by shady actors; some websites block Tor exit nodes or show extra captchas – that’s normal
By the way: Don’t need Tor at all, just a regular WiFi hotspot – for hotels or camping? Then check out our guide Raspberry Pi as WiFi Hotspot – Travel Router Setup.
Frequently Asked Questions about the Raspberry Pi Tor Gateway
Tor conceals your IP address and location, but does not provide complete anonymity. Don’t log in to accounts that know your identity. For maximum anonymity: combine Tor with the Tor Browser and avoid cookies/browser fingerprinting.
A Pi with built-in WiFi and Ethernet (Pi 3, 4, 5); the Zero 2 W needs a USB Ethernet adapter. A Pi 3 is enough for normal browsing; for several devices or better throughput, go for the Pi 4 or Pi 5 – Gigabit Ethernet and significantly more CPU power for Tor’s encryption.
Usually well under 2 MB/s and quite variable – Tor Metrics puts the median at roughly 0.5 to 1.5 MB/s, because traffic is routed through multiple nodes worldwide. Normal browsing and messaging work fine, HD video streaming is usually not practical.
No. On current Raspberry Pi OS, NetworkManager manages the network – /etc/dhcpcd.conf is still there but no longer used, hostapd is no longer needed, and the Tor options TransListenAddress/DNSListenAddress have been removed. Don’t install dhcpcd retroactively either, or two services will manage wlan0 at the same time.
nmcli device wifi hotspot uses ipv4.method shared with automatic NAT – traffic Tor doesn’t intercept would leak to the internet unanonymised. That’s why the access point is created with ipv4.method manual: without NAT and forwarding, anything that doesn’t go through Tor is dropped (fail closed).
