Home » How to Set up a Raspberry Pi as a Tor proxy

How to Set up a Raspberry Pi as a Tor proxy

by shedboy71

Setting up a Raspberry Pi as a Tor proxy allows you to anonymize your internet traffic and enhance privacy.

What is a Tor Proxy

A Tor proxy is a middleman between a client, such as a web browser, and a service, like a web server, that uses the Tor network to encrypt and anonymize internet traffic.

How it Works: When using a Tor proxy, the client sends a message to the proxy, which then passes the request through the Tor network, a series of volunteer-operated servers, before reaching the destination server. This process helps protect the user’s identity and location by making it difficult for the destination server to know who is making the request.

Comparison to Other Proxies: Unlike simple proxy providers, Tor proxy does not create a single point of failure, as the traffic is passed through at least three different servers, each with its own layer of encryption, making it harder for anyone to intercept and read the traffic.

Tor Proxy vs Traditional Proxies: Traditional proxies may see the user’s traffic and personal details, whereas Tor proxy ensures that each relay only sees the previous and next hop, not the entire path, providing better anonymity and privacy.

Accessing Onion Sites: Some Tor proxies allow users to access onion sites, which are websites that can only be accessed through the Tor network, without having to install Tor on their device.

Security Benefits: Using a Tor proxy can add an extra layer of security to web requests, as the traffic is encrypted and passed through multiple relays, making it more difficult for hackers or surveillance agencies to intercept and read the traffic.

This tutorial will guide you through the process step by step of setting this on a  Raspberry Pi.

Requirements

  1. A Raspberry Pi (any model, though newer models are recommended for better performance. I used a raspberry Pi 4).
  2. Raspberry Pi OS (Lite version van be used and is sufficient).
  3. A microSD card (8GB or larger).
  4. Power supply and internet connection (Ethernet preferred, Wi-Fi is acceptable).
  5. Basic familiarity with Linux and networking.

 

Step 1: Prepare Your Raspberry Pi

Install Raspberry Pi OS

  1. Download and install Raspberry Pi Imager.
  2. Flash Raspberry Pi OS (Lite) to the microSD card.
  3. Enable SSH:
    • After flashing, create a file named ssh (no extension) in the boot directory of the microSD card.
  4. Set up Wi-Fi (if not using Ethernet):
    • Create a file named wpa_supplicant.conf in the boot directory and add:
      country=US
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      update_config=1
      network={
          ssid="Your_SSID"
          psk="Your_PASSWORD"
      }
      

      Replace Your_SSID and Your_PASSWORD with your Wi-Fi credentials.

  5. Insert the microSD card into the Raspberry Pi and power it on.

Access the Raspberry Pi

  1. Find the Pi's IP address using your router or a network scanner.
  2. SSH into the Pi:
    ssh pi@<IP_ADDRESS>
    

    Default username: pi, password: raspberry.

  3. Update and upgrade the system:
    sudo apt update && sudo apt upgrade -y
    

Step 2: Install Tor

  1. Install the Tor package:
    sudo apt install tor -y
    
  2. Check if Tor is running:
    systemctl status tor
    

    If it’s not running, start and enable it:

    sudo systemctl start tor
    sudo systemctl enable tor
    

Step 3: Configure Tor as a Proxy

  1. Edit the Tor configuration file:
    sudo nano /etc/tor/torrc
    
  2. Add or uncomment the following lines:
    SocksPort 9050
    SocksPolicy accept 192.168.0.0/16
    ControlPort 9051
    HashedControlPassword <hashed_password>
    
    • Replace 192.168.0.0/16 with your local network range.
    • The HashedControlPassword is optional if you want to control Tor with a password.
  3. Generate a hashed password for Tor (if using):
    tor --hash-password YourPassword
    

    Replace YourPassword with a secure password. Copy the hashed output and paste it into the HashedControlPassword line.

  4. Restart Tor to apply changes:
    sudo systemctl restart tor
    

Step 4: Set Up iptables for Traffic Routing

  1. Enable IPv4 forwarding:
    sudo nano /etc/sysctl.conf
    

    Uncomment or add:

    net.ipv4.ip_forward=1
    

    Apply changes:

    sudo sysctl -p
    
  2. Configure iptables for routing traffic through Tor:
    sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports 9050
    sudo iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    sudo iptables -A OUTPUT -o lo -j ACCEPT
    sudo iptables -A OUTPUT -o eth0 -p tcp --dport 9050 -j ACCEPT
    sudo iptables -A OUTPUT -d 192.168.0.0/16 -o eth0 -j ACCEPT
    sudo iptables -A OUTPUT -j REJECT
    
  3. Save iptables rules:
    sudo sh -c "iptables-save > /etc/iptables/rules.v4"
    

Step 5: Configure Your Network

Option 1: Use the Raspberry Pi as a Wi-Fi Access Point

  1. Install hostapd and dnsmasq:
    sudo apt install hostapd dnsmasq -y
    
  2. Configure the access point (refer to a detailed Wi-Fi Access Point setup tutorial).

Option 2: Set the Raspberry Pi as a Network Gateway

Configure devices on your network to use the Raspberry Pi's IP address as their SOCKS5 proxy with port 9050.

Step 6: Test the Tor Proxy

  1. From a connected device, configure the SOCKS5 proxy:
    • Proxy IP: Raspberry Pi's IP.
    • Proxy Port: 9050.
  2. Test connectivity:

Optional Enhancements

Monitor Tor Traffic

  • Install nyx, a Tor monitoring tool:
    sudo apt install nyx -y
    

    Run:

    nyx
    

Harden Security

  • Change the default pi user password:
    passwd
    
  • Disable unnecessary services:
    sudo systemctl disable bluetooth.service
    

Log Traffic

  • Enable verbose logging in /etc/tor/torrc:
    Log notice file /var/log/tor/notices.log
    

Troubleshooting

  1. Tor doesn’t start:
    • Check logs:
      sudo journalctl -xe | grep tor
      
  2. No internet connection:
    • Verify iptables rules and DNS configuration.
  3. Slow speeds:
    • Tor inherently slows traffic for anonymity. Test with a wired connection for better performance.

By following this guide, you’ll have a Raspberry Pi functioning as a Tor proxy, providing anonymized internet traffic for connected devices.

If nothing else if you have never investigated Tor even the browser – I thoroughly recommend you do

Link

https://www.torproject.org/

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More