Set up your own media server using a OpenWRT based router

linux_jr

New Member
Joined
Mar 31, 2020
Messages
2
Reaction score
0
Credits
0
Summary

All around us there is a lot of devices that are computers, but sometimes we don’t how to push the
maximum from them. Routers are also computers which most of the time are embedded systems
using Linux. To share data easily and that data to be easily reached by phones, media players and
other devices is getting very important these days. The aim of this tutorial is to show how to easily
setup a media server for sharing using a router that can be found almost anywhere in these days. In
this tutorial we will be setting up a Samba share directory and a MiniDLNA protocol that is
compatible with DLNA/UPnP networking protocols. In this example I will be using a RUTX10
router.

“Teltonika” is an IoT devices manufacturer. One of the field, where they specializes in is
networking. All “Teltonika” routers use a special OS called “RutOS” which are based on
OpenWRT.

“Teltonika” RUTX10 router specs

CPU
- Quad-core ARM Cortex A7
CPU cores - 4
RAM - 256 MB, DDR3
FLASH - 256 MB SPI Flash
Ethernet - 4x 10/100/1000 Mbps ethernet ports, compliance with IEEE 802.3, IEEE 802.3u,
802.3az standards
Wireless - 802.11ac (WiFi 5) with data transmission rates up to 867 Mbps (Dual Band, MU-
MIMO)
USB - 1x USB 2.0
USB external devices - Possibility to connect external HDD, flash drive, additional modem, printer
(planned)
Storage formats - FAT, FAT32, NTFS
Bluetooth - Bluetooth 4.0 low energy (LE) for short range communication
Input voltage range - 9 - 50 VDC, reverse polarity protection, voltage surge/transient protection
POE - Passive PoE. Possibility to power up through LAN port, not compatible with IEEE802.3af
and 802.3at standards
Power consumption - 11 W Max
Dimensions - 115 mm x 95 mm x 32 mm (H x W x D)
Operating temperature - -40 C to 75 C

More detailed specification you can find by visiting there website here.

1585819464484.png

FIGURE 1 “Teltonika” RUTX10 router

Getting started


First of all we need to get the SDK for “Teltonika” RUTX series router. SDK will be used to
compile the necessary packages for setting up the media server. You can download the SDK from
there wiki website here. You need to download the SDK for RUTX08, RUTX09, RUTX10,
RUTX11 routers.

1585819554615.png

FIGURE 2 RUTX series SDK download site

The next step is to open your terminal and navigate to the directory where you have downloaded the
RUTX series SDK. When standing in your download directory you need to extract the SDK archive
to your desired directory. You can do this using the tar command. Example:

Code:
tar -zxv RUTX_R_GPL_00.02.01.1.tar.gz --directory /path/to/your/path

NOTE: The file name should be changed to your file name to be extracted. Important is that path to
your extracted SDK should not have any spaces. In other way the SDK will not let to build
anything.

After you extracted the SDK archive, you need to navigate to that directory where you have
extracted the SDK files. After navigated to your SDK files directory, you will see that there isanother directory by the name “openwrt-gpl-ipq40xx.Linux-x86_64”.
You need to navigate in to
her.

The next step is to install the necessary packages to build the SDK. Inside this directory there is a
“README” file. You can read it by using any desired text editor. In my case I use vim. Example:
Code:
vim README

If you don’t want to read this file, you can install the necessary packages using apt if your a Debian
or Ubuntu distribution user. Example:
Code:
sudo apt update && sudo apt install -y binutils binutils-gold build-essential bzip2 curl device-tree-
compiler devscripts file flex fuse g++ gawk gcc gcc-multilib gengetopt gettext git groff libc6-dev
libncurses5-dev libpcre3-dev libssl-dev libxml-parser-perl make ocaml ocaml-findlib ocaml-nox
patch pkg-config python2.7 python-dev python-yaml sharutils subversion u-boot-tools unzip vim-
common wget zlib1g-dev

After installing all the necessary packages we can start building the SDK. First of all we need to
build the configuration file for the packages that will be included in the SDK. You can do that by
using the make command. Example:
Code:
make menuconfig

For the first time this command will check if you have all the necessary tools to build the SDK. If
you will be missing a tool, the make command will stop and will print out the error. If everything is
fine, a configuration screen will appear in your terminal like in “FIGURE 3 OpenWRT
configuration
”.

1585819848129.png

FIGURE 3 OpenWRT configuration

In the configuration menu you need to select packages that will be built with the SDK. In this tutorial we need to select only “MiniDLNA” package and “Transmission” package that is a torrent client, because all the other necessary packages are selected by default. To select the “MiniDLNA” package in the configuration menu navigate to “Multimedia→minidlna” and press the space bar to select the package.

1585819867530.png

FIGURE 4 MiniDLNA package selection

To select the “Transmission” package in the configuration menu navigate to “Network→Bittorent” and press the space bar to select the these packages – transmission-daemon-openssl and transmission-web like in “FIGURE 5 Transmission package selection”.
1585852915070.png

FIGURE 5 Transmission package selection

If you want to add more packages, you can navigate around and select packages that you want to
add to your SDK.
Now you need to exit the configuration menu and save the new configuration. On exiting the
configuration menu you will be prompted with a question if you want to save your configuration.
Select yes.

1585819916750.png

FIGURE 6 Configuration saving

Now lets go to the fun part of building the firmware and SDK tools. Before starting the build, we
need to download the packages. Example:
Code:
make download

It may take some time depending on your internet connection.
After download the packages we can start the build. To build the firmware and SDK tools, we need
to execute make command once again. Example:
Code:
make

This process may take some time depending on your computer. We can speed up things giving the
make command some extra jobs. Example:
Code:
make -j4

To know how much jobs you can give to the make command, you need to know how much
processing units are available. Example:
Code:
nproc

The printed out number you should pass to the ‘-j’ argument. On your computer the number can
differ, my computer has 4 processing units available.
Giving extra jobs to the make command speeds up things, but still it takes time to build everything.
Why building everything, something can fail. Then you need to re run the build process with one
processing unit and enabling verbose debug mode. Example:
Code:
make -j1 V=s

If everything build successfully you should get something like in “FIGURE 7 Firmware and SDK
building

1585820061815.png

FIGURE 7 Firmware and SDK building

The RUTX series router firmware and SDK tools are finished building. Next builds will be more
faster. RUTX firmware can be found in the directory “bin/targets/ipq40xx/generic”. The name of
firmware, that should be uploaded to the router, is – openwrt-ipq40xx-qcom-ipq4018-rutx-
squashfs-apps.bin


If more detailed compilation process need to be explained, it can be found here.

Uploading firmware to router

To upload the firmware to the router first of all you need to connect your router to your computer.
How to setup your router you can watch this video.
After connecting your router to your computer, you need to open a web browser and type your
routers IP address. If this is your first time when you have connected your router, IP address should
be 192.168.1.1.

1585820166162.png

FIGURE 8 RUTX router series login screen

In the login screen type your username and password and press the “LOG IN” button.
After logged in, you need to navigate to “System→Firmware→Update firmware”. You should see a
screen like in “FIGURE 8 Update firmware site

1585820188492.png

FIGURE 9 Update firmware site

Next step is to select the firmware you want to upload and press the “UPGRADE” button. After
pressing the button, you need to wait for firmware to be uploaded to the router. In the second screen
press the “PROCEED” button. While the system is upgrading you should see a screen like in
FIGURE 10 System upgrade

1585820261164.png

FIGURE 10 System upgrade

After system upgrade, you should log in to the router and set up your password once again if you
ticked off the keep settings option.

Setting up SMB for file sharing

In this example I will be using a “Western digital” HDD with a storage of 250 GB connected to the
router through USB. You can use any other external storage like an USB flash drive.
After connecting the external storage drive, we need to check if the drive was mounted. You can do
that my navigating to “Status→Logs→Kernel logs” and check the log. I prefer using ssh and
connecting to the router’s command line. You could do that by using ssh command. Example:
Code:

When prompted enter your password. Draw your attention that connecting to routers CLI we use
another username, not admin anymore.
Also you can use a built-in web CLI. You can find the CLI navigating to “Services→CLI”.
When connected to CLI, check your /mnt directory for new mounted devices. Example:
Code:
ls /mnt

1585820342395.png

FIGURE 11 Mounted partitions

If the drive mounted successfully, you should see a new mounted folder in the /mnt directory. If
you have no more mounted devices, the folder name should be sda1. If your storage drive has more
partitions, there should be more than one new partition mounted.

After mounting the external storage drive the next is to set up the SMB server for sharing. Open
your web browser, type in routers IP address, log in and navigate to “Services→Network
Shares→General”. You should see a site like in “FIGURE 12 Network shares”.

1585820398266.png

FIGURE 12 Network shares

Now we have to configure configure the SMB service. In general settings we configure these fields:
1. Enable – switch to on
2. Hostname – write a desired hostname how you want to see your share on the network
3. Description – write a description for your needs
4. Workgroup -you can leave this field as is it
5. Share home-directories – you can disable it if you don’t want that users could reach there home
directories in router if they exist

