Can your internet router be used as a small webserver?

Oct 10, 2014 11:15 GMT  ·  By

Few people understand why some routers cost $15 and some hundreds of dollars.

There are hardware differences and... software differences.

Using a custom firmware (if supported by the router) can give you options/features available on much more expensive hardware.

Such a firmware is TomatoUSB. It's an open source firmware for Broadcom-based routers.

The first step is to see if your router is supported by Tomato, so please check Shibby Tomato Builds. If it is, get the newest version and flash it on the administration interface.

Usually, there are some flavors: AIO (All in One) or VPN (few features, smaller size, perfect for most users).

If it cannot be flashed through Web interface (like Asus RT-N53), you must use the emergency procedure (see router documentation) to upload the custom firmware to the router.

After you install and set up all the usual settings on Tomato (WIFI, LAN etc.), you can go further, and with some work, you can install many programs, for example a webserver with PHP support or Transmission Torrent client (the router must have USB ports).

Different routers have different flash memory sizes. Inside the flash reside the firmware and settings. Depending on the flash size and firmware size (VPN or AIO), some unused space might still remain, so you can create a JFFS partition to install software. This is critical for routers without USB or if you do not want to use a USB drive. If you do want to use a USB drive, read here how to create a partition, and after you create it, continue this tutorial from #3.

So... let's install some software.

1. Create a JFFS partition.

Go to Administration – JFFS – Enable – Format Erase

In the text box paste:

code
mount -o bind /jffs /opt
Wait a few minutes, and if you do not get any message, reboot the router.

2. Go to Administration – Admin Access and modify the default port settings for router administration (ex: 8082).

Now you can access the admin interface on another port

code
http://ip_router:8082
default: http://192.168.1.1:8082
3. Access the router on SSH using Putty (Windows) or Terminal (Mac). On Mac, the command is:
code
ssh -l root IP
Username must be root and the password of the admin user.

4. Install Optware package manager:

Optware installation code
code
cd /tmp
wget http://tomatousb.org/local--files/tut:optware-installation/optware-install.sh -O - | tr -d '\r' > /tmp/optware-install.sh
chmod 755 optware-install.sh
sh optware-install.sh

This will take some time, depending on your internet speed and router processing power.

5. Install nano (text editor), lighttpd (webserver), and php

code
ipkg install nano
ipkg install lighttpd
ipkg install php-fcgi
6. Edit the lighttpd configuration file:
code
nano /opt/etc/lighttpd/lighttpd.conf
Add this:
code
server.event-handler = "poll"
If you use this tutorial for the Nest Thermostat Hack, you must also add this line:
code
server.error-handler-404 = "/i.php?query=W112BQ"
Modify the default running port of the webserver (default is 8081).
code
server.port       = 80
Save and close nano - (Ctrl+X, Y)

7. Restart the webserver:

code
/opt/etc/init.d/S80lighttpd restart
Now you can put files and scripts in /opt/share/www/

7.1 If you want your webserver to be accessible from WAN, you need to add those lines to the Firewall script (Administration – Scripts – Firewall):

code
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
8. For the Nest Thermostat Hack for unsupported countries, you need to make some modifications. You must create a custom host file.

Go to Advanced DHCP-DNSand add this code to Dnsmasq Custom configuration:

code
addn-hosts=/jffs/hosts
In SSH, enter this command to create the new host file:
code
nano /jffs/hosts
Add line
code
router_IP weather.nest.com
Example: 192.168.1.1 weather.nest.com

Save and close nano - (Ctrl+X, Y)

Restart the dnsmasq service.

code
service dnsmasq restart

Photo Gallery (5 Images)

Tomato Jffs settings
Tomato Jffs settingsTomato administrationports
+2more