Set up a Tor proxy with Raspberry Pi to control internet traffic

Create an anonymous server and browser with these simple steps and a few pieces of affordable hardware.
170 readers like this
170 readers like this
Coding the Raspberry Pi in a web emulator

Opensource.com

First things first: What are proxy servers, and why use them?

Wikipedia provides the following description and diagram: A proxy server is a server (a computer system or an application) that acts as an intermediary for requests from clients seeking resources from other servers. A client connects to the proxy server, requesting some service, such as a file, connection, web page, or other resource available from a different server, and the proxy server evaluates the request as a way to simplify and control its complexity.

Proxy server diagram

Proxy servers are useful in many contexts:

  • In the office: to control internet traffic by blocking some websites or some keywords, to manage contact with external internet from a single point, or to optimize internet bandwidth usage by caching pages at proxy level.
  • At home: to control family internet access to block dangerous websites for children.
  • For personal use: to use an anonymous connection or to bypass network ISP blocks.

And those are just a few examples!

The Tor Project

From the Tor (anonymity network) Wikipedia page:

Tor is free and open source software for enabling anonymous communication. The name is derived from an acronym for the original software project name "The Onion Router." Tor directs internet traffic through a free, worldwide, volunteer overlay network consisting of more than 7000 relays to conceal a user's location and usage from anyone conducting network surveillance or traffic analysis. Using Tor makes it more difficult to trace Internet activity to the user; this includes "visits to websites, online posts, instant messages, and other communication forms." Tor's intended use is to protect the personal privacy of its users, as well as their freedom and ability to conduct confidential communication by keeping their Internet activities from being monitored.

Tor Project is the nonprofit association that currently develops software to facilitate the use of the Tor Network.

Do I need a Tor proxy or an alternative way to use the Tor network?

You can find a simple answer to this question with a few checks:

  • If you can use a different browser within single computers, then you could evaluate Tor Browser. Tor Browser can be installed in your PC and allows you to browse the web with Tor network. A good installation guide comes from our friends at ProPrivacy.
  • If you need a way to use the Tor network with your current browser or you need to connect a number of computers maintaining their current browsers, then you should opt for a Tor proxy. Read on for directions to install a Tor proxy in a cheap Raspberry Pi.

Step-by-step procedure

Hardware needed:

  • a Raspberry Pi Zero W (or higher model) with its power supply (connected via WiFi)
  • a micro SD card

In this guide, we are going to use default Raspbian Buster Lite as OS. Then we'll install Tor from Raspbian repository and apply a very simple configuration to use it as a Socks proxy.

I'll configure the Tor proxy to manage access for all clients on a 192.168.1.0/24 private network to internet. You will need to modify this network depending on your needs and networking configurations.

1. Install OS and Tor

Start from a fresh Raspbian Buster Lite installation. Make sure your OS is updated:

sudo apt-get update
sudo apt-get upgrade

Install Tor by using Raspbian repository:

sudo apt-get install tor

At the end of the installation, you will have two services running as Tor: "tor.service" and "tor@default.service."

The first one is a dummy service, which appears to the user as active but in exited status. In fact, a simple check:

sudo systemctl status tor.service

will give the following result:

● tor.service - Anonymizing overlay network for TCP (multi-instance-master)
   Loaded: loaded (/lib/systemd/system/tor.service; enabled; vendor preset: enabled)
   Active: active (exited) since Tue 2019-10-01 20:25:18 BST; 35s ago
 Main PID: 5546 (code=exited, status=0/SUCCESS)
   Memory: 0B
   CGroup: /system.slice/tor.service

This is normal. The most reliable service to check if Tor is running is the second one. The command:

sudo systemctl status tor@default.service

should deliver a more familiar result:

● tor@default.service - Anonymizing overlay network for TCP
Loaded: loaded (/lib/systemd/system/tor@default.service; enabled-runtime; vendor preset: enabled)
Active: active (running) since Tue 2019-10-01 20:25:30 BST; 1min 36s ago
Main PID: 5552 (tor)
Memory: 23.5M
CGroup: /system.slice/system-tor.slice/tor@default.service
└─5552 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

2. Configure Tor

The Tor main configuration file is named torrc. Before editing, create a backup copy:

sudo cp /etc/tor/torrc /etc/tor/torrc.backup

A very simple configuration will expose Tor Socks proxy service on Tor default port (9050) and will accept connections only from local LAN (192.168.1.0/24). It will run as daemon so that we won't need to call it each time we use it. Finally, it will store data in default directory (/var/lib/tor/).

Edit configuration file:

sudo nano /etc/tor/torrc

including only the following lines (assuming that 192.168.1.100 is your Raspberry Pi IP address):

SocksPort 192.168.1.100:9050
SocksPolicy accept 192.168.1.0/24
RunAsDaemon 1
DataDirectory /var/lib/tor

Close and save the file, then restart Tor service:

sudo systemctl restart tor@default.service

3. Configure your client to use a proxy server

Now you need to configure your client to use Socks proxy server for internet connections. You have to check this, depending on your client browser. Mozilla Firefox can use Socks proxy and can be configured by selecting Options, Network Settings, then Settings. Select Manual Proxy Configuration, insert the Raspberry Pi IP address in the Socks Host field, insert 9050 in the related port and make sure SOCKS v5 flag is active. You should have a configuration like the following picture:

Firefox proxy settings

Close and then restart your browser. Now you are using your Tor network in your browser. You can verify it by browsing the URL https://check.torproject.org/?lang=en.

Tor proxy check

Enjoy!

 

This article was originally posted at peppe8o.com and has been published with the author's permission.

What to read next
Lucky husband, open source passionate. Curious by nature. Proud of my roots, happy to mix and learn from different roots

14 Comments

Can this going on a dietpi running pihole?

Ok ok...but the public ip is exposed! Check with the https://browserleaks.com/ip and the IP is exposed with DNS server

A public IP is always shown, but using TOR proxy this IP is not your one. You can check this by looking your IP without proxy and verifying it again after enabling TOR proxy. About DNS queries, with Firefox you can also enable option "Proxy DNS when using SOCKS v5"

In reply to by Shensueru (not verified)

I have used tor-browser earlier, wasn't knowing we can create a server from it. Very informative article, thanks for writing.

Thank you Abhinav. In my opinion, the cool thing is that this can be done with a very cheap hardware (Raspberry PI Zero W has a very affordable cost) and with a very low power consuption (RPI Zero W users 5V and about 0,5A)

In reply to by Abhinav Ramesh

I didn't knew tha , this can be done ,simply wow!

Thanks for this. Quite interesting and works like a charm. I am setting up an old Rasp 3B with few services including this ver tor proxy and I am wondering whether the raspi itself will route all its traffic through Tor by default? As the raspberry itself will be generating traffic, Is there something else I have to set up? Thanks a lot in advance!

Thank you for your feedback!
To make RPI client of its in-built TOR service, you need to set 127.0.0.1:9050 as socks proxy url in its proxy configurations. For example, to use tor on apt you need to set a properly conf file under /etc/apt/apt.conf.d/.

In reply to by ExMM (not verified)

The internet will slow like tor browser?

Hello,

I got raspberry pi 4 and i want to install TOR.
I know i can just simply install so i need to use Chromium.
I have followed your steps but while reaching configuration of the browser i got this message:
//When running Chromium under a supported desktop environment, the system proxy settings will be used. However, either your system is not supported or there was a problem launching your system configuration.//

can you please help me with the command line?

Also, i mention i`ve already using paid VPN and ufw , adding this will mess my settings ?

Thanks

Try from terminal command:
chromium-browser --proxy-server="proxy_ipaddress:port"
If you left port to 9050, then command should be:
chromium-browser --proxy-server="127.0.0.1:9050".

In reply to by Kraker (not verified)

Hey! Thank you for your tutorial! I have the following problem: I have set up an AP and installed tor, but my IP is not changing. Here are my logs:

eth0: flags=4163 mtu 1500
inet 192.168.0.150 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 2a02:8070:4df:5d00:d399:bdb2:7fda:14f3 prefixlen 64 scopeid 0x0
inet6 fe80::a4de:b9d0:f66:54aa prefixlen 64 scopeid 0x20
ether dc:a6:32:3f:22:7a txqueuelen 1000 (Ethernet)
RX packets 414505 bytes 501022352 (477.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 260123 bytes 29306573 (27.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Lokale Schleife)
RX packets 68 bytes 6216 (6.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 68 bytes 6216 (6.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4163 mtu 1500
inet 192.168.4.1 netmask 255.255.255.0 broadcast 192.168.4.255
inet6 fe80::fba:3c94:dc4f:36fc prefixlen 64 scopeid 0x20
ether dc:a6:32:3f:22:7b txqueuelen 1000 (Ethernet)
RX packets 247724 bytes 24231954 (23.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 392175 bytes 507092369 (483.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

torrc file:
Log notice file /var/log/tor/notices.log
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsSuffixes .onion,.exit
AutomapHostsOnResolve 1
TransPort 9040
TransListenAddress 192.168.4.1
DNSPort 53
DNSListenAddress 192.168.4.1

● tor.service - Anonymizing overlay network for TCP (multi-instance-master)
Loaded: loaded (/lib/systemd/system/tor.service; enabled; vendor preset: enab
Active: active (exited) since Tue 2020-06-09 22:06:37 CEST; 1 day 13h ago
Main PID: 321 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
Memory: 0B
CGroup: /system.slice/tor.service

Jun 09 22:06:37 access systemd[1]: Starting Anonymizing overlay network for TCP
Jun 09 22:06:37 access systemd[1]: Started Anonymizing overlay network for TCP (
Jun 11 00:00:20 access systemd[1]: Reloading Anonymizing overlay network for TCP
Jun 11 00:00:20 access systemd[1]: Reloaded Anonymizing overlay network for TCP

tor@default.service - Anonymizing overlay network for TCP
Loaded: loaded (/lib/systemd/system/tor@default.service; enabled-runtime; ven
Active: active (running) since Thu 2020-06-11 11:40:57 CEST; 16min ago
Main PID: 31206 (tor)
Tasks: 1 (limit: 4915)
Memory: 32.7M
CGroup: /system.slice/system-tor.slice/tor@default.service
└─31206 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defa

Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.923 [notice] Read configurati
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.931 [warn] Skipping obsolete
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.931 [warn] Skipping obsolete
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.932 [notice] Opening Socks li
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.933 [notice] Opened Socks lis
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.933 [notice] Opening DNS list
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.933 [notice] Opened DNS liste
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.933 [notice] Opening Transpar
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.933 [notice] Opened Transpare
Jun 11 11:40:57 access systemd[1]: Started Anonymizing overlay network for TCP.

I stumbled over:

Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.931 [warn] Skipping obsolete
Jun 11 11:40:54 access tor[31206]: Jun 11 11:40:54.931 [warn] Skipping obsolete

Any idea? Thank you in advance!
Greetings

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.