What about using your OpenWrt router as OpenWrt torrent downloader box ? Far better than using a smartphone or laptop for this purpose.
There are many openwrt torrent clients,
- ctorrent, very lightweight and robust.
- rtorrent, advanced and high performance, with web GUI support.
- Transmission, high performance, with CLI, web and remote interface.
In this tutorial we're going to use rtorrent and luci-app-rtorrent, for a easy web based torrent downloading. Rtorrent works very well with openwrt, could be automated with a configuration file, but the ncurses based interface really sucks.
I've found Transmission is the most advanced of them, here is how to properly configure Transmission on OpenWrt.
Ctorrent works fine for small sized download, it has less configuration options to mess around and it's really lightweight.
Contents
Install rtorrent and luci-app-rtorrent
The WiFi router must have a USB port to store downloaded files, around 1 MB of free space required to install all necessary packages, make sure you have enough free space on the router's flash or configure openwrt extroot.
- First login to the router with ssh, and make sure it can connect to the internet.
ssh root@192.168.1.1
ping -c 4 google.com # on OpenWrt
- Update the software repository
opkg update # on OpenWrt
Now install necessary packages, rtorrent, wget and screen.
opkg install rtorrent-rpc wget screen # on OpenWrt
- Download the latest luci-app-rtorrent from this github page, currently it's version 0.1.3,
cd /tmp # on OpenWrt wget --no-check-certificate https://github.com/wolandmaster/luci-app-rtorrent/releases/download/latest/luci-app-rtorrent_0.1.3_all.ipk
- Now install luci-app-rtorrent with opkg
opkg install /tmp/luci-app-rtorrent_0.1.3_all.ipk
Opkg will automatically resolve missing dependencies, i.e. it will download them from repository.
The luci-app-rtorrent is written on lua, so it's platform independent, i.e. it works on all devices running openwrt, developers github page here.
Configure OpenWrt torrent
Let's tweak the rtorrent configuration file, which could be found on the current user's HOME directory, which is /root
for the root user.
The configuration file is .rtorrent.rc
, edit it with vi or nano, I'm using this minimal configuration bellow
encoding_list = UTF-8 system.umask.set = 022 port_range = 23877-23877 port_random = no check_hash = no trackers.enable = 1 dht = auto dht_port = 6881 scgi_port = 127.0.0.1:5000 encryption = allow_incoming, try_outgoing, enable_retry directory = /mnt/sda2/downloads/ session = /mnt/sda2/rtorrent/session/ schedule = rss_downloader,300,300,"execute=/usr/lib/lua/rss_downloader.lua"
Here I'm using the /mnt/sda2/downloads
as download folder and /mnt/sda2/rtorrent/session
as working directory for rtorrent, make sure you have edited them according to your system.
Enable rtorrent at startup
To run rtorrent as a daemon at every startup, create an autostart script, /etc/init.d/rtorrent
with vi or nano and paste this configuration there.
#!/bin/sh /etc/rc.common START=99 STOP=99 start () { screen -dmS rtorrent rtorrent } stop () { killall -9 rtorrent }
Now enable autostart and start rtorrent service.
chmod +x /etc/init.d/rtorrent /etc/init.d/rtorrent enable /etc/init.d/rtorrent start
Testing the setup
Open up your favorite browser and enter the IP of LuCI interface, generally 192.168.1.1, login as root with your password. You will notice Torrent option in the menu bar.
Upload torrent files or copy paste the magnet link to start downloading torrent. You could also change the output folder at this step.
Optimizing OpenWrt torrent download speed
As torrent downloading is a memory intensive process, it's better to add some swap space and optimize few kernel parameters.
- To add swap, create a swap file, twice the size of RAM, in my case RAM is 32 MB so swap size is 64MB
dd if=/dev/zero of=/swap_file bs=1M count=64
- Make it a swap file
mkswap /swap_file
- Turn on the swap
swapon /swap_file
The above step is done assuming you are using a extroot setup and have enough free space on the extroot drive. Swap files works as good as dedicated swap partitions.
Add few kernel parameters listed bellow to the /etc/sysctl.conf
file and run sysctl -p
, this will help to improve download speed.
vm.swappiness=95 vm.vfs_cache_pressure=200 vm.min_free_kbytes=4096 vm.overcommit_memory=2 vm.overcommit_ratio=60
To counter the low RAM issue and improve download speed, you should choose a router with a good amount of RAM and a USB 3.0 port, even better a eSATA port. Here's a list of best wifi router under 100 dollars, a few of them supports OpenWrt very well.
Conclusion and Thoughts
That's it, your very own openwrt torrent downloader box, run it 24x7, low power usage and low cost. The tutorial may be not so newbie friendly, but it's awfully easy if you have basic understanding of command line.
If you have any suggestion or question, just leave a comment, I'll be happy to discuss about it. Also don't forget to share this tutorial with friends !!
ok says
this is what im looking for
But i have couple question to ask
1. can we set USB Flashdisk or Maybe Portable drive as save path directory
2. does this also able to download from http (not torrent)
thanks
Mariano says
+1
Marcin says
Error 404 on step 3
Arnab says
Hi, thanks for your feedback, So you can't download the luci-app-rtorrent ? Just visit the git repo and download the leatet version, then upload it to the router and install it with opkg.
Campos says
My rtorrent no seed to private trackers, you can help?
Arnab says
Sorry about that, I never used private trackers, just heard the name.
Anyway you could try Transmission, http://www.pcsuggest.com/transmission-openwrt-torrent-downloader/
thyron says
Thank you for this. 🙂 finally got it right the second time. This was the only thing that was lacking in my router's setup. along with the samba share on the network.
Arnab says
Thanks a lot 🙂
yousaf says
I'm stuck at step 4
[img]http://i.imgur.com/divVprO.png[/img]
Arnab says
Perhaps it's a dependency related issue, sorry I didn't tested it on Gargoyle firmware.
Miguipda says
Well interresting but following me transmission has never had any problem and more it gives remote management.
Arnab says
Thanks for the tip, I've to tune the transmission configuration.