In the “Shared directories” section press the “ADD” button. In the new appeared configuration we
configure these fields:
1. Name – enter the name of the directory you are sharing to appear as name you have written
2. Path – select the directory you want to share
3. Allowed Users – this selection would not have any selects until you add users in the
“Services→Network Shares→Users” site.
4. Read-only – turn on this if you want that users could not write to your share
5. Browseable – turn on this if you want that users could see your share in the browse list
6. Allow guests – turn on this if you want that not registered users could use your share

After configurated SMB share service, we need to check if the share is working. You need to install
smbclient if you don’t have it already. On Debian based distributions you can use apt command.
Example:
Code:
sudo apt update
sudo apt install smbclient

After installing use smbclient to list available shares: Example:
Code:
smbclient -L 192.168.1.1

You should get the output something similar to “FIGURE 13 Listing SMB server shares”.
1585820514274.png

FIGURE 13 Listing SMB server shares

Next we need to create a directory for mounting the SMB share and mount it. Example:
Code:
sudo mkdir /mnt/smb
sudo mount -t cifs -o sec=none,vers=2.0,uid=$USER //192.168.1.1/external_storage_drive /mnt/smb
ls /mnt/smb -v

You must specify that you use version 2.0, in other way you will get an error and the share will not
be mounted. Sec parameter is to say to the server that you will not use any password. The parameter uid is used to set the owner of the mounted directory. If this parameter isn't set, root user becomes the owner.
If everything went fine, you should see the contents of your share when listed the mounted
directory.

If you need more detailed SMB share configuration you can find it here.

Setting up MiniDLNA media files sharing

SMB share is set up and now we can easily upload files for sharing over the network. This part is
for setting up another service for media devices called “MiniDLNA”. “MiniDLNA” is fully
compatible with DLNA/UpnP clients.
“MiniDLNA” is a simple service comparing with other of this kind services. Also “MiniDLNA” is a
lightweight service.
“Teltonika” RUTX series by default doesn’t have a web site for “MiniDLNA”, but if you really
need it you can download it from here.
All of the setting up will be done from the CLI. You can use your terminal and ssh to connect to
your router or built-in web CLI.
First of all we need to connect to our router’s CLI and open "MiniDLNA” configuration file which
is in directory /etc/config. The only text editor that is in the router, is vim. Example:
Code:
vim /etc/config/minidlna

When open the configuration file, you should see something like in “FIGURE 14 MiniDLNA
configuration file
”.
1585820642307.png

FIGURE 14 MiniDLNA configuration file

We won’t change everything in this configuration file. We will change these fields:
1. Enabled – if this field value is 0, change it to 1
2. Port – if you want that “MiniDLNA” would listen to another port, change this value with the port
number you desire
3. Friendly_name – change this value to change how other devices would see your service on the
network
4. Media_dir – here you can write your directories which ones should be shared over “MiniDLNA”
service. If you want to add more directories to share you should do like in “FIGURE 15 Adding
directories to share

1585820673225.png

FIGURE 15 Adding directories to share

After we are done with the configuration file, we need to start the service. We will start the service
using service command. Example:
Code:
service minidlna start

After starting the service, we need to test it if works. For testing I recommend to use “VLC” player.
Open your “VLC” player ant press “CTRL+L” combination. On the left side of the player you
should see menu like in “FIGURE 16 VLC player menu
1585820726983.png

FIGURE 16 VLC player menu

Click on the “Universal Plug’n’Play” label. If the configuration is correct, you should see
something like in “FIGURE 17 Browsing through MiniDLNA shares”.

1585820744923.png

FIGURE 17 Browsing through MiniDLNA shares

All devices on the network, which supports UPnP protocol, now can see your “MiniDLNA” shares.
One more thing left to do is to set that “MiniDLNA” would always start on boot. For this we will use again service command. Example:
Code:
service minidlna enable

Now, when the router is rebooted you don’t need to worry about if the service started, the service
manager will start it for you.
Also “MiniDLNA” service provides a status website which can be reached through
192.168.1.1:8200 address on your web browser. The IP address of your router can differ depending
on your router configuration.

If you need a more detailed explanation about “MiniDLNA” configuration options, you can find them here.

Setting up Transmission torrent client

In the “Getting started” chapter we selected two Transmission packages: transmission-daemon-openssl and transmission-web. The first one package is the actual torrent client which will download the torrents. Also he will upload the torrent so it’s a good thing to rise up your ratio. The second package is an web interface for the torrent client.
1585853065309.png

