Linksys WRT610N as web server HOWTO

My brother brought me a Linksys WRT610N from the US. It is an 802.11n wireless router with USB storage capabilities. It also has 64MB of RAM and 8MB of flash memory, making it capable enough as a web server. In this article, I will describe how I transformed my pristine WRT610N into a web server. I will try to make it the instructions as usable as possible but my primary intent is to document what I have done for myself.

Although the firmware that comes with the router has support for several services, it does not explicitly have a web server for serving custom webpages so I a reflash is needed. I chose to reflash it with dd-wrt because of dd-wrt’s feature set, hardware support and reputation. I intend to serve wordpress and drupal sites so I didn’t follow the  dd-wrt web server guide and instead installed a php server with mysql support.

Install dd-wrt

  1. Download Linksys WRT610n v2.0 Firmware and Mega Generic
  2. Do a 30-30-30 reset.
  3. Open the router configuration webpage. Go to Administration>Firmware upgrade
  4. Upload Linksys WRT610n v2.0 Firmware and upgrade. Do not turn off the router while uploading.
  5. Wait for about two minutes after the router restarted.
  6. Open the router configuration webpage to check that dd-wrt was successfully installed.
  7. Do another 30-30-30 reset.
  8. Open the router configuration webpage. Go to Administration>Firmware upgrade
  9. Upload Mega Generic and upgrade. Do not turn off the router while uploading.
  10. Wait for about two minutes after the router restarted.
  11. Open the router configuration webpage. Go to Services and enable SSHd.
  12. Click Apply Settings.
  13. Perform initial configuration e.g., make it connect to the Internet.

Notes

  • I prefer mega generic since it has everything but one may opt not to install it or to install a different firmware build. The list of compatible firmwares for 610n can be retrieved by search the router database with 610n as keyword.
  • Linksys WRT610n v2.0 Firmware is a required install when flashing for the first time. It must be installed first before reflashing it with other firmwares.
  • The default settings for the linksys configuration webpage are the following:
    • URL: 192.168.1.1
    • Username: (blank; no username)
    • Password: admin
  • The default settings for the dd-wrt configuration webpage are the following:
    • URL: 192.168.1.1
    • Username: root
    • Password: admin

References

Set up Dynamic DNS (DDNS)

  1. Open the router configuration webpage. Go to Setup>DDNS.
  2. Provide the necessary information. To update multiple hostnames, prefix each hostname, starting from the second, with -a. That is, to update example.org, example.com and example.net simultaneously, the value of the Host name field must be: example.org -a example.com -a example.net
  3. Click Save
  4. Go to Administration.
  5. Append the following line in the Additional Cron Jobs text field:
    */5 * * * * root /usr/bin/killall inadyn && /usr/sbin/inadyn --input_file /tmp/ddns/inadyn.conf
  6. Click Save Settings.

Note

  • I encountered several instances where ddns is not updated. To make sure that it gets updated, I restart inadyn, dd-wrt’s built-in ddns client, every five minutes. This is what steps 4-5 does.

Reference

Set up USB storage

  1. Format USB storage device as outlined in USB storage – DD-WRT Wiki. I used Mandriva’s partition manager (DiskDrake). Aside from using GUI’s, it can also be done by suitable use of fdisk and mkfs.
  2. Open the router configuration webpage. Go to Setup>DDNS.
  3. Enable USB Core Support, USB Storage Support, ext2/ext3 File System Support and at least one of USB 1.0/1.1/2.0 support.
  4. Do not enable Automatic Drive Mount. Other USB support capabilities may be enabled.
  5. Click Apply Settings.
  6. Plug in USB storage device.
  7. ssh into router. Read dmesg to determine the right device file for each partition.
  8. In the router configuration webpage, go to Administration>Commands.
  9. Input the following in the Commands text box (modify as needed):
    sleep 10 && mount /dev/scsi/host0/bus0/target0/lun0/part1 /opt
    sleep 10 && mount /dev/scsi/host0/bus0/target0/lun0/part5 /jffs
    sleep 10 && mount /dev/scsi/host0/bus0/target0/lun0/part6 /mnt
  10. Click Save Startup.

Reference

Install optware, lighttpd, PHP and MySQL

  1. ssh into the router.
  2. Execute the following commands:
    wget www.wlan-sat.com/boleo/optware/optware-install-ddwrt.sh -O - | tr -d ‘\r’ > /tmp/optware-install.sh
    sh /tmp/optware-install.sh
    ipkg-opt install lighttpd php php-fcgi php-mysql php-mbstring mysql
  3. Copy the contents of the default mysql database to /opt/var/lib/mysql/mysql.
  4. Replace /opt/share/mysql/mysql.server with this mysql service script.
  5. Open router configuration webpage. Go to Administration>Commands.
  6. Add the following in the Commands text box:
    /usr/sbin/iptables -I INPUT 1 -p tcp --dport 80 -j logaccept
  7. Click Save Firewall.

Notes

  • I first tried installing and running apache but the router can’t handle it: system load exceeds 1.0 and no webpage served.
  • Apparently, the MySQL package doesn’t successfully create the default mysql database. This will result to failure in starting mysqld. Step 3 works around this bug by directly copying a “pristine” version of the mysql database. I got this by modifying the mysql database from another mysql installation. There are some differences from a real pristine version of the database.
  • Service scripts are not called with start as argument. This results to mysql not being started automatically on startup. I modified the mysql service script to comment out line 78 and insert the following after it:
    if [ -z "$1" ] ; then
    case `echo “$0″ | sed ’s:^.*/\(.*\):\1:g’` in
    S??*) mode=”start” ;;
    K??*) mode=”stop” ;;
    *) mode=”usage” ;;
    esac
    else
    mode=”$1″
    fi

    The modification was based on the lighttpd service script.
  • Optware, the Right Way provides another and possibly more convenient method of installing. I’m a minimal install guy so I didn’t use it.

References

Configure lighttpd

  1. ssh to router.
  2. Edit /opt/etc/lighttpd/lighttpd.conf
  3. Enable (uncomment) mod_rewrite and mod_fastcgi
  4. Add the line: server.event-handler = "select"
  5. Comment out server.port
  6. To enable simple_vhost:
    1. Enable mod_simple_host
    2. Edit the following keys:
      • simple-vhost.server-root
      • simple-vhost.default-host
      • simple-vhost.document-root
  7. To allow a configuration file per virtual per host:
    1. In shell, mkdir /opt/etc/lighttpd/servers.d
    2. Append include_shell "cat /opt/etc/lighttpd/servers.d/*.conf" to lighttpd.conf
  8. Save lighttpd.conf.
  9. Reboot router.

Note

  • mod_simple_vhost automatically creates virtual hosts based on the directory structure of simple-host.server-root. I use the following settings:
    • simple-vhost.server-root=”/opt/share/www/vhosts/”
    • simple-vhost.default-host=”ianalis.is-a-geek.org”
    • simple-vhost.document-root=”/html/”

Leave a Reply