I have long wanted to "touch hands" Internet services by setting up a web server from scratch and releasing it to the Internet. In this article I want to share my experience of turning a home router from a highly functional device into an almost full-fledged server.
It all started with the fact that the TP-Link TL-WR1043ND router, which served faithfully, ceased to satisfy the needs of the home network, I wanted a 5GHz band and quick access to files on a drive connected to the router. After reviewing specialized forums (w4bsitXNUMX-dns.com, ixbt), sites with reviews and looking at the range of local stores, I decided to purchase Keenetic Ultra.
In favor of this particular device, good reviews from the owners worked:
no problems with overheating (here I had to abandon Asus products);
reliability in operation (here crossed out TP-Link);
ease of setup (I was afraid not to cope and crossed out Microtik).
I had to come to terms with the cons:
no WiFi6, I wanted to take equipment with a margin for the future;
4 LAN ports, I wanted more, but this is no longer a home category.
As a result, we got such a “server”:
on the left is the optical terminal of Rostelecom;
on the right is our experimental router;
a 2 GB m.128 SSD lying around is connected to the router with a wire, placed in a USB3 box from aliexpress, now it is neatly fixed to the wall;
in the foreground is an extension cord with independent shutdown of sockets, the wire from it goes to an inexpensive UPS;
in the background is a twisted pair bundle - at the stage of apartment renovation, I immediately planned RJ45 sockets in the places where the equipment was supposed to be located, so as not to depend on WiFi debris.
So, we have the equipment, we need to configure it:
the initial configuration of the router takes about 2 minutes, we specify the parameters for connecting to the provider (my optical terminal is switched to bridge mode, the PPPoE connection raises the router), the name of the WiFi network and the password - basically everything, the router starts up and works.
We set the forwarding of external ports to the ports of the router itself in the "Network Rules - Forwarding" section:
Now you can move on to the "advanced" part, which is what I wanted from the router:
functionality of a small NAS for a home network;
performing the functions of a web server for several private pages;
personal cloud functionality for accessing personal data from anywhere in the world.
The first is implemented by built-in tools, without requiring much effort:
we take the drive intended for this role (flash drive, memory card in the card reader, hard drive or SSD in the external box and format it in Ext4 using MiniTool Partition Wizard Free Edition (I do not have a computer with linux at hand, there you can use the built-in tools). As I understand it, during operation, the system writes only logs to the flash drive, therefore, if they are limited after setting up the system, you can also use memory cards, if you plan to write a lot and often to the drive, SSD or HDD is better.
After that, we connect the drive to the router and observe it on the system monitor screen
We go by clicking on "USB drives and printers" in the "Applications" section and configure the share in the "Windows Network" section:
And we have a network resource that can be used from computers running Windows, connecting if necessary as a disk: net use y: \192.168.1.1SSD / persistent: yes
The speed of such an impromptu NAS is quite sufficient for home use, it uses the entire gigabit over the wire, over WiFi the speed is about 400-500 megabits.
Setting up the storage is one of the necessary steps to set up the server, then we need to:
— buy a domain and a static IP address (you can do without this using Dynamic DNS, but I already had a static IP, so it turned out to be easier to use free Yandex services — delegating a domain there, we get DNS hosting and mail on our domain);
It takes several hours for the domain and DNS delegation settings to take effect, so we are simultaneously configuring the router.
First you need to install the Entware repository, from which we can install the necessary packages on the router. I took advantage this instruction, but did not upload the installation package via FTP, but created a folder directly on the previously connected network drive and copied the file there in the usual way.
Having gained access via SSH, change the password with the passwd command and install all the necessary packages with the opkg install [package names] command:
During the configuration, the following packages were installed on the router (the result of the output of the opkg list-installed command):
Perhaps something superfluous got stuck here, but there is a lot of space on the drive, so I didn’t understand it.
After installing the packages, we set up nginx, I tried with two domains - the second one is configured with https, and while the stub is hanging. 81 and 433 internal ports instead of 80 and 443 are used, because the router admin panels hang on normal ports.
In order for the site to work on https, I used the well-known dehydrated script by installing it by this instruction. This process did not cause any difficulties, it stumbled only on the fact that in the text of the script for working on my router comment out the line in the file /opt/etc/ssl/openssl.cnf:
[openssl_conf]
#engines=engines
And I note that the generation of dhparams.pem by the command “openssl dhparam -out dhparams.pem 2048” on my router takes more than 2 hours, if it were not for the progress indicator, I would lose patience and reboot.
After receiving the certificates, restart nginx with the "/opt/etc/init.d/S80nginx restart" command. In principle, this completes the setup, but there is no site yet - if we put the index.html file in the /share/nginx/html directory, we will see a stub.
To place information beautifully, it is easier for a non-professional like me to use ready-made templates, after a long search of various directories I found templatemo.com - there is a good selection of free templates that do not require mandatory attribution (which is rare on the Internet, most of the templates in the license require you to save a link to the resource from which they were obtained).
We choose a suitable template - there is one for a variety of cases, download the archive, and unpack it into the /share/nginx/html directory, you can do this already from your computer, then edit the template (minimum knowledge of HTML is required here so as not to violate the structure) and replace the graphics as shown in the figure below.
Summary: the router is quite suitable for hosting a light site on it, in principle - if a large load is not expected, you can put and php, and experiment with more complex projects (I look at nextcloud / owncloud, it seems there are successful installations on such hardware). The ability to install packages increases its usefulness - for example, when it was necessary to protect the RDP port of a PC on the local network, put knockd on the router - and port forwarding to the PC was opened only after port knocking.
Why a router and not a regular PC? A router is one of the few computer hardware that works around the clock in many apartments, a home router is usually absolutely silent and a light site with less than a hundred visits per day will not bother him at all.