FIGURE 18 Transmission web interface
First thing we will setup a watch directory for torrent client. This watch directory will be used for adding a new torrent to the client for download. The client will start downloading torrent automatically.

From this step we need to do a couple of steps in the CLI. As earlier we can use the ssh command or the built-in CLI. If you want to use ssh execute this command:
Code:

Or if you want to use the built-in CLI just navigate to “Services→CLI”.
First of all we need to create a directory for where to put the torrents. I will create a directory in my mounted HDD. Example:
Code:
mkdir /mnt/sda1/torrents

We need to create one more directory which will be used to save the downloaded content from the torrents. Example:
Code:
mkdir /mnt/sda1/torrent_downloads

Also you we can create a directory to store the content of those torrents which are still downloading. Example:
Code:
mkdir /mnt/sda1/torrent_incomplete

So we created tree different directories for storing torrent files and for storing torrent content. Now we need to configure the torrent client. The configuration file for torrent client can be found in the directory /etc/config. Configuration file name is transmission. We need to open it with a text editor. We use vim because it is the only editor on the router. Example:
Code:
vim /etc/config/transmission

It’s a big file so I will not take a picture of it. First of all lets add our computer IP address to the white list. You need to find a line the same as in “FIGURE 19 Transmission configuration white list
1585853172334.png

FIGURE 19 Transmission configuration white list

By default white listed address are localhost and the whole subnet of our local are network. This white list is used to check if you can use the web interface for transmission. If you don’t want to let other people to use the web interface, you can just delete the part with our subnet address and add the IP address of your computer. To get your IP address you can use ip or ifconfig command. Example:
Code:
ip a
ifconfig

The next thing is to add and enable the watch directory. Look for the lines like in “FIGURE 20 Transmission watch dir
1585853205786.png

FIGURE 20 Transmission watch dir

The option watch_dir_enabled we need to change from false to true. In the option watch_dir we need to write our directory which will be monitored for torrent files. In our case it is /mnt/sda1/torrents
Two more steps left in the configuration. Now lets configure the incomplete torrent directory settings. You need to find these lines like in “FIGURE 21 Transmission incomplete torrent dir
1585853225934.png

FIGURE 21 Transmission incomplete torrent dir

The option incomplete_dir_enabled we need to change from false to true. In the option incomplete_dir we need to write our directory which will serve as storage directory for still downloading torrents. In our case it is /mnt/sda1/torrent_incomplete
The last step in our configuration is the completed torrents directory. You need to find these lines like in “FIGURE 22 Transmission torrent download dir
1585853246118.png

FIGURE 22 Transmission torrent download dir

Here we only need to change options download_dir value to our preferred directory for storing downloaded torrent content. In our case it is /mnt/sda1/torrent_downloads
After the configuration is done, save the changes and close the file. Now we need to restart the service of the torrent client. Example:
Code:
service transmission stop
service transmission start

After restarting the service check if the client is working. You can do that by typing this address 192.168.1.1:9091 in your web browser. If everything is fine you should see a site like in “FIGURE 18 Transmission web interface
Now you need to download some torrent files from your torrent provider. The downloaded torrent files move to the directory /mnt/sda1/torrents. Earlier using SMB share we mounted a directory to our computer. You can move the torrent files through the mounted directory. After moving the torrent files to the right directory they should appear in your torrent client like in “FIGURE 23 Transmission downloading torrents
1585853294329.png

FIGURE 23 Transmission downloading torrents

While the torrents are downloading, their content should appear in the directory /mnt/sda1/torrent_incomplete. After the torrents have been downloaded, the client should move them to the directory /mnt/sda1/torrent_downloads
The last step in setting up the torrent client is to configure the torrent client that it would start on boot. You can do that using the service command. Example:
Code:
service transmission enable

Now after any reboot the torrent client should start automatically.
If you need a detailed explanation of every option you can find it here.

Conclusion

Using “Teltonika” RUTX series routers it is easy to setup a media center or any other kind of
service, because all of it’s packages are easily reachable and also supports packages from
OpenWRT.
The configuration provided in this tutorial only works on a local network. If you want to be reached
in a bigger network, you have to configure the firewall. The firewall settings can be found
navigating to “Network→Firewall”. Detailed information on how to configure the firewall can be
found here.
 
Last edited:


You can use OpenWRT on raspberry pi, just you need to change the target to BCM27xx. Then this tutorial can be used on raspberry pi
 

Staff online

Members online


Top