garycnew
Senior Member
What is Advanced Settings > VPN > Tor on Asuswrt-Merlin?
1. Although obscurely placed in the VPN section... Tor is NOT a Virtual Private Network (VPN)
2. Tor is an Anonymizing SOCKS Proxy Network developed & maintained by the Tor Project
3. Isn't Tor EVIL? Tor is a tool and like any tool it can be used for Good and Evil. We'll focus on using Tor for Good (RE: Tor Overview)
Requirements/Assumptions:
1. An Asuswrt-Merlin Compatible Router (i.e., Asus RT-AC66U)
2. Asuswrt-Merlin Compatible Firmware (i.e., 384.19)
3. Formated JFFS Partition and Enabled JFFS Custom Scripts and Configs
4. Entware installed on USB 3.0 Interface Device via Asuswrt-Merlin Terminal Menu (AMTM) with Swap File created
5. Capable of Editing the following User Scripts:
/jffs/scripts/torrc.postconf
/jffs/configs/init-start
/jffs/scripts/nat-start (Optional)
Asuswrt-Merlin Tor Options:
1. Tor via Bridge - Route all client traffic for a given network through the Tor network (Best Security - Low Performance: Not Recommended for most networks)
2. Tor via Device - Route all client traffic for a given device (MAC Address) through the Tor network (Better Security - Low Performance: Better than the Bridge option)
3. Tor via Browser - Route all client traffic for a given browser through the Tor network (Good Security - Good Performance: Recommend Tor Browser with SOCKS Proxy Settings)
4. Tor via an Entry (Guard)/Middle (Non-Exit) Relay - Route all server traffic as a Tor relay through the Tor network (Good Security - Good Performance: Congratulations! You're a Tor Contributor)
5. Tor via a Device/Browser/Relay Hybrid - Route device, browser, and relay traffic through the Tor network (Good Security - Good Performance: This is How We Do It!)
Implementing Tor Options:
1. Tor via Bridge option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "LAN(br0)" for "Redirect all user from." Click "Apply." That's it! All client traffic for a given network is routing through the Tor network.
2. Tor via Device option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "Only Specified MAC's" for "Redirect all user from." Select a device from the list of "MAC" addresses. Click "Add." Click "Apply." That's it! All client traffic for a given device (MAC address) is routing through the Tor network.
3. Tor via Browser option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "Only Specified MAC's" for "Redirect all user from." Add the placeholder MAC address "00:00:00:00:00:00" to the list of "MAC" addresses. Click "Add." Click "Apply." Now, create the following torrc.postconf file:
Lastly, configure the Proxy Settings of a Browser, on your LAN, with the SOCKS Host: 192.168.0.1 and Port: 9050. When necessary, this configuration provides an additional level of anonymity for regular browsers. However, when available, we still recommend using Tor Browser as it provides a greater level of anonymity.
That's it! All client traffic for a given Browser is routing through the Tor network.
4. Tor via an Entry (Guard)/Middle (Non-Exit) Relay option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "Only Specified MAC's" for "Redirect all user from." Add the placeholder MAC address "11:11:11:11:11:11" to the list of "MAC" addresses. Click "Add." Click "Apply." Now, create the following torrc.postconf file:
Congratulations! You're a Tor Contributor!
4a. [Optional] Asuswrt-Merlin Tor with Dual WAN: Force Asuswrt-Merlin Tor (upper-case T) to Reload/Start Modified Config Anytime the nat-start Script is Executed
4b. [Optional] Install/Use Entware tor: Force Asuswrt-Merlin to use Entware installation of tor (lower-case T)
4c. [Optional] Entware tor with Dual WAN: Force Entware tor (lower-case T) to Reload/Start Modified Config Anytime the nat-start Script is Executed
5. Tor via a Device/Browser/Relay Hybrid option: Is Tor via Device (Tor Option #2), Tor via Browser (Tor Option #3), and Tor via an Entry (Guard)/Middle (Non-Exit) Relay (Tor Option #4) steps all combined. Simply select a device from the list of "MAC" addresses and/or uncomment the Tor via Browser option within the torrc.postconf file:
That's it! All client traffic for a given device (MAC address) and/or Browser is routing through the Tor network and You're a Tor Contributor!
Within 48 hours of successful implementation, using a 100Mb/s fiber Internet link and Asus RT-AC66U (256MB) model router, our Tor via an Entry (Guard)/Middle (Non-Exit) Relay is showing up in the Tor Metrics - Relay Search database (search for your Tor "Nickname" or "Fingerprint") as having potential for a Fast-Middle Relay. We'll see where we end up after the 90-day lifecycle.
Enjoy this Tutorial? Checkout some of my other Tutorials:
Tutorial: [SOLUTION] OpenVPN Client Split Tunnel for BitTorrent Traffic
Tutorial: [SOLUTION] OpenVPN Client Split Tunnel Reverse Proxy Web Traffic using Nginx, DNSMasq, and IPTables
1. Although obscurely placed in the VPN section... Tor is NOT a Virtual Private Network (VPN)
2. Tor is an Anonymizing SOCKS Proxy Network developed & maintained by the Tor Project
3. Isn't Tor EVIL? Tor is a tool and like any tool it can be used for Good and Evil. We'll focus on using Tor for Good (RE: Tor Overview)
Requirements/Assumptions:
1. An Asuswrt-Merlin Compatible Router (i.e., Asus RT-AC66U)
2. Asuswrt-Merlin Compatible Firmware (i.e., 384.19)
3. Formated JFFS Partition and Enabled JFFS Custom Scripts and Configs
4. Entware installed on USB 3.0 Interface Device via Asuswrt-Merlin Terminal Menu (AMTM) with Swap File created
5. Capable of Editing the following User Scripts:
/jffs/scripts/torrc.postconf
/jffs/configs/init-start
/jffs/scripts/nat-start (Optional)
Asuswrt-Merlin Tor Options:
1. Tor via Bridge - Route all client traffic for a given network through the Tor network (Best Security - Low Performance: Not Recommended for most networks)
2. Tor via Device - Route all client traffic for a given device (MAC Address) through the Tor network (Better Security - Low Performance: Better than the Bridge option)
3. Tor via Browser - Route all client traffic for a given browser through the Tor network (Good Security - Good Performance: Recommend Tor Browser with SOCKS Proxy Settings)
4. Tor via an Entry (Guard)/Middle (Non-Exit) Relay - Route all server traffic as a Tor relay through the Tor network (Good Security - Good Performance: Congratulations! You're a Tor Contributor)
5. Tor via a Device/Browser/Relay Hybrid - Route device, browser, and relay traffic through the Tor network (Good Security - Good Performance: This is How We Do It!)
Implementing Tor Options:
1. Tor via Bridge option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "LAN(br0)" for "Redirect all user from." Click "Apply." That's it! All client traffic for a given network is routing through the Tor network.
2. Tor via Device option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "Only Specified MAC's" for "Redirect all user from." Select a device from the list of "MAC" addresses. Click "Add." Click "Apply." That's it! All client traffic for a given device (MAC address) is routing through the Tor network.
3. Tor via Browser option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "Only Specified MAC's" for "Redirect all user from." Add the placeholder MAC address "00:00:00:00:00:00" to the list of "MAC" addresses. Click "Add." Click "Apply." Now, create the following torrc.postconf file:
Code:
# vi /jffs/scripts/torrc.postconf
#!/bin/sh
CONFIG=$1
HOSTIPADDR=$(hostname -i)
source /usr/sbin/helper.sh
if [ "$HOSTIPADDR" != "" ]; then HOSTIPADDR="${HOSTIPADDR}:"; fi
pc_insert "SocksPort 9050" "SocksPort ${HOSTIPADDR}9050" $CONFIG
Code:
# chmod 755 /jffs/scripts/torrc.postconf
# service restart_tor
Done.
# hostname -i
192.168.0.1
That's it! All client traffic for a given Browser is routing through the Tor network.
4. Tor via an Entry (Guard)/Middle (Non-Exit) Relay option: Under Advanced Settings > VPN > Tor - Enable "TOR" and select "Only Specified MAC's" for "Redirect all user from." Add the placeholder MAC address "11:11:11:11:11:11" to the list of "MAC" addresses. Click "Add." Click "Apply." Now, create the following torrc.postconf file:
Code:
# vi /jffs/scripts/torrc.postconf
#!/bin/sh
CONFIG=$1
#DYNIPADDR=$(ip addr show vlan2 | grep -ioE "inet\s(.+)\/[0-9]{1,2}" | sed -E "s/inet\s//g; s/\/[0-9]{1,2}//g;")
DYNIPADDR=$(/opt/bin/dig +short myip.opendns.com @resolver1.opendns.com)
HOSTIPADDR=$(hostname -i)
PORT="443"
source /usr/sbin/helper.sh
# Tor: A non-exit relay should be able to handle 7000 concurrent connections
ulimit -n 7168
#if [ "$DYNIPADDR" = "xxx.xxx.xxx.xxx" ]; then DYNIPADDR="192.168.2.254"; PORT="9001"; fi
if [ "$DYNIPADDR" != "" ]; then DYNIPADDR="${DYNIPADDR}:"; fi
if [ "$HOSTIPADDR" != "" ]; then HOSTIPADDR="${HOSTIPADDR}:"; fi
# Note: The default ORPort 9001 is blocked by our ISP, so we opted to use ORPort 443
pc_insert "SocksPort 9050" "Nickname ASUSWRTMerlinRelay" $CONFIG
pc_insert "Nickname ASUSWRTMerlinRelay" "ORPort ${DYNIPADDR}${PORT}" $CONFIG
pc_delete "SocksPort 9050" $CONFIG
pc_insert "ORPort ${DYNIPADDR}${PORT}" "SocksPort 9050" $CONFIG
pc_insert "SocksPort 9050" "ExitRelay 0" $CONFIG
pc_insert "ExitRelay 0" "DirCache 0" $CONFIG
pc_insert "DirCache 0" "GeoIPFile /opt/share/tor/geoip" $CONFIG
pc_replace "DataDirectory /tmp/.tordb" "DataDirectory /tmp/tor/torrc.d/.tordb" $CONFIG
pc_append "ContactInfo tor-operator@your-emailaddress-domain" $CONFIG
# Note: By default, Tor will try to pick a reasonable MaxMemInQueues based on your system's physical memory
# Uncomment the following line to limit the MaxMemInQueues that Tor can use based on your physical memory
#pc_insert "DirCache 0" "MaxMemInQueues 192 MB" $CONFIG
# Start by setting your MaxMemInQueues to 3/4 (i.e., 192MB) your system's total physical memory (i.e., 256MB)
# Uncomment the following line to include the Tor via Browser option
#pc_insert "SocksPort 9050" "SocksPort ${HOSTIPADDR}9050" $CONFIG
Code:
#vi /jffs/scripts/init-start
#!/bin/sh
# Note: Tor DataDirectory requires a lot of disk space, so we symlinked to our USB 3.0 Interface Device
if [ ! -d "/tmp/tor" ]; then
ln -s /tmp/mnt/SanDiskSDHC/tmp/tor /tmp/tor
fi
Code:
# opkg update
# opkg install bind-dig
# opkg install tor-geoip
# echo $(/opt/bin/dig +short myip.opendns.com @resolver1.opendns.com)
xxx.xxx.xxx.xxx
# chmod 755 /jffs/scripts/torrc.postconf
# chmod 755 /jffs/scripts/init-start
# mkdir -p /tmp/mnt/SanDiskSDHC/tmp/tor/torrc.d
# /jffs/scripts/init-start
# service restart_tor
Done.
Code:
# cat /tmp/torrc
Nickname ASUSWRTMerlinRelay
ORPort xxx.xxx.xxx.xxx:443
SocksPort 9050
SocksPort 192.168.0.1:9050
ExitRelay 0
DirCache 0
GeoIPFile /opt/share/tor/geoip
Log notice file /tmp/torlog
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsOnResolve 1
TransPort 192.168.0.1:9040
DNSPort 192.168.0.1:9053
RunAsDaemon 1
DataDirectory /tmp/tor/torrc.d/.tordb
AvoidDiskWrites 1
User tor
4a. [Optional] Asuswrt-Merlin Tor with Dual WAN: Force Asuswrt-Merlin Tor (upper-case T) to Reload/Start Modified Config Anytime the nat-start Script is Executed
Code:
# vi /jffs/scripts/nat-start
...
# Force Asuswrt-Merlin Tor (upper-case T) to Reload Modified Config
. /jffs/scripts/torrc.postconf
Code:
# vi /jffs/scripts/torrc.postconf
...
# Force Asuswrt-Merlin Tor (upper-case T) to Reload/Start Modified Config
if ! /usr/bin/killall -HUP Tor; then
Tor -f /tmp/torrc --quiet
fi
Code:
# opkg update
# opkg install tor
Code:
# vi /jffs/scripts/torrc.postconf
...
# Force Asuswrt-Merlin Tor (upper-case T) to Reload/Start Modified Config
#if ! /usr/bin/killall -HUP Tor; then
# Tor -f /tmp/torrc --quiet
#fi
# Force Asuswrt-Merlin Tor (upper-case T) to Exit Cleanly to use Entware tor
/usr/bin/killall Tor
Code:
# vi /jffs/scripts/nat-start
...
# Force Entware tor (lower-case T) to Reload Modified Config
. /jffs/scripts/torrc.postconf
Code:
# vi /jffs/scripts/torrc.postconf
...
# Force Asuswrt-Merlin Tor (upper-case T) to Reload/Start Modified Config
#if ! /usr/bin/killall -HUP Tor; then
# Tor -f /tmp/torrc --quiet
#fi
# Force Asuswrt-Merlin Tor (upper-case T) to Exit Cleanly to use Entware tor
/usr/bin/killall Tor
# Force Entware tor (lower-case T) to Reload/Start Modified Config
if ! /usr/bin/killall -HUP tor; then
/opt/sbin/tor -f /tmp/torrc --quiet
fi
5. Tor via a Device/Browser/Relay Hybrid option: Is Tor via Device (Tor Option #2), Tor via Browser (Tor Option #3), and Tor via an Entry (Guard)/Middle (Non-Exit) Relay (Tor Option #4) steps all combined. Simply select a device from the list of "MAC" addresses and/or uncomment the Tor via Browser option within the torrc.postconf file:
Code:
# vi /jffs/scripts/torrc.postconf
...
# Uncomment the following line to include the Tor via Browser option
pc_insert "SocksPort 9050" "SocksPort ${HOSTIPADDR}9050" $CONFIG
Within 48 hours of successful implementation, using a 100Mb/s fiber Internet link and Asus RT-AC66U (256MB) model router, our Tor via an Entry (Guard)/Middle (Non-Exit) Relay is showing up in the Tor Metrics - Relay Search database (search for your Tor "Nickname" or "Fingerprint") as having potential for a Fast-Middle Relay. We'll see where we end up after the 90-day lifecycle.
Enjoy this Tutorial? Checkout some of my other Tutorials:
Tutorial: [SOLUTION] OpenVPN Client Split Tunnel for BitTorrent Traffic
Tutorial: [SOLUTION] OpenVPN Client Split Tunnel Reverse Proxy Web Traffic using Nginx, DNSMasq, and IPTables
Last edited: