Installing and setting up a TOR relay
published on
Before we begin it is important to remember that not all providers will allow you to use TOR with their services. Make sure to read their terms before proceeding.
It is also worth nothing that, even the ones that allow a relay may not allow an exit server.
Information about installing a TOR relay, post-install tasks and good practices can be found at https://community.torproject.org/relay/setup/guard/. What I have listed below is just the short version that will get you set up quickly.
Installing TOR
Presuming you are running Ubuntu execute the following commands to install the latest version of TOR. Do not just try installing TOR from Ubuntu's own respositories as it doesn't have the latest version.
apt install apt-transport-https
echo "deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $(lsb_release -cs) main" > /etc/apt/sources.list.d/tor.list
echo "deb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $(lsb_release -cs) main" >> /etc/apt/sources.list.d/tor.list
wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null
apt update
apt install tor deb.torproject.org-keyring
Configure TOR as a relay
We need to make sure TOR is set up as a relay and not an exit node on this server. To do so, edit /etc/tor/torrc
and add the following lines at the end of the file:
Nickname myNiceRelay
ContactInfo your@e-mail
Log notice syslog
ORPort 443
ExitRelay 0
SocksPort 0
Make sure to use your own nickname, add your chosen email address and change the port if desired. Whatever port you use make sure it is open in your firewall.
Make sure to restart TOR by executing systemctl restart tor@default
and you should now have a TOR relay installed and running.
Traffic limits
Whilst completing the above steps will set up a TOR relay it is likely that you will also want to limit the amount of traffic that can be used (either for cost reasons or because the provider only gives you a certain amount of data each month).
To do this have a look in the /etc/tor/torrc
file and add the following lines to the bottom of the file
AccountingMax 2 GBytes
AccountingStart month 1 00:00
What the above instructions will do is make sure that TOR can only use 2GB traffic outbound and another 2GB inbound each month. This limit will be reset every 1st of the month at 00:00.
Make sure to restart TOR to implement the traffic limits.
Keep an eye on the amount of traffic going through your server
If you are ever interested how much traffic is going through your server you can install a package called nyx
. Do so by running sudo apt install nyx
. Bear in mind that traffic will start off low at first and ramp up after a while.
Note: It is also worth reading some of the information on the TOR website to help you configure things further should you wish.