1. Enable Automatic Updates for Packages

One of the most important things to keeps your relay secure is to install security updates timely and ideally automatically so you can not forget about it. Follow the instructions to enable automatic software updates for your operating system.

2. Bootstrap pkg

This article assumes we have already a base installation of FreeBSD running, and only the base system (here, we are running 12.0-RELEASE). That means we do not have any packages installed, or even the pkg packages manager itself (there's no sudo available - we are running commands as root).

To bootstrap and install pkg we should run the following command:

pkg bootstrap
pkg update -f

To follow upstream updates in a "faster way" we recommend changing the 'quarterly' branch used by pkg to its 'latest' branch.

One additional step is to prefer using HTTPS to fetch our packages, and updates - so here we also need an extra package to help us out (ca_root_nss).

Installing the ca_root_nss package:

pkg install ca_root_nss

We are keeping the original setting used by pkg but setting a new one that will override it. So we set up a new directory, and then create a configuration file to override what we need. This configuration file will be /usr/local/etc/pkg/repos/FreeBSD.conf.

Creating the new directory:

mkdir -p /usr/local/etc/pkg/repos

This is how the new configuration file /usr/local/etc/pkg/repos/FreeBSD.conf must look like:

FreeBSD: {
  url: pkg+https://pkg.freebsd.org/${ABI}/latest

After applying all these changes, we update the packages list again and try to check if there's already a new update to apply:

pkg update -f
pkg upgrade -y -f

3. Install tor FreeBSD's Package

Here we can choose to install the latest stable version, like:

pkg install tor

... or install an alpha release:

pkg install tor-devel

4. Configure /usr/local/etc/tor/torrc

This is a very simple version of the torrc configuration file in order to run a Middle/Guard relay on the Tor network:

Nickname    myBSDRelay    # Change your relay's nickname to something you like
ContactInfo your@email    # Please write your email address and be aware that it will be published
ORPort      443           # You might want to use/try a different port, should you want to
ExitRelay   0
SocksPort   0
Log notice  syslog

5. Ensure net.inet.ip.random_id is enabled:

echo "net.inet.ip.random_id=1" >> /etc/sysctl.conf
sysctl net.inet.ip.random_id=1

6. Start tor:

Here we set tor to start at boot time and use the setuid feature, in order to bind to lower ports like 443 (the daemon itself will still run as a regular non-privileged user).

sysrc tor_setuid=YES
sysrc tor_enable=YES
service tor start

7. Final Notes

If you are having trouble setting up your relay, have a look at our help section. If your relay is now running, check out the post-install notes.