Chaos Computer Club Lëtzebuerg

“Chaos in the world brings uneasiness, but it also allows the opportunity for creativity and growth.” -- Tom Barret

User Tools

Site Tools

projects:raspberrypi:tor-hotspot Lang:
Name Tor Hotspot
Description Build a WiFi AP which tunnels TCP connections through Tor
Status Concluded
Contact virii
Participants: virii

Want a Tor Router out of a raspberry pi?! Well here we go!


We need the following:

  • Raspberry Pi (Modell B, REV1 or REV2) ~40€
  • A case for our Pi ~10€
  • Transcend Extreme-Speed SDHC 16GB SDCARD ~12€
  • Micro-USB 5V 1500mA Power Supply ~4€
  • LAN Cable ~1€
  • TP-Link TL-WN722N Wireless adapter ~12€
  • D-Link DUB-H4 USB HUB ~18€

Makes a total of ~97€ for a ready-to-go Tor Hotspot. (amazon prices!)


Prepare the SDCard with the latest version of Raspbian.

wget -O /tmp/raspbian.img
dd if=/tmp/raspbian.img of=/dev/<YOUR SDCARD> bs=4M

  • Plug the SDcard into the Pi
  • Connect it with the LAN cable to your router/switch
  • Connect the Pi with an HDMI cable to a monitor
  • Connect the USB Hub to the Pi.
  • On the HUB, connect an USB Keyboard and the Wireless adapter.
  • Connect the USB Hub and the Pi to their power supplies and fire it all up.


When raspi-config opens, tell it to expand the filesystem to the full size of your SDcard.
Next, go and enable the SSH daemon. Now you can change the hostname to something like “TorRouter”.

Switch to the root user!
sudo su
Install Hostapd (does the Hotspot/Access Point) stuff, the DCHP server and Tor.
apt-get update && apt-get install isc-dhcp-server tor

For our setup we must compile Hostapd by hand as our TP-Link TL-WN722N uses a driver that's not enabled by the default raspbian hostapd.
apt-get install libssl-dev libnl-dev
tar xzvf hostapd-2.0.tar.gz
cd hostapd-2.0/hostapd
cp defconfig .config
nano .config

Uncomment the following line

Compile it!
make install

Edit dhcpd.conf
nano /etc/dhcp/dhcpd.conf

Comment the following lines out
# option domain-name “”;
# option domain-name-servers,;

Uncomment the following line
# authoritative;
Now add the following block of lines to the config (at the end of the file)

subnet netmask {
option broadcast-address;
option routers;
default-lease-time 600;
max-lease-time 7200;
option domain-name “local”;
option domain-name-servers,;

Edit /etc/default/isc-dhcp-server
nano /etc/default/isc-dhcp-server
Change the INTERFACES value to this
Now open /etc/network/interfaces and edit it to the following lines

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_upplicant.conf
#iface default inet dhcp

iface wlan0 inet static
address netmask

Enable wlan0
ifup wlan0
Now we create /etc/hostapd/hostapd.conf
nano /etc/hostapd/hostapd.conf
Fill it with the following lines


Enable DAEMON mode in hostapd.
nano /etc/default/hostapd
Edit it

Now we need to download some more firmware for the chipset on our TP-Link
wget -O /etc/driver/htc_9271.fw
Go ahead and start the 2 services!
service hostapd start
service isc-dhcp-server start

Enable autostart
update-rc.d hostapd enable
update-rc.d isc-dhcp-server enable

Add the following line to /etc/sysctl.conf
Activate the changement
sysctl -p
Delete any old IPtables rule (if any)
iptables -F
iptables -t nat -F

Add the following ip-forwarding rules

iptables -t nat -A PREROUTING -i wlan0 -p tcp –dport 22 -j REDIRECT –to-ports 22
iptables -t nat -A PREROUTING -i wlan0 -p udp –dport 53 -j REDIRECT –to-ports 53
iptables -t nat -A PREROUTING -i wlan0 -p tcp –syn -j REDIRECT –to-ports 9040
iptables-save > /etc/iptables.ipv4.nat

Add the following line to /etc/network/interfaces but after a newline.
up iptables-restore /etc/iptables.ipv4.nat

Config Tor! Add the following lines after this line ##

Log notice file /var/log/tor/notices.log
AutomapHostsSuffixes .onion, .exit
AutomapHostsOnResolve 1
TransPort 9040
DNSPort 53

Start Tor
service tor start

Enable Tor in autostart
update-rc.d tor enable

Now your Hotspot is ready to be used!
Go ahead and connect to it. Then go to It will tell you that you are using Tor!
Have fun with it!

Buyable solutions

onionpi.jpg If you want to buy a package with everything you need then have a look at Adafruit. But you still need do configure everything by your own! Costs: $94.95

projects/raspberrypi/tor-hotspot.txt · Last modified: 2016/10/19 23:31 by virii