ejes consulting

Techincal Consulting Design and Automation

Tutorial: Bittorrents in FreeNAS

with 40 comments

As you might notice, I have been playing around with FreeNAS a lot lately.

Among the many features that I enjoy in the FreeNAS project, one of my very favorite ones is the Bittorrent Server that it has built in.

Really it’s just a verion of Transmission bittorrent web client which I remember from Mac OS.  (http://www.transmissionbt.com/) but running in WebGUI mode (by default on your freeNAS server on port 9091 http://freenas:9091 or similar)

The features that I want specifically is the blocklist feature, which allows you to download a list of blocked ips from known malware locations or otherwise malicious sites, and the ability to encrypt my traffic so that my ISP cannot detect my bittorrent traffic.

So let’s get started:

Step 1:  Let’s open our firewall to let incomming bittorrent connections through.  This will help the speed of my bittorrent client dramatically.  In order to trick my ISP from throttling my connections, I’ll be trying to get bittorrent to look like a VPN.  This is accomplished by allowing only encrypted peers and setting the bittorrent traffic to well known VPN TCP port 1723.  On the firewall I only need to forward the VPN traffic port TCP/1723 on all WAN connections to my FreeNAS server on the same port.

Step 2: Under System| Advanced | rc.conf tab in the FreeNAS webGUI;  add two variables: transmission_blocklist=YES, and transmission_noblocklist=NO.

Step 3: Under Services | Bittorret; set the incomming port the 1723 (the VPN port I set earlier on my firewall), Disable UPNP, and enable Encryption.  Then Save and Restart the service.

Step 4: Download the blocklistdl script from my script repo (http://ejesconsulting.wordpress.com/blocklistdl/).  Its actually the same as the script from (http://sourceforge.net/apps/phpbb/freenas/viewtopic.php?f=60&t=519&start=40).  Place the script in a conveniant directory.  I put mine in my transmission home directory in a subdirectory called “bin”.  I changed the attributes to executable, and owned by “transmission:staff”; the user and group that bittorrent runs as.

Step 5: Add a cron job to the System | Advanced | Cron tab of the FreeNAS Web Gui to run the script at a predetermined time.  I set min to run every Sunday night at midnight.

Step 6: While in the cron tab, I added a few timed download limits so that while I’m asleep or not home the bittorrent client can take 100% of the network bandwith, but while I’m expected to be at home it would reduce it’s available downloads to a fraction of my maximum bandwitdth.

The command is “/usr/local/bin/transmission-remote –no-uplimit –no-downlimit –auth admin:xxxxxxxx” to unlimit and “/usr/local/bin/transmission-remote –uplimit 20 –downlimit 20 –auth admin:xxxxxxxx” to limit to 20Kbps and 20Kbps upload and download while I’m home – please modify these parameters as you see fit.

As always, if you find this useful or need more info I’d be happy to help.

About these ads

Written by ejes

July 20, 2009 at 10:00 am

40 Responses

Subscribe to comments with RSS.

  1. [...] Related links: Bittorrents in FreeNAS « ejes consulting [...]

  2. Great tutorial, really clearly explained. Well done :)


    August 18, 2009 at 1:25 pm

  3. Thanks for taking the time to put this together. I could use some help with step 4. I’m a total novice with BSD, etc… and while I know how to copy the script to a windows wordpad file and then change that to an exe, I’m not sure how to do the equivalent from FreeNAS. I tried doing the above and running the exe via the CRON “Run Now” but get an error each time. Could you explain this step further?



    August 23, 2009 at 9:23 am

    • Thanks for your comment Mark

      step 4 is a FreeBSD Script. You’re correct saving it as a text file, but ensure it’s on the freeBSD (ahem, FreeNAS) server. once you’ve saved it on the freenas server, you have to login and get a command prompt. I use PuttySSH when in the windows world. (it’s free, and really an excellent terminal emulator). Once I am at a command prompt, I use the command “su” to become root. root is the administrative ID, equivalent to the “Administrator” user in Windows. once I’ve become root I navigate to where I saved the script; as i said mine is in /mnt/default/transmission/bin so I issue a “cd /mnt/default/transmission/bin” command. Then i’m at where my executable file is. i change it to “executable” by using chmod a+x blocklistdl. now the file is executable, and can be run by anyone (that’s what the ‘a’ stands for, a(nyone)+(e)x(ecute) :)
      here’s output for your reference:
      mac-mini:~ evanstawnyczy$ ssh user@
      user@′s password:
      Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
      The Regents of the University of California. All rights reserved.

      > su
      nas:/mnt/default/user# cd /mnt/default/transmission/bin
      nas:/mnt/default/transmission/bin# ls
      nas:/mnt/default/transmission/bin# chmod a+x blocklistdl

      now it’s executable and able to be run by hand or by cron. remember that UNIX type systems only run what’s in their path, so you can’t just type “blocklistdl” but instead you have to type “./blocklistdl”:

      Thanks again for your comment Mark. Please feel free to contact me with any other questions or comments.


      August 23, 2009 at 11:31 am

  4. ejes,

    Thank you for your previous explanation. I tried doing what you said, and the permissions were changed correctly on the file, but I still can’t get the script to work. I also tried changing DIR=$(xml sel -T -t -v “/freenas/bittorrent/configdir” /conf/config.xml) to DIR=$(xml sel -T -t -v “/tmpknas/bittorrent/configdir” /conf/config.xml), since my server is named tmpknas. However, I don’t see a bittorrent directory if I cd / and then ls from the root. Do I need to point the DIR somewhere else?
    Here is a copy of my PuTTY session.
    tmpknas:~# cd /mnt/guy/transmission/bin
    tmpknas:/mnt/guy/transmission/bin# ls -lah
    total 18
    drwxrwxrwx 2 ftp wheel 512B Aug 29 05:00 .
    drwxrwxrwx 3 ftp wheel 512B Aug 25 10:41 ..
    -rw-rw-rw- 1 ftp wheel 6.0K Aug 25 10:41 .DS_Store
    -rwxrwxrwx 1 root wheel 823B Aug 29 04:53 blocklistdl
    tmpknas:/mnt/guy/transmission/bin# ./blocklistdl
    ./blocklistdl: Exec format error. Binary file not executable.


    August 29, 2009 at 9:30 am

    • It sounds like you’re missing the shebang at the begnning of your file. For ALL Scripts you must point to the executing program; this is called a shebang.
      The script should be:

      Is that the case?


      August 31, 2009 at 10:04 am

  5. I just recently Installed and connected a FreeNAS Server. PC World had a nice how to guide for setting up an iTunes, Torrent, and file server, and I’m sure some other things I haven’t discovered yet. But I’m trying to move some downloaded things into a directory, and on certain files I get “You require permission from UNIX user\transmission to make changes to this file”.
    How can I go about giving the entire drive an open permission? We connect from a myriad of devices, and would like to be able to access/manipulate anything on the drive, from any device.



    April 2, 2010 at 8:06 pm

  6. Hi I have set everything up the way you said minus the extra transmission crons for changing speeds at different times. My only question is after the script downloads the blocklist how does Transmission know to use the blocklist?


    July 4, 2010 at 1:39 pm

    • Thanks for the comment :)

      In step 2 you set an environment variable, something like:
      transmission_blocklist=YES this is passed to the transmission daemon through the script /etc/rc.d/transmission, which sets the command line option –blocklist if the transmission_blocklist variable is set to YES.


      July 5, 2010 at 8:55 pm

  7. Hi I am getting some weird messages in my log I don’t think the script is working right. Here is whatI am getting http://pastebin.com/GkBPbq8w


    July 8, 2010 at 7:28 pm

    • It looks like your transmission daemon is running in the wrong directory (/var/log) and not in a writeable location. you can just add write to /var/log for the transmission daemon (with: chmod -R a+rwx /var/log/) but realisticly you should probably fix your transmissions home directory settings.
      let me know if you need more help.


      August 5, 2010 at 9:26 am

  8. I think in 0.7.2 they changed the directory for transmission because my blocklists, resume, torrents, dht.dat and settings.json are all at /home/transmission/ and the script downloads everything to /home/transmission/.config/transmission-daemon/


    July 30, 2010 at 2:02 pm

  9. I am getting a ton of these errors lately “transmission-daemon: blocklist skipped invalid address at line 14567 (blocklist.c:286)” not sure why.


    August 5, 2010 at 2:03 am

    • That sounds to me like your transmission daemon isn’t decompressing the “level1.gz” file, go to your blocklist directory (mine is in my “transmission” home directory) and find a level1.gz file, then gunzip it like this:
      gunzip level1.gz
      that should create a “level1″ file. This file contains a list that looks like this (in my file anyway):

      General Electric Company:
      Level 3 Communications:
      Level 3 Communications:
      Level 3 Communications:

      there are literally hundreds of more lines.
      let me know if that works for you.


      August 5, 2010 at 9:23 am

      • I is decompressing the file it is skipping the ones that say reassign to whatever like this:

        reassign to Fujitsu (Thailand) Co., Ltd:

        also my transmission config files are all in /home/transmission but once and a while i check my log after a blocklist update and I see that error about permissions and creation. I’m still waiting to see it again do you have a forum or a better way to communicate?


        August 5, 2010 at 3:31 pm

      • check the /etc/rc.d/transmission script to see if it’s getting your configuration information from the correct place – it sounds to me like it’s not.


        August 23, 2010 at 2:43 pm

  10. Hi it’s me again, I am having a weird issue when ever there is an update for the blocklist it updates it then restarts Transmission with /etc/rc.d/transmission restart and then all my transmission settings get reset my config resets to /var/log/.config and my torrents try to download to /var/log/Downloads I am not sure what is going on because I told it to save my config in /home/transmission which it works in until the restart.


    August 14, 2010 at 3:12 pm

  11. Ok so I upgraded my freenas and this time used stable 0.7.1 everything works except the script says there’s no update available and it wont download the blocklist. Not sure what its comparing the new one too if it hasen’t downloaded one before.


    August 16, 2010 at 11:21 pm

  12. Ok just checked the log today and I am having the same problems as before with transmissionbt trying to make files in /var/log/.config I don’t understand what is going on I told it to use /home/transmission/ for config. It happens when the script finds a new blocklist and then tries to restart transmission. Here is the what I am seeing in my log http://pastebin.com/f3Jy3miu

    Please help I don’t know what is going on thank you.


    August 20, 2010 at 4:27 pm

    • Hi There,

      I was away on vacation – I’ll look at your logs etc tonight and let you know.


      August 23, 2010 at 2:39 pm

  13. ejes, if you can help please contact me at bbrun123@yahoo.com thanks.


    August 20, 2010 at 4:52 pm

  14. Now a bunch of us are getting errors from transmission trying to read the level1.gz file it looks like this http://pastebin.com/hTusxy3K


    August 23, 2010 at 11:01 pm

  15. I fixed the /var/log/.config errors I guess you can’t restart transmission with user group transmission so I had to change my cron job that runs the script to root and now the errors are gone. Everything works now, the only thing that is left to fix is the blocklist import errors here: http://pastebin.com/hTusxy3K

    I think transmission is trying to read the level1.gz file directly. When I manually copy level1 to the blocklists folder I don’t get any errors but if I copy level1.gz there I do. I know the script needs the gz to update so I’m not sure if there is a way to fix it.


    August 24, 2010 at 2:37 pm

    • the script downloads it but doesn’t decompress it. look at the script to see where it decompresses it, when it does ensure that it deletes the .gz file after it decompresses it. transmission is dumb, it’ll open any blocklist file (level1.anything) and try to read it. so what i used to do is have it download to a different directory and have a script of mine move it to the proper place after i ensure everything is decompressed properly.


      August 27, 2010 at 10:32 am

      • Hey I got everything working great now all I had to do is modify the script a little bit and have it download level1.gz to the scripts directory and then move it to the blocklists directory then restart. Here is what I have now. http://pastebin.com/Bm1uE7ms


        September 1, 2010 at 7:00 pm

  16. Hey ejes,

    Got this working with your awesome instructions. Thanks!

    One question, however, I got the script to run successfully, but how do I verify that it’s actually working, doing its thing?

    Thanks again!



    September 15, 2010 at 4:00 am

    • That is, the blocklistdl script…


      September 15, 2010 at 4:05 am

  17. Excellent tutorial just have a question about the “/usr/local/bin/transmission-remote –no-uplimit –no-downlimit –auth admin:xxxxxxxx ” which user and password is referred to here, the bittorrent or a system user? Im a newbie so forgive me if the answer is obvious :)


    September 26, 2010 at 3:08 pm

    • The transmission admin username and password. :)


      September 27, 2010 at 11:58 am

  18. Hi,
    Thanks for the tutorial, works great :) Can I just ask: how would I go about adding a second (level2) blocklist for more security?


    October 24, 2010 at 5:02 pm

    • I will look into it. I haven’t discovered (as yet). I’ll keep you posted.


      October 25, 2010 at 9:17 am

  19. Your directions on Freenas are Great. I am having one issue though, I can not seem to get the Blocklist script to run correctly. I am a Windows user (I know, I know..) and I saved the script to a text file and place it on the server. After making the chmod and chown to it, I keep getting the error, “Failed to execute cron job” when I try and run the script now. Any information would be a HUGE help. Thanks


    January 29, 2011 at 11:41 am

    • Hi Phil,

      The script itself won’t work on windows, unless you’re running bash or possibly some korn shell compliant shell and not windoze “cmd.exe” What I would do if I were you is try to run it with “Microsoft SFU” (services for unix) which includes a nice ksh compatible shell as well as some other posix goodies.



      January 31, 2011 at 4:03 pm

      • I have the same issue as Phil but I’m trying to run it on the Freenas Box. The problem is I don’t know how to create the script on Windows so the script can run on Freenas. Anyone know how to create the Blocklist script on Windows but run it on Freenas?


        April 14, 2011 at 10:36 pm

      • Hey, Ken – I would instead use something developed for windows in this kind of circumstance. Try something like ClamWin (a port of clam antivirus for windows)


        April 15, 2011 at 10:17 am

  20. Hey everyone I noticed that the Transmission level1 url was outdated and even the newer one isn’t updated that much so I modified my script to work with http://iblocklist.com here it is:



    April 15, 2011 at 3:19 pm

    • Awesome!!!! Thanks :)


      April 15, 2011 at 3:31 pm

  21. [...] customization.  If you want to setup scheduled activity then some coding is required.  This tutorial provides a step-by-step way to add the torrent server to your NAS and add additional scheduling [...]

    Bittorrent in Freenas

    August 16, 2011 at 11:32 am

  22. Script works when running under root, but not under transmission. Error: transmission failed to load external entity “/conf/config.xml”. Freenas 7.2.8191.


    October 21, 2011 at 1:12 am

    • root is required, unfortunately because of the protection on /conf/config.xml – which if you read has your passwords in them in PLAIN TEXT.

      one of the reasons I switched from FreeNAS to a pure OpenBSD server running NGINX and WebDAV.


      October 25, 2011 at 11:04 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: