A minimal system-wide Tor routing helper for Linux.
Torsen backs up your current network state, rewrites Tor configuration from a template, takes control of DNS, applies firewall rules, waits for Tor bootstrap, and restores everything cleanly when you disconnect.
- System-wide traffic routing through Tor
- Automatic iptables/ip6tables backup and restore
- Automatic DNS takeover and recovery
- Automatic torrc backup, templating, and restore
- Waits for Tor bootstrap using the control port
- Built-in status, verify, and recover commands
- Editable Tor template with safe runtime placeholders
- Persistent local state for clean rollback
- Simple single-binary CLI
Torsen modifies:
- firewall rules
- DNS configuration
- Tor service configuration
- system networking behavior
You should:
- run it only on systems you understand
- review the source before production use
- test inside a VM or disposable machine first
- always use
verifybefore first connection
Root privileges are required.
When you run torsen connect, the tool roughly does this:
- Backs up current firewall rules
- Stops local DNS-related services if needed
- Backs up and replaces
resolv.conf - Backs up your current
torrc - Renders a Tor config from template
- Restarts the Tor service
- Waits until Tor bootstrap finishes
- Applies firewall rules to route traffic through Tor
- Stays active until you press
Ctrl+C - Restores everything on disconnect
make buildThe binary will be created at:
build/torsensudo make installThis installs:
- binary to
/usr/local/bin/torsen - state directory at
/var/lib/torsen - log directory at
/var/log/torsen
sudo make uninstallTorsen is designed for Linux systems with:
toriptablesiptables-saveiptables-restoreip6tablessystemctl
Optional but useful:
obfs4proxynmcli
Check everything with:
sudo torsen verifysudo torsen verifysudo torsen connectWhen the connection becomes active, Torsen will keep running in the foreground.
Press:
Ctrl+C
to disconnect and restore your original settings.
sudo torsen statussudo torsen disconnectsudo torsen recoversudo torsen connect
sudo torsen disconnect
sudo torsen status
sudo torsen verify
sudo torsen recover
sudo torsen edit
sudo torsen reset-template| Command | Description |
|---|---|
connect |
Start Tor routing workflow and stay attached until interrupted |
disconnect |
Restore previous network and Tor state |
status |
Show current state of Tor, DNS, firewall, and internal state |
verify |
Check whether required system dependencies exist |
recover |
Force cleanup and restore the machine to a clean state |
edit |
Open the custom Tor template in your editor |
reset-template |
Restore the default embedded Tor template |
Torsen reads configuration from:
.env/etc/torsen/.env
It loads the first one that exists.
TOR_USER=tor
TOR_CONTROL_PORT=9051
TOR_CONTROL_PASSWORD=change-this-password
TOR_BOOTSTRAP_TIMEOUT=120
SYSTEM_TORRC_PATH=/etc/tor/torrc
TOR_DNS_PORT=5353
TOR_DNS_IP=127.0.0.1
TOR_TRANSPARENT_PORT=9040
NON_TOR_NETWORKS=192.168.0.0/16 10.0.0.0/8 172.16.0.0/12
RESOLV_CONF_PATH=/etc/resolv.conf
DNS_SERVICE_NAME=
STATE_DIR=/var/lib/torsen
LOG_DIR=/var/log/torsen
LOG_LEVEL=info| Variable | Default | Description |
|---|---|---|
TOR_USER |
tor |
System user used by Tor |
TOR_CONTROL_PORT |
9051 |
Tor control port |
TOR_CONTROL_PASSWORD |
torsen2025 |
Control password used at runtime |
TOR_BOOTSTRAP_TIMEOUT |
120 |
Bootstrap wait timeout in seconds |
SYSTEM_TORRC_PATH |
/etc/tor/torrc |
Main Tor configuration path |
TOR_DNS_PORT |
5353 |
Tor DNS port |
TOR_DNS_IP |
127.0.0.1 |
DNS resolver IP written into resolv.conf |
TOR_TRANSPARENT_PORT |
9040 |
Transparent proxy port |
NON_TOR_NETWORKS |
private networks | CIDRs excluded from Tor redirection |
RESOLV_CONF_PATH |
/etc/resolv.conf |
Path to system resolver file |
DNS_SERVICE_NAME |
empty | Optional DNS service to stop/restart explicitly |
STATE_DIR |
/var/lib/torsen |
State and backup directory |
LOG_DIR |
/var/log/torsen |
Log directory |
LOG_LEVEL |
info |
Console log verbosity |
Recommended: set your own strong
TOR_CONTROL_PASSWORD.
Torsen ships with an embedded torrc template and lets you override it locally.
sudo torsen editsudo torsen reset-templateThese values are automatically replaced when the template is rendered:
{{TOR_USER}}{{TOR_CONTROL_PORT}}{{HASHED_CONTROL_PASSWORD}}{{TOR_TRANSPARENT_PORT}}{{TOR_DNS_PORT}}
You can safely customize things like:
- bridges
- pluggable transports
- exit policies
- logging
- client behavior
- performance tuning
sudo torsen verify
sudo torsen edit
sudo torsen connectIn another terminal:
sudo torsen statusIf anything looks inconsistent:
sudo torsen recoverTorsen stores its working data here by default:
/var/lib/torsen
This may include:
state.jsoniptables.v4.bakip6tables.v6.bakresolv.conf.baktorrc.baktorrc.template
/var/log/torsen/torsen.log
torsen status checks:
- internal state file
- Tor service activity
- DNS hijack marker
- Torsen firewall chains
Typical states:
- CONNECTED through Tor
- PARTIALLY CONNECTED
- NOT CONNECTED
If you see a partial state, run:
sudo torsen recoverCheck:
- your internet connection
- bridge settings in the template
- control port settings
- whether Tor starts manually
- firewall conflicts from other tools
Try:
systemctl status tor
journalctl -u tor -eRun:
sudo torsen recoverIf your machine uses a custom resolver manager, set:
DNS_SERVICE_NAME=your-dns-serviceRun:
sudo torsen recoverThen verify:
sudo torsen status.
βββ cmd/torsen
βββ internal/config
βββ internal/dns
βββ internal/firewall
βββ internal/logger
βββ internal/runner
βββ internal/state
βββ internal/tor
βββ scripts
βββ Makefile
βββ go.mod
| Package | Responsibility |
|---|---|
config |
Reads .env and builds runtime config |
dns |
Takes over and restores system DNS |
firewall |
Backs up, applies, and restores iptables rules |
logger |
Console and file logging |
runner |
Command execution wrapper |
state |
Stores connection and backup metadata |
tor |
Manages torrc, service lifecycle, and bootstrap |
- Keep the CLI simple
- Keep rollback easy and predictable
- Prefer explicit system control over hidden magic
- Stay hackable for custom Tor setups
- Be useful for self-hosted and lab environments
- Linux only
- Requires root
- Assumes
systemctlis available - Assumes an
iptables-compatible environment - Not intended for mobile or desktop portability without adaptation
- Not a replacement for a full security audit
Contributions are welcome.
If you want to improve Torsen, useful areas include:
- tests
- nftables support
- safer restore paths
- stronger defaults
- packaging for distributions
- CI workflows
- docs and examples
Feel free to open:
- issues
- feature requests
- pull requests
This project is open-source and available under the GNU AGPLv3 License.
Thanks for visiting! β