How to Create Tor Private Obfs4 Bridges

To create a private obfs4 bridge, you will need a virtual private server (VPS) running Debian 10.

1. Install Firewall

After you first create your server, update all the existing packages:

sudo apt update

sudo apt upgrade

Then install Nftables to implement your server’s firewall:

sudo apt install nftables

sudo systemctl enable nftables

sudo systemctl start nftables

Now add the rules. In the rules below:

sudo nft add rule inet filter input ct state related,established \
    counter accept

sudo nft add rule inet filter input iif lo counter accept

sudo nft add rule inet filter input tcp dport 22 \
    ip saddr YOUR.PC.IP.ADDRESS counter accept
    
sudo nft add rule inet filter input tcp dport 443 counter accept

Drop any unexpected traffic:

sudo nft add rule inet filter input counter drop

Save these rules so that they persist across reboots:

sudo su -c 'nft list ruleset > /etc/nftables.conf'

2. Install Tor

Install the prerequisite package:

sudo apt install apt-transport-https

Add the Tor repositories to your Advanced Packaging Tool (APT) sources list:

sudo vi /etc/apt/sources.list

Press Shift+g to navigate to the bottom of the file. Press the o key to open lines for input. Add lines at the bottom for the Tor project repositories:

deb https://deb.torproject.org/torproject.org buster main
deb-src https://deb.torproject.org/torproject.org buster main

Press the Esc key on your computer keyboard to escape from insert mode. Type :wq and press Enter to write the file to disk and quit the editor.

Add the GNU Privacy Guard (GPG) key used to sign the Tor packages. The escape character (backslash) appears in the commands below to escape a line break. You can, if you wish, omit the escape character and enter the commands as a single line.

sudo apt install gpg

wget -qO- https://deb.torproject.org/torproject.org/\
A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import

gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 \
    | sudo apt-key add -

Update your package lists:

sudo apt update

Install Tor and the Tor Debian keyring from the Tor project repository:

sudo apt install tor deb.torproject.org-keyring

3. Install Obfs4proxy

Install the package for obfs4:

sudo apt install obfs4proxy

Allow obfs4proxy to bind to privileged ports:

sudo setcap cap_net_bind_service=+ep /usr/bin/obfs4proxy

While #18356 is still outstanding, you must also amend two Systemd service files as follows.

Edit the default service file:

sudo vi /lib/systemd/system/tor@default.service

Use the Page Down key on your keyboard. Use the down arrow key to reach the line that says NoNewPrivileges=yes. Press the w key twice to go forward to the word yes. Use the x key three times to delete three characters. Press the a key to append characters. Change the line to read:

NoNewPrivileges=no

Press the Esc key on your computer keyboard to escape from insert mode. Type :wq and press Enter to write the file to disk and quit the editor.

Edit the service file:

sudo vi /lib/systemd/system/tor@.service

Where it says NoNewPrivileges=yes, repeat the process to change it to read:

NoNewPrivileges=no

Type :wq and press Enter to write the file to disk and quit the editor.

Then run:

sudo systemctl daemon-reload

4. Configure Tor

Edit the Tor configuration file:

sudo vi /etc/tor/torrc

Press the keys dG on your computer keyboard to delete the existing lines. Press the i key to enter insert mode. Insert the lines that follow. Note that:

Log notice file /var/log/tor/log
ORPort 9001
AssumeReachable 1
ExtORPort auto
BridgeRelay 1
PublishServerDescriptor 0
ExitPolicy reject *:*
ServerTransportPlugin obfs4 exec /usr/bin/obfs4proxy
ServerTransportListenAddr obfs4 0.0.0.0:443
ContactInfo yourname@example.com
Nickname PonteVecchio

Press the Esc key on your computer keyboard to escape from insert mode. Type :wq and press Enter to write the file to disk and quit the editor.

5. Start Bridge

Start your bridge running with your revised configuration by issuing the command:

sudo systemctl restart tor

6. Construct Bridge Line

Obtain a template for the bridge line:

sudo cat /var/lib/tor/pt_state/obfs4_bridgeline.txt

The template will look like this:

Bridge obfs4 <IP ADDRESS>:<PORT> <FINGERPRINT> \
cert=KkdWiWlfetJG9SFrzX8g1teBbgxtsc0zPiN5VLxqNNH+iudVW48CoH/XVXPQntbivXIqZA \
iat-mode=0

Obtain your bridge’s fingerprint:

sudo cat /var/lib/tor/fingerprint

The results will show your bridge nickname and its fingerprint:

PonteVecchio EFC6A00EE6272355C023862378AC77F935F091E4

Substitute your server’s IP address, your chosen port, and your fingerprint into the bridge line. The results will look like this:

Bridge obfs4 123.45.67.89:443 EFC6A00EE6272355C023862378AC77F935F091E4 \
cert=KkdWiWlfetJG9SFrzX8g1teBbgxtsc0zPiN5VLxqNNH+iudVW48CoH/XVXPQntbivXIqZA \
iat-mode=0

7. Test Bridge

a) Check Tor Log

Check the Tor log file:

sudo cat /var/log/tor/log

You should see a line:

Bootstrapped 100% (done): Done

b) Test TCP Connectivity

Open Windows PowerShell and issue the following command. Replace 123.45.67.89 by your server’s actual IP address and 443 by your choice of port.

Test-NetConnection -ComputerName "123.45.67.89" -Port 443 -InformationLevel "Detailed"

After a minute or so, you should see a line:

TcpTestSucceeded        : True

c) Test from Tor Browser on Windows

Test your bridge from the Tor Browser for Windows, as described in the article How to Use Tor Private Obfs4 Bridges from Windows.

8. Communicate Bridge Line to User(s)

Communicate the bridge line to your user(s) by a secure method such as Signal or Telegram messengers or from a secure website. Note that email is normally not secure.

Signal and Telegram are blocked in several countries. In some cases it may be possible to connect to Telegram using an MTProto proxy. Describing how to use a proxy in Telegram is out of scope for this article.

There is a decision to be made as to whether you install and configure software before or after you enter a censored country.

There is a trade-off here between convenience and security. It is more convenient to install software and configurations in a free country. The risk is that electronic devices may be inspected when entering a censored country. On the other hand, installing software and configurations after arrival may necessitate additional circumvention measures to reach blocked resources. In the worst case, a user may be completely unable to download the required software and configurations.

9. Optionally Install Nyx

If you want to monitor your bridge, you can optionally install the Nyx command-line monitor, previously known as the anonymizing relay monitor (arm):

sudo apt install python3-pip

sudo pip3 install nyx

Edit your Tor configuration file:

sudo vi /etc/tor/torrc

Add the lines:

ControlPort 9051
CookieAuthentication 1

Press the Esc key on your computer keyboard to escape from insert mode. Type :wq and press Enter to write the file to disk and quit the editor.

Start your bridge running with your revised configuration by issuing the command:

sudo systemctl restart tor

Add yourself to the debian-tor group. In the command that follows, replace yourusername by your actual username:

sudo usermod -a -G debian-tor yourusername

Log off and then log on again so that the above command becomes effective.

Invoke Nyx with the command:

nyx

Use the left and right arrows on your computer keyboard to page through the Nyx screens. Press q and then q again to quit Nyx.