Raspberry Pi as a Tor router and web filter

Activating IP Forwarding

The communication between the Wi-Fi subnet and Tor requires several adjustments of the network configuration. To begin, open the /etc/sysctl.conf file and append the directive net.ipv4.ip_forward=1 at the end. Then, activate the change by issuing sysctl -p.

The next step addresses the need for modifying the rules for iptables. You should first delete already existing rules using the commands iptables -F and iptables -t nat -F. You can then activate the new rules, which are shown in Listing 5, and immediately save them in the file /etc/iptables.ipv4.nat. Finally, open the /etc/network/interfaces file and append an empty line and the entry up iptables-restore /etc/iptables.ipv4.nat. This step instructs the system to process the rules on subsequent reboots.

Listing 5

Activating New 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

Installing Tor

The /etc/tor/torrc file contains the Tor configuration information. Directly following the line ##https://www.torproject.org/docs/faq#torrc, add the text from Listing 6. You should also create a log file (Listing 7) so that Tor has a place to record its messages. Finally, you can start Tor by invoking service tor start. By issuing the command update-rc.d tor enable, you ensure that this service also starts up automatically after a reboot.

Listing 6

Configuring /etc/tor/torrc

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

Listing 7

Creating a Log File

# touch /var/log/tor/notices.log
# chown debian-tor /var/log/tor/notices.log
# chmod 644 /var/log/tor/notices.log

To use Tor from now on, you just need to register the device of your choice with the new Wi-Fi network. You can check whether this arrangement works as intended by calling up the web page https://check.torproject.org. In case of success, you will see the message Congratulations. Your browser is configured to use Tor (Figure 4).

Figure 4: The website check.torproject.org checks whether your system is properly connected to the Tor network..

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content