OpenWRT, or What else can you do with your router

    Hello, I was prompted to write this article by a similar one , but the server was Raspberry Pi. In my opinion, using this small but powerful enough scarf for this purpose is a little inappropriate, many have a wi-fi router with a USB port, and therefore why plug an entire power supply from the computer into the outlet, letting it be small. but all the same, power consumption when everything is needed is already included in the outlet.
In this article, we will consider installing a torrent download on almost any router with USB and support for OpenWRT firmware. I have Linksys E3000 available, but there is no specific difference in installing and configuring OpenWRT. What we will need for this:

  • Directly a router with a USB connector, ideally of course with two.
  • Flash drive / USB HDD of any size for your needs the more the better.
  • Literally half an hour of free time to deliver and configure everything.
  • Straight arms.


Install / configure OpenWRT

    First of all, I’ll make a reservation that you do everything at your own peril and risk, since there is a possibility of “scorching” your router. We check if your router is in the list of supported devices, for this we go to the OpenWrt website.



    Click on the appropriate link and look for your device in the list there. In principle, the information there is not always up-to-date, I was convinced of this from my personal experience with my router, which is listed on this list as not fully supported , although it is already included in the trunk. It is advisable to remember on which chipset your router is built to facilitate the search for exactly your firmware.



    After that, go to the “Downloads” tab



    Here it’s worth choosing which branch to use stable (Attitude Adjustment) or accordingly “trunk” in the snapshots folder, I’ll immediately notice if your router is a less or less new model, then most likely you will not find it in the stable branch.



    We proceed directly to downloading the firmware.



    After the firmware has downloaded, go to the firmware of your router. To do this, go to its web interface, which is usually located at 192.168.1.1 or 192.168.0.1 , depending on the manufacturer of the router. For more information on the process of flashing and configuring Wi-Fi and everything else for a specific router, you can contact Googleotherwise this article can be stretched to indecent sizes, but we will focus on installing and configuring Transmission.

Install and configure Transmission

     After flashing the router, we start PuTTY if your OS is Windows, if Linux then just start the terminal. In the address field, we drive 192.168.1.1 for PuTTY or a command telnet 192.168.1.1for Linux. After a successful connection, we proceed to install / configure packages.

    There is a small digression before downloading packages. Since there is not enough physical memory in the router, it varies from 4 to 16 megabytes depending on the advancement and price of your router, we should worry about its increase in advance. After all, in any case, we are going to connect a flash drive or hard drive to it, so why don’t we make the router boot directly from the partition on our media? Let's do that! Before all the manipulations with the router, you need to "split" your HDD / flash drive into several sections.

  1. Swap partition (100-200 MB will be enough) * when using HDD, when using a flash drive it is not recommended, since there is a large but still limited supply of rewriting cycles
  2. The section with which the router will be loaded (at your discretion from 50 MB and above) with the Ext3 or Ext4 file system * Here we can use a second flash drive, where it is better to place the boot area and the area for storing downloads on different devices so that it can be easily removed to drop information without turning off the router.
  3. The partition for your downloads / storage all the remaining space is also desirable in Ext3 / 4, if you want to periodically use the media on the computer, then NTFS, but get ready for periodic errors, since Linux is “friends” with this type of FS rather mediocre, you will also have to install one more the package ntfs-3g.

    Of course, all this could be done on the router, but on the computer it all happens much faster and you can use programs with a graphical interface, and not just a command line terminal, which for a beginner significantly speeds up the process. How to do all this on Windows and Linux, again, you can look at Google for the same reason as the first call to this source.

    Let's get started. Enter the commands in the terminal sequentially

opkg update
opkg install block-mount kmod-usb-core kmod-usb2 kmod-usb-ohci kmod-usb-storage kmod-fs-ext4


With these commands, we updated the repository database on the router and installed the packages we needed: kernel modules for USB support and file system modules


block info


And we are looking for our sections on the flash drive / HDD * You did not forget to connect your flash drive / HDD to the router, right?


mount /dev/sdaX /mnt
mkdir /tmp/cproot
mkdir /home
mount --bind / /tmp/cproot
tar -C /tmp/cproot -cvf - . | tar -C /mnt -x                                      
sync 
umount /mnt
umount /tmp/cproot


Here, in return, sdaXyou need to select the section from which we are going to load in the future. All other commands are designed to copy the boot partition of the router to a USB flash drive / HDD.


block detect > /etc/config/fstab


This command writes all found sections for automatic connection to a file /etc/config/fstab. Next, we need to silently edit this file to look:


config 'global'
        option  anon_swap       '0'
        option  anon_mount      '0'
        option  auto_swap       '1'
        option  auto_mount      '1'
        option  delay_root      '0'
        option  check_fs        '0'
config 'mount'
        option  target  '/'
        option  uuid    '7d3abfaf-493a-46bb-9730-1d793ecb9783'
        option  enabled '1'
config 'mount'
        option  target  '/home'
        option  uuid    '7d3abfaf-463a-46db-9730-1d793ecb4593'
        option  enabled '1'
config 'swap'
        option  uuid    '76d36596-5710-4b77-a3a7-02a66d469750'
        option  enabled '1'


We open this file for editing:

vi /etc/config/fstab

You can see how to use this editor here or, again, turn to Google .
Reboot the router. Again we go to the console and check if everything is mounted correctly:

root@OpenWrt:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
rootfs                 2758072    118004   2501828   5% /
/dev/root                 2048      2048         0 100% /rom
tmpfs                    63340        76     63264   0% /tmp
tmpfs                      512         0       512   0% /dev
/dev/sda1              2758072    118004   2501828   5% 


Here you should pay attention to the fact that it rootfsmatches the parameters with /dev/sda1, if so, then we all succeeded. Go to the next item.

Installing the torrent Transmission client.


opkg update
opkg install transmission-daemon transmission-cli transmission-web transmission-remote
/etc/init.d/transmission enable


Open the client settings file and edit to your needs:

vi /etc/config/transmission


config transmission
        option enable 1    #  непосредственно включает клиент
        option config_dir '/etc/transmission'   # расположение фалов настроек клиента
        option alt_speed_down 50   # ограничение скорости
        option alt_speed_enabled false
        option alt_speed_time_begin  540
        option alt_speed_time_day 127
        option alt_speed_time_enabled false
        option alt_speed_time_end 1020
        option alt_speed_up 50
        option bind_address_ipv4 '0.0.0.0'
        option bind_address_ipv6 '::'
        option blocklist_enabled false
        option dht_enabled true
        option download_dir '/home/'  # директория для загрузок
        option encryption 0   # шифрование
        option incomplete_dir '/home'  # директория для не завершенных загрузок
        option incomplete_dir_enabled false # включение/выключение директории для незавершенных загрузок
        option lazy_bitfield_enabled true
        option lpd_enabled false
        option message_level 2
        option open_file_limit 32
        option peer_limit_global 240
        option peer_limit_per_torrent 60
        option peer_port 51413
        option peer_port_random_high 65535
        option peer_port_random_low 49152
        option peer_port_random_on_start false
        option peer_socket_tos 0
        option pex_enabled true
        option port_forwarding_enabled false
        option preallocation 1
        option proxy ""
        option proxy_auth_enabled false
        option proxy_auth_password ''
        option proxy_auth_username ''
        option proxy_enabled false
        option proxy_port 80
        option proxy_type 0
        option ratio_limit 2.0000
        option ratio_limit_enabled false
        option rename_partial_files true
        option rpc_authentication_required false
        option rpc_bind_address '0.0.0.0'
        option rpc_enabled true
        option rpc_password ''
        option rpc_port 9091
        option rpc_username ''
        option rpc_whitelist '127.0.0.1,192.168.1.*'
        option rpc_whitelist_enabled false
        option script_torrent_done_enabled false
        option script_torrent_done_filename ''
        option speed_limit_down 100
        option speed_limit_down_enabled false
        option speed_limit_up 40
        option speed_limit_up_enabled true
        option start_added_torrents false
        option trash_original_torrent_files false
        option umask 18
        option upload_slots_per_torrent 14
        option watch_dir_enabled false
        option watch_dir ''


We launch and check:

/etc/init.d/transmission start


We launch the browser and enter 192.168.1.1:9091 if everything works then that's all.

If this article is of interest to someone, I’m also ready to talk about setting up a “file wash”, raising a VPN server, setting up IPTV on OpenWRT.

    I foresee the opinion of many that on Habré and throughout the Internet it is full of similar instructions, but nevertheless I tried as detailed and simple as possible to paint the entire installation and configuration process. Also recently in OpenWRT the principle of using a flash drive as a root partition has changed a bit, now this information is already available in the project wiki but only in English.

UPD: This article does not describe how to configure the Internet connection from your provider, as there are too many nuances of the settings. Without connecting the router to the Internet, of course, nothing will come of it.

Also popular now: