Difference between revisions of "Tor"

From ArchWiki
Jump to navigation Jump to search
(→‎Tor configuration: added socksport explanation)
m (→‎Tor configuration: formatting)
Line 409: Line 409:
Tor opens a socks proxy on port 9050 by default -- even if you don't configure one. Set {{ic|SocksPort 0}} if you plan to run Tor only as a relay, and not make any local application connections yourself.
Tor opens a socks proxy on port 9050 by default -- even if you don't configure one. Set {{ic|SocksPort 0}} if you plan to run Tor only as a relay, and not make any local application connections yourself.
{{ic|Log notice stdout}} changes logging to stdout, which is also the Tor default.
{{ic|Log notice stdout}} changes logging to stdout, which is also the Tor default.
{{ic|ControlPort 9051}}, {{ic|CookieAuthentication 1}} and {{ic|DisableDebuggerAttachment 0}} enables {{Pkg|arm}} to connect to Tor and display connections.
{{ic|ControlPort 9051}}, {{ic|CookieAuthentication 1}} and {{ic|DisableDebuggerAttachment 0}} enables {{Pkg|arm}} to connect to Tor and display connections.

Revision as of 16:13, 1 January 2015


Tor is an open source implementation of 2nd generation onion routing that provides free access to an anonymous proxy network. Its primary goal is to enable online anonymity by protecting against traffic analysis attacks.


Users of the Tor network run an onion proxy on their machine. This software connects out to Tor, periodically negotiating a virtual circuit through the Tor network. Tor employs cryptography in a layered manner (hence the 'onion' analogy), ensuring perfect forward secrecy between routers. At the same time, the onion proxy software presents a SOCKS interface to its clients. SOCKS-aware applications may be pointed at Tor, which then multiplexes the traffic through a Tor virtual circuit.

Warning: Tor by itself is not all you need to maintain your anonymity. There are several major pitfalls to watch out for (see: Want Tor to really work?).

Through this process the onion proxy manages networking traffic for end-user anonymity. It keeps a user anonymous by encrypting traffic, sending it through other nodes of the Tor network, and decrypting it at the last node to receive your traffic before forwarding it to the server you specified. One trade off that has to be made for the anonymity Tor provides is that it can be considerably slower than a regular direct connection, due to the large amount of traffic re-routing. Additionally, although Tor provides protection against traffic analysis it cannot prevent traffic confirmation at the boundaries of the Tor network (i.e. the traffic entering and exiting the network).

See Wikipedia:Tor (anonymity network) for more information.


Install tor, available in the official repositories.

The arm (Anonymizing Relay Monitor) package provides a terminal status monitor for bandwidth usage, connection details and more.

Additionally, there is a Qt frontend for Tor in package vidalia. In addition to controlling the Tor process, Vidalia allows you to view and configure the status of Tor, monitor bandwidth usage, and view, filter, and search log messages.

Warning: There are projects that recommend against using vidalia.


By default Tor reads configurations from the file /etc/tor/torrc. The configuration options are explained in man tor and the Tor website. The default configuration should work fine for most Tor users.

There are potential conflicts between configurations in torrc and those in tor.service.

  • In torrc, RunAsDaemon should, as by default, be set to 0, since Type=simple is set in the [Service] section in tor.service.
  • In torrc, User should not be set unless User= is set to root in the [Service] section in tor.service.

Relay Configuration

The maximum file descriptor number that can be opened by Tor can be set with LimitNOFILE in tor.service. Fast relays may want to increase this value.

If your computer is not running a webserver, and you have not set AccountingMax, consider changing your ORPort to 443 and/or your DirPort to 80. Many Tor users are stuck behind firewalls that only let them browse the web, and this change will let them reach your Tor relay. If you are already using ports 80 and 443, other useful ports are 22, 110, and 143.[1] But since these are privileged ports, to do so Tor must be run as root, by setting User=root in tor.service and User tor in torrc.

You may wish to review Lifecycle of a New Relay Tor documentation.

Running Tor in a Chroot

Warning: Connecting with telnet to the local ControlPort seems to be broken while running Tor in a chroot

For security purposes, it may be desirable to run Tor in a chroot. The following script will create an appropriate chroot in /opt/torchroot:

export TORCHROOT=/opt/torchroot

mkdir -p $TORCHROOT
mkdir -p $TORCHROOT/etc/tor
mkdir -p $TORCHROOT/dev
mkdir -p $TORCHROOT/usr/bin
mkdir -p $TORCHROOT/usr/lib
mkdir -p $TORCHROOT/usr/share/tor
mkdir -p $TORCHROOT/var/lib

ln -s /usr/lib  $TORCHROOT/lib
cp /etc/hosts           $TORCHROOT/etc/
cp /etc/host.conf       $TORCHROOT/etc/
cp /etc/localtime       $TORCHROOT/etc/
cp /etc/nsswitch.conf   $TORCHROOT/etc/
cp /etc/resolv.conf     $TORCHROOT/etc/
cp /etc/tor/torrc       $TORCHROOT/etc/tor/

cp /usr/bin/tor         $TORCHROOT/usr/bin/
cp /usr/share/tor/geoip* $TORCHROOT/usr/share/tor/
cp /lib/libnss* /lib/libnsl* /lib/ld-linux-*.so* /lib/libresolv* /lib/libgcc_s.so* $TORCHROOT/usr/lib/
cp $(ldd /usr/bin/tor | awk '{print $3}'|grep --color=never "^/") $TORCHROOT/usr/lib/
cp -r /var/lib/tor      $TORCHROOT/var/lib/
chown -R tor:tor $TORCHROOT/var/lib/tor

sh -c "grep --color=never ^tor /etc/passwd > $TORCHROOT/etc/passwd"
sh -c "grep --color=never ^tor /etc/group > $TORCHROOT/etc/group"

mknod -m 644 $TORCHROOT/dev/random c 1 8
mknod -m 644 $TORCHROOT/dev/urandom c 1 9
mknod -m 666 $TORCHROOT/dev/null c 1 3

if [[ "$(uname -m)" == "x86_64" ]]; then
  cp /usr/lib/ld-linux-x86-64.so* $TORCHROOT/usr/lib/.
  ln -sr /usr/lib64 $TORCHROOT/lib64
  ln -s $TORCHROOT/usr/lib ${TORCHROOT}/usr/lib64

After running the script as root, Tor can be launched in the chroot with the command:

# chroot --userspec=tor:tor /opt/torchroot /usr/bin/tor

or if you use systemd overload the service:

ExecStart=/usr/bin/sh -c "chroot --userspec=tor:tor /opt/torchroot /usr/bin/tor -f /etc/tor/torrc"

Running Tor in a systemd-nspawn container with a virtual network interface

In this example we will create a systemd-nspawn container named tor-exit with a virtual macvlan network interface.

See Systemd-nspawn and systemd-networkd for full documentation.

Host installation and configuration

In this example the container will reside in /srv/container:

# mkdir /srv/container/tor-exit

Install the arch-install-scripts:

# pacman -S arch-install-scripts

Install base, tor and arm and deselect linux as per Systemd-nspawn#Installation_with_pacstrap:

# pacstrap -i -c -d /srv/container/tor-exit base tor arm

Create directory if it does not exist:

# mkdir /var/lib/container

Symlink to register the container on the host, as per Systemd-nspawn#Boot_your_container_at_your_machine_startup:

# ln -s /srv/container/tor-exit /var/lib/container/tor-exit

Virtual network interface

Create a Dropin directory for the container service:

# mkdir /etc/systemd/system/systemd-nspawn@tor-exit.service.d
ExecStart=/usr/bin/systemd-nspawn --quiet --keep-unit --boot --link-journal=guest --network-macvlan=$INTERFACE --private-network --directory=/var/lib/container/%i

--network-macvlan=$INTERFACE --private-network automagically creates a macvlan named mv-$INTERFACE inside the container, which is not visible from the host. --private-network is implied by --network-macvlan= according to man systemd-nspawn.

LimitNOFILE=32768 per Tor#Raise_maximum_number_of_open_file_descriptors.

Setup systemd-networkd according to your network in /srv/container/tor-exit/etc/systemd/network/mv-$INTERFACE.network.

Start and enable systemd-nspawn

Start and enable systemd-nspawn@tor-exit.service.

Container configuration

# machinectl login tor-exit login to the container, see Systemd-nspawn#machinectl_command.

# mv /srv/container/tor-exit/etc/securetty /srv/container/tor-exit/etc/securetty.bak if you get the error described in Systemd-nspawn#Troubleshooting.

Start and enable systemd-networkd

Start and enable systemd-networkd.service. networkctl displays if systemd-networkd is correctly configured.

Configure Tor

See Tor#Running_a_Tor_server.

Tip: It is easier to edit files in the container from the host with your normal editor.


Start/enable tor.service using systemd. Alternatively, launch it from vidalia, or with sudo -u tor /usr/bin/tor.

To use a program over tor, configure it to use or localhost as a SOCKS5 proxy, with port 9050 (plain tor with standard settings) or port 9051 (configuration with vidalia, standard settings). To check if Tor is functioning properly visit the Tor, Harvard or Xenobite.eu websites.

Web browsing

The Tor Project currently only supports web browsing with tor through the Tor Browser Bundle, which can be downloaded from the AUR. It is built with a patched version of the Firefox extended support releases. Tor can also be used with regular Firefox, Chromium and other browsers, but this is not recommended by the Tor Project.

Tip: For makepkg to verify the signature on the AUR source tarball download for TBB, signing keys from the Tor Project (currently 0x63FEE659) must be downloaded from the keyservers and added to the user gpg keyring with:
$ gpg --recv-keys 0x63FEE659


In Preferences > Advanced > Network tab > Settings manually set Firefox to use the SOCKS proxy localhost with port 9050. Then you must type about:config into the address bar and void your warranty. Change network.proxy.socks_remote_dns to true and restart the browser. This channels all DNS requests through TOR's socks proxy.


You can simply run:

$ chromium --proxy-server="socks://localhost:9050"

Just as with Firefox, you can setup a fast switch for example through Proxy SwitchySharp.

Once installed enter in its configuration page. Under the tab Proxy Profiles add a new profile Tor, if ticked untick the option Use the same proxy server for all protocols, then add localhost as SOCKS Host, 9050 to the respective port and select SOCKS v5.

Optionally you can enable the quick switch under the General tab to be able to switch beetween normal navigation and Tor network just by left-clicking on the Proxy SwitchySharp's icon.


Warning: It will not be hard for an observer to identify you by the rare user-agent string, and there may be further issues with Flash, JavaScript or similar.

You can simply run:

$ torify luakit

HTTP proxy

Tor can be used with an HTTP proxy like Polipo or Privoxy, however the Tor dev team recommends using the SOCKS5 library since browsers directly support it.


The FoxyProxy add-on allows you to specify multiple proxies for different URLs or for all your browsing. After restarting Firefox manually set Firefox to port 8118 on localhost, which is where Polipo or Privoxy are running. These settings can be access under Add > Standard proxy type. Select a proxy label (e.g Tor) and enter the port and host into the HTTP Proxy and SSL Proxy fields. To check if Tor is functioning properly visit the Tor Check website and toggle Tor.


The Tor Project has created a custom Polipo configuration file to prevent potential problems with Polipo as well to provide better anonymity.

Keep in mind that Polipo is not required if you can use a SOCKS 5 proxy, which Tor starts automatically on port 9050. If you want to use Chromium with Tor, you do not need the Polipo package (see: #Chromium).


You can also use this setup in other applications like messaging (e.g. Jabber, IRC). Applications that support HTTP proxies you can connect to Privoxy (i.e. To use SOCKS proxy directly, you can point your application at Tor (i.e. A problem with this method though is that applications doing DNS resolves by themselves may leak information. Consider using Socks4A (e.g. with Privoxy) instead.

Instant messaging

In order to use an IM client with tor, we do not need an http proxy like polipo/privoxy. We will be using tor's daemon directly which listens to port 9050 by default.


You can set up Pidgin to use Tor globally, or per account. To use Tor globally, go to Tools -> Preferences -> Proxy. To use Tor for specific accounts, go to Accounts > Manage Accounts, select the desired account, click Modify, then go to the Proxy tab. The proxy settings are as follows:

Proxy type SOCKS5
Port 9150

Note that some time in 2013 the Port has changed from 9050 to 9150 if you use the Tor Browser Bundle. Try the other value if you receive a "Connection refused" message.


Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: cap_sasl.pl is broken with perl 5.20; SSL does also not work with torsocks (Discuss in Talk:Tor#)

Freenode recommends connecting to .onion directly. It also requires charybdis and ircd-seven's SASL mechanism for identifying to nickserv during connection; see Irssi#Authenticating_with_SASL. Start irssi:

$ torsocks irssi

Set your identification to nickserv, which will be read when connecting. Supported mechanisms are DH-BLOWFISH (recommended) and PLAIN.

/sasl set network username password mechanism

Disable CTCP and DCC and set a different hostname to prevent information disclosure: [2]

/ignore * CTCPS
/ignore * DCC
/set hostname fake_host

Connect to Freenode:

/connect -network network frxleqtzgvwkv7oz.onion

For more information check Accessing freenode Via Tor, SASL README or IRC/SILC Wiki article.


Pacman download operations (repository DBs, packages, and public keys) can be done using the Tor network. Though relatively extreme, this measure is useful to prevent an adversary (most likely at one's LAN or the mirror) from knowing a subset of the packages you have installed, at the cost of longer latency, lower throughput, possible suspicion, and possible failure (if Tor is being filtered via the current connection).

Warning: It would be arguably simpler for an adversary, specifically one who desires to indiscriminately disseminate malware, to perform his/her activity by deploying malicious Tor exit node(s). Always use signed packages and verify new public keys by out-of-band means.
XferCommand = /usr/bin/curl --socks5-hostname localhost:9050 -C - -f %u > %o

Running a Tor server

The Tor network is reliant on people contributing bandwidth. There are several ways to contribute to the network.

Running a Tor bridge

This involves making your machine an 'entry node' for people who are having trouble connecting to Tor through traditional methods.


According to https://www.torproject.org/docs/bridges , make your torrc be just these four lines:

   SocksPort 0
   ORPort 443
   BridgeRelay 1
   Exitpolicy reject *:*


If you get "Could not bind to Permission denied" errors on startup, you will need to pick a higher ORPort (e.g. 8080), or perhaps forward the port in your router.

Running a "Middleman" relay

This means that your machine will contribute bandwidth to the 'internal' part of the network, acting as neither an entry nor exit point, merely forwarding bits to and from other Tor nodes/relays.


You should at least share 20KiB/s:

Nickname tornickname
ORPort 9001
BandwidthRate 20 KB            # Throttle traffic to 20KB/s
BandwidthBurst 50 KB           # But allow bursts up to 50KB/s

Run Tor as middleman ( a relay):

ExitPolicy reject *:*

Running a Tor exit node

Any requests from a Tor user to the regular internet obviously need to exit the network somewhere, and exit nodes provide this vital service. To the accessed host, the request will appear as having originated from your machine. This means that running an exit node is generally considered more legally onerous than running other forms of Tor relays. Before becoming an exit relay, you may want to read Tips for Running an Exit Node With Minimal Harrasment.


Using the torrc, you can configure which services you wish to allow through your exit node. Allow all traffic:

ExitPolicy accept *:*

Allow only irc ports 6660-6667 to exit from node:

ExitPolicy accept *:6660-6667,reject *:* # Allow irc ports but no more

By default, Tor will block certain ports. You can use the torrc to overide this.

ExitPolicy accept *:119        # Accept nntp as well as default exit policy

+100Mbps Exit Relay configuration example

If you run a fast exit relay (+100Mbps) with ORPort 443 and DirPort 80 (as recommended in Configuring a Tor relay on Debian/Ubuntu) the following configuration changes might serve as inspiration to setup Tor alongside iptables firewall, Haveged to increase system entropy and pdnsd as DNS cache. It is important to first read Configuring a Tor relay on Debian/Ubuntu.

Note: See Tor#Running_Tor_in_a_systemd-nspawn_container_with_a_virtual_network_interface for instructions to install Tor in a systemd-nspawn container. Haveged should be installed on the container host.
Raise maximum number of open file descriptors

To handle more than 8192 connections LimitNOFILE can be raised to 32768 as per Tor FAQ.


To succesfully raise nofile limit, you may also have to append the following:

tor     soft    nofile    32768
tor     hard    nofile    32768
@tor    soft    nofile    32768
@tor    hard    nofile    32768

Check if the nofile (filedescriptor) limit is succesfully raised with # sudo -u tor 'ulimit -Hn' or # sudo -u tor bash and # ulimit -Hn.

Start tor.service as root to bind Tor to privileged ports

To bind Tor to privileged ports the service must be started as root. Please specify User tor option in /etc/tor/torrc.

Tor configuration

To listen on Port 80 and 443 the service need to be started as root as described in #Start tor.service as root to bind Tor to privileged ports. Use the User tor option in /etc/tor/torrc to properly reduce Tor’s privileges.

SocksPort 0                                       ## Pure relay configuration without local socks proxy

Log notice stdout                                 ## Default Tor behavior

ControlPort 9051                                  ## For arm connection
CookieAuthentication 1                            ## For arm connection

ORPort 443                                        ## Service must be started as root

Address $IP                                       ## IP or FQDN
Nickname $NICKNAME                                ## Nickname displayed in Onionoo

RelayBandwidthRate 500 Mbits                      ## bytes|KBytes|MBytes|GBytes|KBits|MBits|GBits
RelayBandwidthBurst 1000 MBits                    ## bytes|KBytes|MBytes|GBytes|KBits|MBits|GBits

ContactInfo $E-MAIL - $BTC-ADDRESS                ## See OnionTip

DirPort 80                                        ## Service must be started as root
DirPortFrontPage /etc/tor/tor-exit-notice.html    ## Original: https://gitweb.torproject.org/tor.git/plain/contrib/operator-tools/tor-exit-notice.html

MyFamily $($KEYID),$($KEYID)...                   ## Remember $ in front of keyid(s) ;)

ExitPolicy reject XXX.XXX.XXX.XXX/XX:*            ## Block domain of public IP in addition to std. exit policy

User tor                                          ## Return to tor user after service started as root to listen on privileged ports

DisableDebuggerAttachment 0                       ## For arm connection

### Performance related options ###
AvoidDiskWrites 1                                 ## Reduce wear on SSD
DisableAllSwap 1                                  ## Service must be started as root
HardwareAccel 1                                   ## Look for OpenSSL hardware cryptographic support
NumCPUs 2                                         ## Only start two threads

This configuration is based on the Tor Manual.

Tor opens a socks proxy on port 9050 by default -- even if you don't configure one. Set SocksPort 0 if you plan to run Tor only as a relay, and not make any local application connections yourself.

Log notice stdout changes logging to stdout, which is also the Tor default. ControlPort 9051, CookieAuthentication 1 and DisableDebuggerAttachment 0 enables arm to connect to Tor and display connections.

ORPort 443 and DirPort 80 lets Tor listen on port 443 and 80 and DirPortFrontPage displays the tor-exit-notice.html on port 80.

ExitPolicy reject XXX.XXX.XXX.XXX/XX:* should reflect your public IP and netmask, which can be obtained with the command # ip addr, so exit connections cannot connect to the host or neighboring machines public IP and circumvent firewalls.

AvoidDiskWrites 1 reduces disk writes and wear on SSD. DisableAllSwap 1 "will attempt to lock all current and future memory pages, so that memory cannot be paged out".

If # cat /proc/cpuinfo | grep aes returns that your CPU supports AES instructions and # lsmod | grep aes returns that the module is loaded, you can specify HardwareAccel 1 which tries "to use built-in (static) crypto hardware acceleration when available", see http://www.torservers.net/wiki/setup/server#aes-ni_crypto_acceleration.

ORPort 443, DirPort 80 and DisableAllSwap 1 require that you start the Tor service as root as described in #Start tor.service as root to bind Tor to privileged ports. Use the User tor option to properly reduce Tor’s privileges.


If ControlPort 9051 and CookieAuthentication 1 is specified in /etc/tor/torrc, arm can be started with sudo -u tor arm. If you want to watch Tor connections in arm DisableDebuggerAttachment 0 must also be specified.


Setup and learn to use iptables. Instead of being a Simple_stateful_firewall where connection tracking would have to track thousands of connections on a tor exit relay this firewall configuration is stateless.


-A INPUT -p tcp ! --syn -j ACCEPT
-A INPUT -p udp -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -i lo -j ACCEPT

-A PREROUTING -j NOTRACK and -A OUTPUT -j NOTRACK disables connection tracking in the raw table.

:INPUT DROP [0:0] is the default INPUT target and drops input traffic we do not specifically ACCEPT.

:FORWARD DROP [0:0] is the default FORWARD target and only relevant if the host is a normal router, not when the host is an onion router.

:OUTPUT ACCEPT [0:0] is the default OUTPUT target and allows all outgoing connections.

-A INPUT -p tcp ! --syn -j ACCEPT allow already established incoming TCP connections per the rules below and TCP connections established from the exit node.

-A INPUT -p udp -j ACCEPT allow all incoming UDP connections because we do not use connection tracking.

-A INPUT -p icmp -j ACCEPT allow ICMP.

-A INPUT -p tcp --dport 443 -j ACCEPT allow incoming connections to the ORPort.

-A INPUT -p tcp --dport 80 -j ACCEPT allow incoming connections to the DirPort.

-A INPUT -i lo -j ACCEPT allows all connections on the loopback interface.


See Haveged to decide if your system generates enough entropy to handle a lot of OpenSSL connections, see haveged - A simple entropy daemon and how-to-setup-additional-entropy-for-cloud-servers-using-haveged for documentation.

Warning: This configuration assumes your network DNS resolver is trusted (uncensored).

You can use pdnsd to cache DNS queries locally, so the exit relay can resolve DNS faster and the exit relay does not forward all DNS queries to an external DNS recursor.

perm_cache=102400                       ## (Default value)*100 = 1MB * 100 = 100MB
server {
    label= "resolvconf";
    file = "/etc/pdnsd-resolv.conf";    ## Preferably do not use /etc/resolv.conf
    timeout=4;                          ## Server timeout, this may be much shorter than the global timeout option.
    uptest=query;                       ## Test availability using empty DNS queries. 
    query_test_name=".";                ## To be used if remote servers ignore empty queries.
    interval=10m;                       ## Test every 10 minutes.
    purge_cache=off;                    ## Ignore TTL.
    edns_query=yes;                     ## Use EDNS for outgoing queries to allow UDP messages larger than 512 bytes. May cause trouble with some legacy systems.
    preset=off;                         ## Assume server is down before uptest.

This configuration stub shows how to cache queries to your normal DNS recursor locally and increase pdnsd cache size to 100MB.

Uncensored DNS

If your local DNS recursor is in some way censored or interferes with DNS queries, see Resolv.conf#Alternative_DNS_servers for alternatives and add them in a seperate server-section in /etc/pdnsd.conf as per Pdnsd#DNS_servers.


The Tor 0.2.x series provides a built-in DNS forwarder. To enable it add the following lines to the Tor configuration file and restart the daemon:

DNSPort 9053
AutomapHostsOnResolve 1
AutomapHostsSuffixes .exit,.onion

This will allow Tor to accept DNS requests (listening on port 9053 in this example) like a regular DNS server, and resolve the domain via the Tor network. A downside is that it is only able to resolve DNS queries for A-records; MX and NS queries are never answered. For more information see this Debian-based introduction.

DNS queries can also be performed through a command line interface by using tor-resolve. For example:

$ tor-resolve archlinux.org

Using TorDNS for all DNS queries

It is possible to configure your system, if so desired, to use TorDNS for all queries your system makes, regardless of whether or not you eventually use Tor to connect to your final destination. To do this, configure your system to use as its DNS server and edit the 'DNSPort' line in /etc/tor/torrc to show:

DNSPort 53

Alternatively, you can use a local caching DNS server, such as dnsmasq or pdnsd, which will also compensate for TorDNS being a little slower than traditional DNS servers. The following instructions will show how to set up dnsmasq for this purpose.

Change the tor setting to listen for the DNS request in port 9053 and install dnsmasq.

Modify its configuration file so that it contains:


These configurations set dnsmasq to listen only for requests from the local computer, and to use TorDNS at its sole upstream provider. It is now neccessary to edit /etc/resolv.conf so that your system will query only the dnsmasq server.


Start the dnsmasq daemon.

Finally if you use dhcpd you would need to change its settings to that it does not alter the resolv configuration file. Just add this line in the configuration file:

nohook resolv.conf

If you already have an nohook line, just add resolv.conf separated with a comma.


torify will allow you use an application via the Tor network without the need to make configuration changes to the application involved. From the man page:

torify is a simple wrapper that attempts to find the best underlying Tor wrapper available on a system. It calls torsocks with a tor specific configuration file.

Usage example:

$ torify elinks checkip.dyndns.org
$ torify wget -qO- https://check.torproject.org/ | grep -i congratulations

Torify will not, however, perform DNS lookups through the Tor network. A workaround is to use it in conjunction with tor-resolve (described above). In this case, the procedure for the first of the above examples would look like this:

$ tor-resolve checkip.dyndns.org
$ torify elinks

Transparent Torification

In some cases it is more secure and often easier to transparently torify an entire system instead of configuring individual applications to use Tor's socks port, not to mention preventing DNS leaks. Transparent torification can be done with iptables in such a way that all outbound packets are redirected through Tor's TransPort, except the Tor traffic itself. Once in place, applications do not need to be configured to use Tor, though Tor's SocksPort will still work. This also works for DNS via Tor's DNSPort, but realize that Tor only supports TCP, thus UDP packets other than DNS cannot be sent through Tor and therefore must be blocked entirely to prevent leaks. Using iptables to transparently torify a system affords comparatively strong leak protection, but it is not a substitute for virtualized torification applications such as Whonix, or TorVM [3]. Transparent torification also will not protect against fingerprinting attacks on its own, so it is recommended to use it in conjunction with the Tor Browser (search the AUR for the version you want: https://aur.archlinux.org/packages/?K=tor-browser) or to use an amnesic solution like Tails instead. Applications can still learn your computer's hostname, MAC address, serial number, timezone, etc. and those with root privileges can disable the firewall entirely. In other words, transparent torification with iptables protects against accidental connections and DNS leaks by misconfigured software, it is not sufficient to protect against malware or software with serious security vulnerabilities.

To enable transparent torification, use the following file for iptables-restore and ip6tables-restore (internally used by systemd's iptables.service and ip6tables.service).


This file uses the nat table to force outgoing connections through the TransPort or DNSPort, and blocks anything it cannot torrify.

  • Now using --ipv6 and --ipv4 for protocol specific changes. iptables-restore and ip6tables-restore can now use the same file.
  • Where --ipv6 or --ipv4 is explicitly defined, ip*tables-restore will ignore the rule if it is not for the correct protocol.
  • ip6tables does not support --reject-with. Make sure your torrc contains the following lines:
SocksPort 9050
DNSPort 5353
TransPort 9040

See man iptables.


:OUTPUT ACCEPT [17:6239]

-A PREROUTING ! -i lo -p udp -m udp --dport 53 -j REDIRECT --to-ports 5353
-A PREROUTING ! -i lo -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports 9040
--ipv4 -A OUTPUT -d -j RETURN
-A OUTPUT -m owner --uid-owner "tor" -j RETURN
-A OUTPUT -p udp -m udp --dport 53 -j REDIRECT --to-ports 5353
-A OUTPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports 9040


-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
--ipv4 -A INPUT -p tcp -j REJECT --reject-with tcp-reset
--ipv4 -A INPUT -p udp -j REJECT --reject-with icmp-port-unreachable
--ipv4 -A INPUT -j REJECT --reject-with icmp-proto-unreachable
--ipv6 -A INPUT -j REJECT
--ipv4 -A OUTPUT -d -j ACCEPT
--ipv4 -A OUTPUT -d -j ACCEPT
--ipv6 -A OUTPUT -d ::1/8 -j ACCEPT
-A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -m owner --uid-owner "tor" -j ACCEPT
--ipv4 -A OUTPUT -j REJECT --reject-with icmp-port-unreachable
--ipv6 -A OUTPUT -j REJECT

This file also works for ip6tables-restore, so you may symlink it:

ln -s /etc/iptables/iptables.rules /etc/iptables/ip6tables.rules

Then make sure Tor is running, and start iptables and ip6tables:

systemctl {enable,start} tor iptables ip6tables

You may want to add Requires=iptables.service and Requires=ip6tables.service to whatever systemd unit logs your user in (most likely a display manager), to prevent any user processes from being started before the firewall up. See systemd.


Problem with user value

If the tor daemon failed to start, then run the following command as root (or use sudo)

# tor

If you get the following error

May 23 00:27:24.624 [warn] Error setting groups to gid 43: "Operation not permitted".
May 23 00:27:24.624 [warn] If you set the "User" option, you must start Tor as root.
May 23 00:27:24.624 [warn] Failed to parse/validate config: Problem with User value. See logs for details.
May 23 00:27:24.624 [err] Reading config failed--see warnings above.

Then it means that the problem is with the User value, which likely means that one or more files or directories in your /var/lib/tor directory is not owned by tor. This can be determined by using the following find command:

find /var/lib/tor/ ! -user tor

Any files or directories listed in the output from this command needs to have its ownership changed. This can be done individually for each file like so:

chown tor:tor /var/lib/tor/filename

Or to change everything listed by the above find example, modify the command to this:

find /var/lib/tor/ ! -user tor -exec chown tor:tor {} \;

Tor should now start up correctly.

Still if you cannot start the tor service, run the service using root (this will switch back to the tor user). To do this, change the user name in the /etc/tor/torrc file:

User tor

Now modify the systemd's tor service file /usr/lib/systemd/system/tor.service as follows


The process will be run as tor user. For this purpose change user and group ID to tor and also make it writable:

# chown -R tor:tor /var/lib/tor/
# chmod -R 755 /var/lib/tor

Now save changes and run the daemon:

# systemctl --system daemon-reload
# systemctl start tor.service

See also