# Onion Pi

## Overview

Warning: This guide, written in 2013, predates newer Pi operating systems and hardware so it does not reflect the instructions for more modern hardware & software. It's here for reference only.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/059/medium800/raspberry_pi_onionpi.jpg?1396881734)

Feel like someone is snooping on you? Browse anonymously anywhere you go with the Onion Pi Tor proxy. This is fun weekend project that uses a Raspberry Pi, a USB WiFi adapter and Ethernet cable to create a small, low-power and portable privacy Pi.   
  
Using it is easy-as-pie. First, plug the Ethernet cable into any Internet provider in your home, work, hotel or conference/event. Next, power up the Pi with the micro USB cable to your laptop or to the wall adapter. The Pi will boot up and create a new secure wireless access point called **Onion Pi**. Connecting to that access point will automatically route any web browsing from your computer through the anonymizing Tor network.

# Who is this good for?
If you want to browse anonymously on a netbook, tablet, phone, or other mobile or console device that cannot run Tor and does not have an Ethernet connection. If you do not want to or cannot install Tor on your work laptop or loan computer. If you have a guest or friend who wants to use Tor but doesn't have the ability or time to run Tor on their computer, this gift will make the first step much easier.  
  

# What is Tor?
Tor is an **onion routing** service - every internet packet goes through 3 layers of relays before going to your destination. This makes it much harder for the server you are accessing (or anyone snooping on your Internet use) to figure out who you are and where you are coming from. It is an excellent way to allow people who are blocked from accessing websites to get around those restritions.  
  
