How To Install And Use Tor As A Proxy In Ubuntu Or Linux Mint

Tor (The Onion Router) logo png

Tor (The Onion Router) directs Internet traffic through a volunteer overlay network, with the purpose of protecting the user's privacy and freedom.

This article explains how to install the latest Tor in Ubuntu 18.04 or 16.04 / Linux Mint 19.x and 18.x, and using it as a proxy with various applications.

The instructions below include steps for setting up Privoxy, in case you want to use Tor with an application that doesn't support SOCKS5 proxies, manually setting up the proxy in case torsocks fails to launch an application, as well as configuring Tor to use country-specific exit nodes (so you can specify from which country your new IP should be), useful if you want to bypass country restrictions / censorship and you don't afford a VPN (but if you can, go for the VPN option!).

This should work in Ubuntu 16.04 / Linux Mint 18.x, Ubuntu 18.04 (and 18.10) / Linux Mint 19 (and 19.x), and newer, as well as Linux distributions based on Ubuntu, like elementary OS, and Ubuntu or Linux Mint flavors, like Linux Mint MATE or Kubuntu, Xubuntu, Ubuntu MATE, and so on.

Ubuntu versions older than 16.04 / Linux Mint older than 18.x don't use systemd, so some things in this article won't work for such old versions.

Tor does not prevent online services from determining that you're using Tor so keep this in mind! This should be used for privacy, and not anonymity.  If all you need a web browser using Tor, use Tor Browser which uses Firefox ESR as its base, is very easy to use, and it includes everything you need. This article is for using Tor with other applications.

Installing Tor and optionally Privoxy in Ubuntu or Linux Mint


I. Install Tor in Ubuntu or Linux Mint

The Tor package from the Ubuntu repositories is usually not updated frequently, so it's recommended you use the official Tor repository instead.

Start by installing apt-transport-https, needed in order to use https repositories:

sudo apt install apt-transport-https

And then add the Tor repository (and its key) in Ubuntu using these commands:

sudo sh -c 'echo "deb https://deb.torproject.org/torproject.org/ $(lsb_release -cs) main" >> /etc/apt/sources.list.d/tor.list'

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89

sudo apt update

For Linux Mint, replace $(lsb_release -cs) in the first command with the Ubuntu version codename your Linux Mint version is based on. For Linux Mint 19 (and 19.x), use bionic, while for Linux Mint 18.x use xenial.

Now you can install Tor, tor-geoipdb (to be able to use country specific exit nodes), torsocks (a library to easily torify applications) and deb.torproject.org-keyring (a package that makes sure you have the latest repository signing key):

sudo apt install tor tor-geoipdb torsocks deb.torproject.org-keyring

II. Optionally install Privoxy and configure it for use with Tor

Privoxy is a non-caching web proxy. You can use it with Tor if you plan on using Tor with applications that only support HTTP proxies (don't support SOCKS5 proxies).

To install Privoxy in Ubuntu or Linux Mint, use:

sudo apt install privoxy

To use Privoxy with Tor you'll need to edit its /etc/privoxy/config configuration file with a text editor, like Nano (as root):

sudo nano /etc/privoxy/config

In this configuration file, paste the following line at the end, without changing anything else:

forward-socks5 / localhost:9050 .

There's a space and then a dot at the end of the line, that is not a typo.

Then save the file and exit (to save the file using Nano command line text editor, press Ctrl + O, then Enter; exit using Ctrl + X).

Now you'll need to restart Privoxy:

sudo sudo systemctl restart privoxy

Using Tor and Privoxy in Ubuntu or Linux Mint


I. Using Tor via torsocks

To easily launch an application and make it use Tor, you can use torsocks, which works with both GUI and command line programs. This library ensures that DNS requests are handled safely and explicitly rejects any traffic other than TCP from the application you're using.

For example, to launch Sporify with torsocks, use:

torsocks spotify

To test it, run this command to get your real IP address:

curl ipv4.icanhazip.com

(In case curl is not installed, you can install it using: sudo apt install curl)

And then run the same command but using torsocks:

torsocks curl ipv4.icanhazip.com

The torsocks command should return a different IP because it was ran through the Tor proxy.

If you get an error, the Tor service may not be running. It should be automatically started when it's installed, but in case it's not, you can start it using this command:

sudo systemctl start tor

There is a problem with torsocks though - it fails to launch some applications. For example, running torsocks firefox or torsocks google-chrome does nothing. For such cases, you'll need to enter the Tor SOCKS5 proxy manually in the application you want to use - see below.

II. Enter the proxy address manually

Once you install Tor and Privoxy, you can use the following proxy information (you only need to set up one of these two) in the application network / proxy settings:

  • SOCKS5 proxy: use localhost as the proxy host / IP, and 9050 as the port
  • HTTP proxy (requires Privoxy installed and configured as explained): use localhost as the proxy address and 8118 as the port

Use a SOCKS5 proxy where possible or, if the application doesn't support it, use a regular HTTP proxy instead.

You can also use Tor as a system-wide proxy. For example in Gnome go to System Settings > Network, click on Network Proxy, set the proxy to Manual, then use localhost as the Socks Host and 9050 as the port:

</code></span>

Note that Chromium-based web browsers (Google Chrome, Opera, Vivaldi, etc.) don't allow setting a proxy in their settings and instead use the system-wide proxy.

III. How to change the IP address given by Tor

In case you need to change the IP address given by Tor, the easiest way is to reload the Tor service, like this:

sudo systemctl reload tor

This command will reload the Tor configuration and get Tor to set up a new circuit, giving you a new IP address.

Check the IP address using the torsocks curl ipv4.icanhazip.com command.

IV. How to configure Tor to use country specific exit nodes (choose from which country your new IP should be)

To be able to specify country specific exit nodes in Tor, the tor-geoipdb package needs to be installed. This package is mentioned in the instructions above, so it should already be installed, but I thought I'd mention this in case you already had Tor installed and skipped the installation instructions from this article.

To use Tor to change your IP to a specific country IP, you'll need to edit the Tor /etc/tor/torrc configuration file as root:

sudo nano /etc/tor/torrc

Add the following two lines to the file, without changing anything else:

ExitNodes {COUNTRY_CODE}
StrictNodes 1

Replace COUNTRY_CODE with the 2 letter ISO3166 country code, for example use us for the United States, de for Germany, and so on. You can find a list of country codes here. You can also specify multiple countries by separating them with a comma, like this: {country1},{country2},{country3}, for example {be},{pl},{ca}. The countries need to be specified between curly brackets: {}.

When you're done, save the file and exit (to save the file using Nano command line text editor, press Ctrl + O, then Enter; exit using Ctrl + X), and reload the Tor configuration using this command:

sudo systemctl reload tor

No comments: