1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using HyperWRT as Web Server

Discussion in 'HyperWRT Firmware' started by atzplzw, Nov 26, 2004.

  1. atzplzw

    atzplzw Network Guru Member


    I want to use my WRT54GS as a web server. I know it hasn't much power but I don't care.
    I just wanna give it a try and see how it works. So how can this be done?

    I can use https to run the default httpd and port 80 can be used then. So what is the syntax of httpd to direct it to another dir?

  2. atzplzw

    atzplzw Network Guru Member

    Ah! I forgot: Do iptables need to be modified or something?
    Since port 80 needs to be available to the outside...

  3. littlewhoo

    littlewhoo Network Guru Member

    Logon to the device with ssh or telnet. Create a new directory and put the websites you want to serve in this directory. "cd" to this directory and enter the command

    httpd -p 1234

    (where 1234 should be replaced by the port, you want to use for your webserver)

    Do not use port 80 for this webserver, because this port is already being used by the httpd process serving the webinterface.

    Be aware, that the custom httpd on the WRT54G(S) has some limitations:

    1.) http-auth is hardcoded in the binary, so you'll always get the authetication window of the webinterface. Even if you want to access your own webpages on a second httpd instance.

    2.) This httpd version doesn't support cgi scripting. If you want to do scripting stuff, you'll have to use asp.

    3.) All files to be served by httpd must have the file extension .asp
    Even if they contain no asp at all, but just plain html!

    So probably the best thing to do if you want to use the WRT54G(S) as a webserver, would be to recompile httpd without these limitations for the WRT54G(S).

    If you don't know how to do that, you can just extract busybox from the batbox distribution http://www.batbox.org/wrt54g-linux.html , upload it to your WRT54G(S) and use the httpd version which is included there (full cgi support, no harcoded http-auth). The disadvantage of this method is, that you have to upload the complete busybox binary (~1 MB), which includes much more applications than only httpd, to the router. But most of these additional applications like ftpput or ftpget can be really useful. So it might not a bad idea after all to have the full busybox suite on the router.
    After copying busybox to the router, you'll have to create proper links to be able to use httpd
    ln -sf /var/bin/busybox /var/bin/httpd
    (where /var/bin/busybox should be replaced by the path where you have stored budybox and /var/bin/httpd indicated, where the link to httpd should be created)

    Or perhaps you can find somebody else, who has already recompiled only httpd for the WRT54G(S).

    Regarding your IPTABLES question: yes, you'll certainly have to do some modificatins for your webserver being accessible from the outside. But I don't know much about IPTABLES and I'm using my WRT54G-webserver only on the intranet. So I can't help you with the IPTABLES stuff.
  4. bakajikara

    bakajikara Network Guru Member


    so you mean it's really possible without any big hassle to do something like
    voidmain did on one of his wrt54 boxes using openWRT (see urls below) ?

    KEWWWWLLLLL!!!! i really appreciate this and have been waiting for somebody giving a little hint and advisory how to do this using hyperWRT:))


    could you, perhaps, give a little more detailed info on how to do this trick via batbox and hyperwrt on the 54gs?

    special thanks,
  5. littlewhoo

    littlewhoo Network Guru Member

    I've tested the following instructions with the Sveasoft Satori Firmware. But I'm pretty sure, that no Sveasoft specific stuff ist used during this process. Afaik except the SSH/Telnet access all involved tools like wget are already part of the standard Linksys firmware. So this should also work with HyperWRT.

    1.) Download Jim Buzbee's Batbox Distro for the WRT54G

    2.) Extract the file "busybox" from the WRT54G-0.51.tar.gz archive

    3.) Get some webspace and upload the busybox file to this webspace
    (This step is required to get busybox on the router. Of course you could also use a webserver on you local computer for this purpose)

    4.) Open a SSH or Telnet Shell to your router. I don't know, if HyperWRT has sshd support, but according to this thread http://www.linksysinfo.org/modules.php?name=Forums&file=viewtopic&t=1504 it seems to support Telnet access, which is sufficient.

    5.) Create the new directory /var/bin on your router.
    mkdir -p /var/bin

    6.) Now download the busybox binary from you webserver to this new directory.
    wget -O /var/bin/busybox http://yourwebserversadress/busybox

    7.) Make busybox executable.
    chmod 755 /var/bin/busybox

    8.) Create a Symlink to httpd.
    ln -sf /var/bin/busybox /var/bin/httpd

    Now you have an uncrippled httpd version on your WRT54GS.

    Just create another new directory in /usr/tmp , where you can put the html files you want to serve. For example /usr/tmp/webserv
    You can upload the html files to the WRT54GS the same way, you did upload busybox. Now you can cd to your directory with the html files and start a second httpd instance.
    /var/bin/httpd -p 8080
    Where 8080 is the port the new webserver should use. Just don't use port 80.

    now you can access the webserver from inside you LAN like

    To be able to access the webserver form the internet, you'll have to add a new iptables rule. But I have no experience with iptables, so I can't help you with that.

    Edit: I think, I've figured out how to make the webserver accessible from the internet. Just add this iptables rule:
    iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
    Such manually added rules are being removed, when you disconnect and reconnect to the internet / when your public IP is renewed. In the Sveasoft firmware you can use the rc_firewall nvram parameter to automatically re-add such rules. But I don't know, if rc_firewall is also present in HyperWRT.
  6. atzplzw

    atzplzw Network Guru Member

    Nice!! I tried that and it works!

    Now I just need to figure out how to use iptables.
    I use port 8000 for the webserver but I want it to be visible on port 80.
    I know that I can shutdown the admin httpd and start it on another port but it would be more simple to just redirect the outside port 80 to another port.
    So how can that be done?

  7. atzplzw

    atzplzw Network Guru Member

    I did try this:

    iptables -I INPUT -p tcp --dport 80 -j ACCEPT
    iptables -t nat -A PREROUTING -p tcp -i vlan1 --dport 80 -j DNAT --to-destination

    Which I did found on the svea forums but it doesn't work. I would have posted it there to but I don't have a permission.
    Plz any iptables guru post a solution...

  8. Scribe

    Scribe Network Guru Member

    hey guys, worked great for me, but how do i UN httpd a port? - eidt nm fixed
  9. Scribe

    Scribe Network Guru Member

    right, in my startup i have this:
    mkdir -p /var/bin
    wget -P /var/bin/ http://www.thenewhorizon.co.uk/busybox
    chmod 755 /var/bin/busybox
    ln -sf /var/bin/busybox /var/bin/httpd
    mkdir -p /var/bin/web
    wget -P /var/bin/web/ http://www.thenewhorizon.co.uk/index.html
    cd var/bin/web
    httpd -p 3000
    you see anything wrong with it? all the files are going in their place but no web access
  10. Janto

    Janto Network Guru Member

    ssh ?

    hi is it possible to get in the router with a gui or something? so not a dosbox
  11. Janto

    Janto Network Guru Member

    i mean...

    i mean a gui program so you can drag & drop a like explorer something

Share This Page