[According to the Tor website:](https://www.torproject.org/about/overview.html.en)  

> Journalists use Tor to communicate more safely with whistleblowers and dissidents. Non-governmental organizations (NGOs) use Tor to allow their workers to connect to their home website while they're in a foreign country, without notifying everybody nearby that they're working with that organization.  
>   
> Groups such as Indymedia recommend Tor for safeguarding their members' online privacy and security. Activist groups like the Electronic Frontier Foundation (EFF) recommend Tor as a mechanism for maintaining civil liberties online. Corporations use Tor as a safe way to conduct competitive analysis, and to protect sensitive procurement patterns from eavesdroppers. They also use it to replace traditional VPNs, which reveal the exact amount and timing of communication. Which locations have employees working late? Which locations have employees consulting job-hunting websites? Which research divisions are communicating with the company's patent lawyers?  
>   
> A branch of the U.S. Navy uses Tor for open source intelligence gathering, and one of its teams used Tor while deployed in the Middle East recently. Law enforcement uses Tor for visiting or surveilling web sites without leaving government IP addresses in their web logs, and for security during sting operations.

Info: 

Info: 

# Onion Pi

## What you'll need

You'll need a few things to run this tutorial:

- [Raspberry Pi model B+](https://www.adafruit.com/products/1914) (or B) - Ethernet is required
- [Ethernet cable](http://www.adafruit.com/products/730)
- [WiFi adapter](http://www.adafruit.com/products/814) **- Not all WiFi adapters work, we know for sure it works with the ones in the Adafruit shop!**
- [SD Card (4GB or greater)](http://www.adafruit.com/products/102) with Raspbian on it. You can either copy the Raspbian image onto it or [buy a ready-made Raspbian card](http://www.adafruit.com/products/1121)
- [Power supply for your Pi](https://www.adafruit.com/products/1995)
- [USB Console cable (optional) - this makes it a little easier to debug the system](http://www.adafruit.com/products/954)
- [Case for your Pi (optional)](https://www.adafruit.com/products/2258)
- [A SD or MicroSD card reader](http://www.adafruit.com/products/939) (optional)

Chances are you've got a couple of these items already. If not, our [Onion Pi starter pack](http://www.adafruit.com/products/1410) has everything you need

![](https://cdn-learn.adafruit.com/assets/assets/000/009/120/medium800/raspberry_pi_onionpimini.jpg?1396883549)

# Onion Pi

## Preparation

This tutorial assumes you have your Pi mostly set up and have followed our "Raspberry Pi as Wifi Access Point" tutorial  
  
Please follow these tutorials in order to

- [Install the OS onto your SD card](http://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi)  
If you bought an SD card with Raspbian pre-burned on you can skip this step
- [Boot the Pi and log into it](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-2-first-time-configuration)  
**Don't forget to change the default password for the 'pi' acccount!!!**

Make sure to expand the filesystem to the entire disk or you may run out of space (this is done by default now on Raspbian when you boot it)

However, don't configure WiFi - you can log in over Ethernet or Serial console

![](https://cdn-learn.adafruit.com/assets/assets/000/009/070/medium800/raspberry_pi_expandFS.gif?1448056506)

- [Set up and test the Ethernet connection - in general this means just plug into Ethernet before booting](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup "Link: http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup")  
Check that you can&nbsp; **ssh** to, or **ping** from the Raspberry Pi
- For WiFi, you do not need to configure anything. and that your Wifi adapter is recognized and shows up as **wlan0** when you run **ifconfig wlan0**

![](https://cdn-learn.adafruit.com/assets/assets/000/046/002/medium800/raspberry_pi_ifconf.png?1504321772)

- [Connect with a USB console cable (optional)](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup "Link: http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup")  
Handy for debugging especially when connecting to the access point hosted by the Pi

**When done you should have a Pi that is booting Raspbian, has working Ethernet, and you can connect to with a USB console cable and log into the Pi via the command line interface.**

- Then [follow our Pi-as-Access-Point tutorial](http://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point "Link: http://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point")to set up the Pi as a wifi access point router.

When done you should be able to connect to the Pi as a WiFi access point and connect to the internet through it.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/071/medium800/raspberry_pi_connecting.gif?1448056498)

It is possible to do this tutorial via **ssh** on the Ethernet port **or** using a console cable.  
  
If using a console cable, even though the diagram on the last step shows powering the Pi via the USB console cable (red wire) we suggest not connecting the red wire and instead powering from the wall adapter. Keep the black, white and green cables connected as is.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/072/medium800/raspberry_pi_gpio_closeup.jpg?1396882052)

# Onion Pi

## Install Tor

[Essentially, this tutorial just follows the tor "anonymizing middlebox" writeup here.](https://trac.torproject.org/projects/tor/wiki/doc/TransparentProxy#AnonymizingMiddlebox "Link: https://trac.torproject.org/projects/tor/wiki/doc/TransparentProxy#AnonymizingMiddlebox")  
  
_If you hate typing a lot,_ [_this script from breadk will do it all_](https://raw.github.com/breadtk/onion_pi/master/setup.sh) _for you! Make sure to read through the script to make sure you don't want to change anything!_ ([More about how to use it here!](https://github.com/breadtk/onion_pi "Link: https://github.com/breadtk/onion\_pi")) We do suggest going step by step so you can have the experience of all the upkeep tasks.  
  
We'll begin by installing **tor** - the onion routing software.  
  
Log into your pi by Ethernet or console cable and run

> **sudo apt-get update**  
> **sudo apt-get install tor**

![](https://cdn-learn.adafruit.com/assets/assets/000/009/060/medium800/raspberry_pi_aptgettor.png?1396881769)

Edit the tor config file by running

> **sudo nano /etc/tor/torrc**

and copy and paste the text into the top of the file, right below the the FAQ notice.  
```
Log notice file /var/log/tor/notices.log
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsSuffixes .onion,.exit
AutomapHostsOnResolve 1
TransPort 9040
TransListenAddress 192.168.42.1
DNSPort 53
DNSListenAddress 192.168.42.1
```

![](https://cdn-learn.adafruit.com/assets/assets/000/009/062/medium800/raspberry_pi_torrc.png?1396881830)

Let's edit the host access point so it is called something memorable like **Onion Pi** - don't forget to set a good password, don't use the default here!

**sudo nano /etc/hostapd/hostapd.conf**

( **Don't forget to do the AP setup step in "Preparation" before this!** )

![](https://cdn-learn.adafruit.com/assets/assets/000/009/061/medium800/raspberry_pi_hostapd.png?1396881794)

Time to change our ip routing tables so that connections via the wifi interface ( **wlan0** ) will be routed through the tor software.  
Type the following to flush the old rules from the ip NAT table

> **sudo iptables -F**  
> **sudo iptables -t nat -F**

If you want to be able to **ssh** to your Pi after this, you'll need to add an exception for port 22 like this (not shown in the screenshot below)  

> **sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 22 -j REDIRECT --to-ports 22**

Type the following to route all DNS (UDP port 53) from interface wlan0 to internal port 53 (DNSPort in our torrc)  

> **sudo iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j REDIRECT --to-ports 53**

Type the following to route all TCP traffic from interface wlan0 to port 9040 (TransPort in our torrc)  

> **sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports 9040**

Next you can check that the ip tables are right with  

> **sudo iptables -t nat -L**

  
  
![](https://cdn-learn.adafruit.com/assets/assets/000/009/063/medium800/raspberry_pi_iptables.png?1396881860)

If all is good, we'll save it to our old NAT save file

> **sudo sh -c "iptables-save \> /etc/iptables.ipv4.nat"**

It will automatically get loaded when the networking is set up on reboot (as we did in the last tutorial on making a Pi access point)  
![](https://cdn-learn.adafruit.com/assets/assets/000/009/068/medium800/raspberry_pi_savetable.png?1396881999)

Next we'll create our log file (handy for debugging) with

> **sudo touch /var/log/tor/notices.log**  
> **sudo chown debian-tor /var/log/tor/notices.log**  
> **sudo chmod 644 /var/log/tor/notices.log**

Check it with   

> **ls -l /var/log/tor**

Start the tor service manually  

> **sudo service tor start**

Check its really running (you can run this whenever you're not sure, it something is wrong you'll see a big FAIL notice  

> **sudo service tor status**

Finally, make it start on boot  

> **sudo update-rc.d tor enable**

![](https://cdn-learn.adafruit.com/assets/assets/000/009/064/medium800/raspberry_pi_runtor.png?1396881890)

That's it, now you're ready to test in the next step.

# Onion Pi

## Test It!

OK now the fun part! It's time to test your TOR anonymizing proxy. On a computer, check out the available wifi networks, you should see the **Onion Pi** network

![](https://cdn-learn.adafruit.com/assets/assets/000/009/066/medium800/raspberry_pi_onionpi.png?1396881950)

Connect to it using the password you entered into the **hostapd** configuration file

![](https://cdn-learn.adafruit.com/assets/assets/000/009/067/medium800/raspberry_pi_connecting.png?1396881970)

You can open up a Terminal or command prompt and **ping 192.168.42.1** to check that your connection to the Pi is working. However you won't be able to ping outside of it because ping's are not translated through the proxy

![](https://cdn-learn.adafruit.com/assets/assets/000/009/069/medium800/raspberry_pi_ping192.gif?1448056514)

To check that the proxy is working, visit a website like [http://www.ipchicken.com](http://www.ipchicken.com) which will display your IP address as it sees it and also the matching domain name if available. The IP address should not be from your internet provider - in fact, if you reload the page it should change!

![](https://cdn-learn.adafruit.com/assets/assets/000/009/065/medium800/raspberry_pi_ipchicken.png?1396881919)

Your web browsing traffic is now anonymized!

Info: 

# Onion Pi

## Do more...

Now that you have this project set up, you can do more...

# Set up as a Wifi-to-Wifi Tor middlebox
We use Ethernet because it requires no configuration or passwords, just click the cable to get DHCP but if you want, its possible to set it up as a WiFi-to-WiFi proxy. You'll need two WiFi adapter, then edit **/etc/networks/interfaces** to add **wlan1** and [enter in the SSID/password for your Internet provider using our WiFi tutorial](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/setting-up-wifi-with-occidentalis) We don't have a tutorial for this project  
  

# Configure Tor to make your Exit Node in a particular country only

Its very easy to configure tor to give you a presence in any country of your choice. For example here's my torrc that makes me 'present' in Great Britain.  
Replace aaa.bbb.ccc.ddd by the IP address of your RPi and GB by the country code of your choice.  
Configure your browser to uses a Socks 5 proxy on aaa.bbb.ccc.ddd, port 9050

> Log notice file /var/log/tor/notices.log  
> SocksListenAddress aaa.bbb.ccc.ddd  
> ExitNodes {GB}  
> StrictNodes 1

# Set up as a Tor Relay or Exit Node
If you like using Tor, help make it faster by joining as a relay, or increasing the anonymity by becoming an exit node. [Check out the Tor project website for how to edit your](https://www.torproject.org/docs/tor-relay-debian.html.en)**[torrc](https://www.torproject.org/docs/tor-relay-debian.html.en)**[to turn your Pi into either](https://www.torproject.org/docs/tor-relay-debian.html.en "Link: https://www.torproject.org/docs/tor-relay-debian.html.en").  
  

# Donate to the Tor Project
If you like using Tor, but can't run a relay or exit node - [consider donating to the project which helps pay for developers, servers and more.](https://www.torproject.org/donate/donate.html.en) Your donation is tax-deductable if you are in the US  
  

## Featured Products

### Onion Pi Pack w/ WiFi Module - Make a Raspberry Pi B+ Tor Proxy

[Onion Pi Pack w/ WiFi Module - Make a Raspberry Pi B+ Tor Proxy](https://www.adafruit.com/product/1410)
Feel like someone is snooping on you? Browse anonymously anywhere you go with the Onion Pi Tor proxy. Using this pack of parts and a free weekend you can build a project that uses a Raspberry Pi, a USB WiFi module&nbsp;and Ethernet cable to create a small, low-power and portable privacy Pi.<br...></br...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1410)
[Related Guides to the Product](https://learn.adafruit.com/products/1410/guides)
### Onion Pi Pack w/Large Antenna - Make a Raspberry Pi B+ Tor Proxy

[Onion Pi Pack w/Large Antenna - Make a Raspberry Pi B+ Tor Proxy](https://www.adafruit.com/product/1406)
Feel like someone is snooping on you? Browse anonymously anywhere you go with the Onion Pi Tor proxy. Using this pack of parts and a free weekend you can build a project that uses a Raspberry Pi B+, a USB WiFi adapter and Ethernet cable to create a small, low-power and portable privacy Pi.<br...></br...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1406)
[Related Guides to the Product](https://learn.adafruit.com/products/1406/guides)
### Raspberry Pi Model B+ 512MB RAM

[Raspberry Pi Model B+ 512MB RAM](https://www.adafruit.com/product/1914)
OMG OMG OMG, did you hear? There's a Raspberry Pi&nbsp;called the Model B+ and check it out...more USB ports, more GPIO, better power supply, four mounting holes, less sticky-out SD card! Yep, that's right, the fantastic engineers at Raspberry Pi HQ have blessed us with a new design....

In Stock
[Buy Now](https://www.adafruit.com/product/1914)
[Related Guides to the Product](https://learn.adafruit.com/products/1914/guides)
### Adafruit Raspberry Pi B+ / Pi 2 / Pi 3 Case - Smoke Base

[Adafruit Raspberry Pi B+ / Pi 2 / Pi 3 Case - Smoke Base](https://www.adafruit.com/product/2258)
It took awhile to perfect&nbsp;-&nbsp;but that's okay&nbsp;since we can now safely say that the Adafruit case for Raspberry Pi Model B+ / Pi 2 / Pi 3&nbsp;is The Single&nbsp;Greatest Raspberry Pi Model B+ Case Ever.

This enclosure&nbsp;was designed by Mike Doell - just like our...

In Stock
[Buy Now](https://www.adafruit.com/product/2258)
[Related Guides to the Product](https://learn.adafruit.com/products/2258/guides)
### Raspberry Pi Model B 512MB RAM

[Raspberry Pi Model B 512MB RAM](https://www.adafruit.com/product/998)
Adafruit ships the **Raspberry Pi Model B 512MB RAM** as of 10/18/2012.  
  
The Raspberry Pi® is a single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools. The Raspberry...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/998)
[Related Guides to the Product](https://learn.adafruit.com/products/998/guides)
### Adafruit Pi Case- Enclosure for Raspberry Pi Model A or B

[Adafruit Pi Case- Enclosure for Raspberry Pi Model A or B](https://www.adafruit.com/product/1326)
We are happy to finally release Adafruit's lovely Raspberry Pi case, designed by Mike Doell ([who made our really terrific Arduino enclosures as well](http://www.adafruit.com/products/337)). We wanted a beautiful, elegant case, not just functional but also something you'd...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1326)
[Related Guides to the Product](https://learn.adafruit.com/products/1326/guides)
### 4GB SD card for Raspberry Pi preinstalled with Raspbian Wheezy

[4GB SD card for Raspberry Pi preinstalled with Raspbian Wheezy](https://www.adafruit.com/product/1121)
![Raspbian](../images/rasp.png)  
This is a 4GB microSDHC card (SDC44GB) that comes with a SD adapter and is pre-programmed to contain the latest Raspberry Pi Linux distribution "Raspbian Wheezy" which was released on 2015-01-31...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1121)
[Related Guides to the Product](https://learn.adafruit.com/products/1121/guides)
### 5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable

[5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable](https://www.adafruit.com/product/1995)
Our all-in-one 5V 2.5 Amp + MicroUSB cable power adapter is the perfect choice for powering single-board computers like Raspberry Pi, BeagleBone, or anything else that's power-hungry!

This adapter was specifically designed to provide 5.25V, not 5V, but we still call it a 5V USB...

In Stock
[Buy Now](https://www.adafruit.com/product/1995)
[Related Guides to the Product](https://learn.adafruit.com/products/1995/guides)

## Related Guides

- [Raspberry Pi WiFi Radio](https://learn.adafruit.com/pi-wifi-radio.md)
- [Setting up a Raspberry Pi as a WiFi Access Point](https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point.md)
- [Pi Hole Ad Detection Display with PiTFT](https://learn.adafruit.com/pi-hole-ad-pitft-tft-detection-display.md)
- [Introducing the Raspberry Pi 2 - Model B](https://learn.adafruit.com/introducing-the-raspberry-pi-2-model-b.md)
- [Monitor Your Home With the Raspberry Pi B+](https://learn.adafruit.com/monitor-your-home-with-the-raspberry-pi-b-plus.md)
- [Playing sounds and using buttons with Raspberry Pi](https://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi.md)
- [Adafruit DVI Breakout Board](https://learn.adafruit.com/adafruit-dvi-breakout-board.md)
- [LED Matrix Wall Arcade for Pico-8](https://learn.adafruit.com/led-matrix-wall-arcade.md)
- [Neo Trinkey Auto Screen Locker](https://learn.adafruit.com/neo-trinkey-auto-screen-locker.md)
- [Use 3D Scanning to Make Low Poly 3D Models](https://learn.adafruit.com/use-3d-scanning-to-make-low-poly-3d-models.md)
- [Making PCB Jewelry & Art with Gingerbread and KiCad](https://learn.adafruit.com/making-pcb-art-with-gingerbread-and-kicad.md)
- [Networked Thermal Printer using Raspberry Pi and CUPS](https://learn.adafruit.com/networked-thermal-printer-using-cups-and-raspberry-pi.md)
- [NeoPixels on Raspberry Pi](https://learn.adafruit.com/neopixels-on-raspberry-pi.md)
- [DIY Adaptive Game Controllers](https://learn.adafruit.com/diy-adaptive-game-controllers.md)
- [Adafruit QT Py CH32V203](https://learn.adafruit.com/adafruit-qt-py-ch32v203.md)
