Sponsored By

Hands-On Linux: Build A BitTorrent Server

Want a distributed file-sharing solution that won't keep your lawyer awake at night? A dedicated Linux box, running as a BitTorrent P2P server, is an ideal solution -- and we'll show you how to build the perfect 'torrent box.

6 Min Read

13. In Firefox, browse to azureus.sourceforge.net, and download the Linux GTK version of Azureus. Save the package to your home directory.

14. To open the archive, double-click "torrserv's Home" on the desktop, then double-click on Azureus_2.3.0.4_linux.GTK.tar.bz2. Click the Azureus folder, then click Extract. By default, this will extract to the desktop in a new folder called azureus. Drag the azureus folder into the torrserv home directory, as shown below:

15. Click to the azureus directory, then double-click the file named azureus. The system will prompt you whether to read or run the file; select Run. After a brief delay, Azureus will open.

16. The configuration wizard will launch. Click Next until you reach the Configuration Wizard Transfer and Connection setup screen. Running a torrent consumes bandwidth, and the nature of torrents is to consume as much bandwidth as possible so long as users are connected to the torrent. So the Max Up Speed defined on this screen should be a value the customer can afford to tie up with uploading on a 24 x 7 basis. In no event should you exceed about 80% of the peak upstream bandwidth available, even if the file-serving is to be the primary online activity; it may impact the efficiency of other outbound traffic.

For our example, we will presume a client who has 25 KB/sec. of upstream bandwidth to devote to serving this torrent. Select Line type of Custom and enter 25 KB/sec. in the Max Up Speed section. When finished, click Next.

As shown below, you will set the maximum upload bandwidth for all torrents here. Don't encroach on the company's maximum bandwidth, as torrents tend to consistently consume all the resources they are given:

17. Configure the port the torrent will be served on. By default, this is port 6881, which should be opened for this machine at the client's firewall. Open incremental ports (6882, 6883, etc.) for each additional simultaneous torrent this machine will serve. For example, if the machine will serve three separate torrent archives, then open ports 6881, 6882 and 6883. Ports 6969 through 7000 will also need to be forwarded to this machine, for reasons which will become clear in Step 19. A different port may be used, if necessary, but avoid overlap with other common traffic ports (such as port 80 HTTP, etc.) Once you have completed configuring the port, click Next.

18. Azureus now selects a directory to store torrent files. By default, this is /home/torrserv/.Azureus/torrents (this is not the same folder the Azureus binaries are stored in!). To accept this setting and launch Azureus, click Finish. The window may open minimized; if so, click the Azureus icon in the bottom taskbar to bring it to the front.

19. Before torrents can be shared, the external tracker must be configured. Open Tools/Options, select the Tracker drop-down, and click Server. This is a large configuration window, but most of the options may be retained as the defaults.

The first field, Tracker external IP address, should be populated by either the computer's IP address if it has a fully public IP, or the client's external network IP if this machine is behind network address translation (NAT). The current IP address can be obtained in a terminal window with the command /sbin/ifconfig.

The next two boxes, Enable tracker on HTTP port, should be checked. This will share the public torrent data on port 6969, the default. But if you require secure HTTP transfer of the torrent data (the information that tells other computers how to download the torrent), turn on the HTTPS tracker on port 7000 instead.

Do not enable external torrents unless the client plans to develop a community where other files may be shared via torrent. Under most conditions, enabling external torrents can create a risk for infringing behavior.

If the torrent should be password-protected (in the case of a limited-audience file), turn on Enable password on torrents. Then input the relevant username and password that downloaders will need to participate.

The Tracker client poll interval, Scrape and cache, and Processing limits sections provide controls for fine-tuning the performance of the torrent and relates to checking the status of each of the peers in the torrent. Accept the defaults. Further down in the window, turn on Log Periodic Statistics.

In the Networks section, leave all of the networks enabled if the torrent will be made publicly available. But if the audience will remain selective, disable I2P and The Onion Router. Click Save to commit these changes. Below is a view of the built-in tracker, a convenient feature of Azureus with many configurable options:

20. Select a file to share with a torrent audience. To do this, load the media on the machine you wish to share via torrent. A single torrent can serve either a single file archive (such as a .zip or .tgz file) or a large directory structure.

For this recipe, we will serve a single archive dubbed fileshare.zip. Obtain the media you wish to share, and copy it via the file browser or shell to a convenient location in the /home/torrserv path. Here's a view of Azureus with no torrent loaded and waiting to seed:

21. In the window menu, click File/Share/File, and browse to the location of fileshare.zip (in this example, in the root of /home/torrserv.) Click OK. This will add the archive to the list of Azureus's torrent data by dividing the file into chunks and creating a .torrent file that contains download information.

Depending on the size of the archive and the speed of the system, this may take a minute or more. Once the filename appears in the "Seeding" list, the file is ready for download. In the screen shot below, our torrent is loaded and a peer is connected, downloading the file as fast as we can send it:

22. All that remains is to publicize the torrent's availability. There are two ways to do this. One is to provide the tracker Web page to outside users. The format for the URL is: http://machine-address:6969 ... So for our recipe, this would be:

This is the view customers will see when they log in to download the torrent. The Web page is provided by Azureus's internal tracker:

The second way is to distribute the direct URL to the .torrent management file by appending /torrents/filename.torrent to the above URL. In our example, this would be:

Once customers sign in using the BitTorrent client of their choice, the torrent will begin sharing, indicated by the number of Peers listed and the usage of upload traffic. Once a peer is 100% complete, it becomes a seed. Then it will act as an upload-only client until the user stops participating.

As I hope this Recipe shows, P2P needn't be a dirty acronym anymore. By giving your clients a safe and effective way of sharing files with their customers, you can help them stretch their bandwidth dollar and open up new avenues of data distribution.

JASON COMPTON is a technology writer who has covered topics ranging from 8-bit entertainment to supercomputing for more than a decade.

Never Miss a Beat: Get a snapshot of the issues affecting the IT industry straight to your inbox.

You May Also Like

More Insights