The original post: /r/tor by /u/whichkey45 on 2024-11-14 13:44:23.
Hi, this should be straightforward for someone with the requisite knowledge, who has the time to look through the commands I have issued below, but there is a lot of information here! I have simplified this post as much as I am able to.
I have used the following two tutorials to try and set up a tor wifi router on a raspberry pi 3b+ to which I connected a 5g modem via a hat. The 5g modem appears to the pi as 'usb0'.
https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software
https://learn.adafruit.com/onion-pi
The first tutorial (first block of commands) results in me having a working raspberry pi router. I have made the odd adaptation (mainly due to the fact that I am connecting to the internet through usb0, rather than eth0, and I am in the UK so am using the GB country code rather than, US. But the commands below are exactly what I input.
The second tutorial, converting the wifi router into a tor router isn't working.
I am connected to the pi via eth0 which gets an ip address from my laptop as I am running isc-dhcp-server. I can ping and wget google.com from the pi's command line after the second tutorial, but I can't get to google.com from the web browser on my laptop via the wifi network that I created in the first tutorial.
I am comfortable with the linux aspects of what I have posted below (but usually this kind of problem is usually the result of some sort of daft mistake I am making, I know).
Primarily I am not sure about the torrc I have (it is simple, I know, I have (I have googled extensively, I promise, but I am still learning).
But I am also not sure what impact using a 5g modem attached to the pi via a hat has on any of these commands.
I have been trying to get this working, and experimenting for a long time........ Any help would be very much appreciated! Thanks
So
As well as the above, I also note that many of tutorials I have gone through utilise a bridge interface. I don't know what kind of effect bridging wlan0 with usb0 has, given that I need the hat to get an ip address from the mobile internet provider.
Having said that this pair of tutorials doesn't use a bridge anyway. I wonder whether I need one because of the 5g modem, and I don't know enough tor setup to figure out how I might have to change my torrc in order to accommodate it if I do..
After entering these commands I have a functioning raspberry pi based router:
sudo apt update
sudo apt -y upgrade
sudo apt install -y hostapd dnsmasq
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
sudo reboot
sudo nano /etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
sudo nano /etc/sysctl.d/routed-ap.conf
# Enable IPv4 routing
net.ipv4.ip_forward=1
sudo nano /etc/dnsmasq.conf
interface=wlan0 # Listening interface
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
# Pool of IP addresses served via DHCP
domain=wlan # Local wireless DNS domain
address=/gw.wlan/192.168.4.1
# Alias for this router
sudo nano /etc/hostapd/hostapd.conf
country_code=GB
interface=wlan0
ssid=mywifinetwork
hw_mode=a
channel=48
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mywifipassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
sudo rfkill unblock wifi
sudo raspi-config nonint do_wifi_country GB
sudo iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
sudo netfilter-persistent save
sudo reboot
-----
sudo apt remove modemmanager # I removed modemmanager because the developer of the hat says I need to. The 5g modem is functioning fine without any need for setup, but I am able to communicate with it using AT commands if I need to. The router worked fine at this point post removal of modemmanager.
As I said, this results in a working router. Something in it, given that I have this 5g modem/hat or for some other reason, might explain why the following tutorial isn't working. Thanks
sudo apt-get update
sudo apt-get install tor
sudo nano /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
~~~## I am fairly new to tor. I roughly know that I will point my web browser towards port 9050, and any other general tcp traffic will get pointed towards port 9040. I am confused as to why the listening address is 192.168.42.1? Is this some sort of virtual address used by tor, or is it a typo?~~~
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 22 -j REDIRECT --to-ports 22
sudo iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j REDIRECT --to-ports 53
sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports 9040
sudo iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:ssh redir ports 22
REDIRECT udp -- anywhere anywhere udp dpt:domain redir ports 53
REDIRECT tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,ACK/SYN redir ports 9040
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
~~~## I noticed the rule from the previous tutorial didn't appear to be loaded, (I thought sudo netfilter-persistent save would reload it sutomatically) but nevertheless the pi-router was functioning. I decided to re-create the rule as I presume the tutorial expects it. I understand the rule, but am not sure how it interacts with tor.~~~
## Here is the rule:
sudo iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo touch /var/log/tor/notices.log
sudo chown debian-tor /var/log/tor/notices.log
sudo chmod 644 /var/log/tor/notices.log
ls -l /var/log/tor
sudo service tor start
sudo service tor status
● 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 Thu 2024-11-14 12:20:13 GMT; 23min ago
Process: 1298 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 1298 (code=exited, status=0/SUCCESS)
CPU: 5ms
Nov 14 12:20:13 piOnionROuter systemd[1]: Starting Anonymizing overlay network for TCP (multi-instance-master)...
Nov 14 12:20:13 piOnionROuter systemd[1]: Finished Anonymizing overlay network for TCP (multi-instance-master).
sudo update-rc.d tor enable