Setting up a Tor Relay

I wrote a project last night, using PyLoris over Tor to create a variable-source layer 7 DoS attack:

p5x-122-Pyloris.html

I got this tweet from @sebastianhahn after publishing it:

@sambowne Right, it also overloads the Tor network and makes it harder for people to use it in every day life. You're part of the problem.

He has a point, here I am using Tor for my projects without contributing to it. And I have a Ubuntu server available, so I wondered how hard it would be to make it a Tor relay.

I decided to time the process, and as you can see below, it took less than one hour, including reading the docs, making mistakes, testing it, and writing these notes.

Live Log of Setup Process

-------------------------------------
10:19 am at Starbuck's, just starting to set up a Tor Exit Node.

Reading https://www.torproject.org/docs/tor-doc-relay.html.en

First I need to set up Tor, I see, reading https://www.torproject.org/download/download.html.en

Linux instructions: https://www.torproject.org/docs/tor-doc-unix.html.en

"Don't use the one in the Ubuntu repositories", it says.  Instead, do this:

https://www.torproject.org/docs/debian.html.en#ubuntu

I am using Ubuntu 10.04, cat /etc/debian_version says it is "Squeeze".
But apparently there are ubuntu-specific items, for "lucid".  Oh, I see, 
that's what lsb_release -c shows.

nano /etc/apt/sources.list, adding
deb     http://deb.torproject.org/torproject.org lucid main

Then this:

gpg --keyserver keys.gnupg.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -

apt-get update
apt-get install tor tor-geoipdb

OK, supposedly it is running, but how to test it?  I only have an 
SSH session on a remote server.  I could connect X to get graphical output,
but I'd rather not.

lsof -i :9050 shows tor running, that's a good sign.

Oh, here's an easy way to test it, from

http://forlackofacontingencyplan.tumblr.com/post/13248617923/pyloris-fake-ddos-attack-using-the-tor-network

tor-resolve google.com

It works!

TIMECHECK: 10:34 AM ----------------

Coffee not even half gone yet :)

Step One done, back to step two here:

https://www.torproject.org/docs/tor-doc-relay.html.en

It recommends setting up NTP, which I want to do anyway.

https://help.ubuntu.com/8.04/serverguide/C/NTP.html

ntupdate is not installed, I see.

apt-get install ntupdate -- fails, no such package.

Oh, D-uh.  It's ntpdate.

nano /etc/cron.daily/ntpdate 

Add this line

ntpdate ntp.ubuntu.com

chmod 755 /etc/cron.daily/ntpdate

To test it, I'll run 

ntpdate ntp.ubuntu.com

at the command line right now.  My time was off by 320 seconds, which
I suspected from my strange timestamps on packet captures.

To confirm, run

ntpdate ntp.ubuntu.com

again.  Now it's only off by 4 milliseconds :)

TIMECHECK: 10:45 am ------------------------

nano /etc/tor/torrc

scroll down to 
################ This section is just for relays #####################

Uncomment:

ORPort 9001

Nickname samsclass-tor-relay

Address attack.samsclass.info

RelayBandwidthRate 100 KB  # Throttle traffic to 100KB/s (800Kbps)
RelayBandwidthBurst 200 KB # But allow bursts up to 200KB/s (1600Kbps)

  OK, how many Gigs per month do I have anyway?  Checking my contract...
  It is apparently unlimited!  I'll make it 4 GB per day.

## Set a maximum of 4 gigabytes each way per period.
AccountingMax 4 GB
## Each period starts daily at midnight (AccountingMax is per day)
AccountingStart day 00:00

ContactInfo Sam Bowne sbowne@ccsf.edu                

DirPort 9030 # what port to advertise for directory connections

Done editing torrc

The docs say it will just start working soon, within 20 minutes.

watch "tail /var/log/tor/log"

Client functionality was working at "18:42" -- 14 minutes ago, 
one second after I reset the time.

TIMECHECK: 11:00 am -----------------------

It took 42 minutes from scratch, and supposedly it will be automatic now.

I'll do other things for 20 minutes and see.

Wait, the graphical document seems to indicate that restarting the
relay is a good thing to do.

service tor restart

Yikes!   My nickname is illegal!

nano /etc/tor/torrc

Changing it to samsclass

service tor restart

Works now :)

watch "tail /var/log/tor/log"

Nov 24 19:02:57.119 [notice] Self-testing indicates your ORPort is reachable fro
m the outside. Excellent. Publishing server descriptor.

TIMECHECK: 11:04 am-----------------------

Checking at 

http://194.109.206.212/tor/status-vote/current/consensus

My relay is not there yet, but that might take an hour.

11:18, my relay is still not on the list...

Yay! My relay just appeared on the list, at 12:02 PM 11-24-11:


Last modified 12:03 pm 11-24-11

Written by Sam Bowne