OpenWrt Forum Archive

Topic: Looking for help setting up a openwrt setup.

The content of this topic has been archived on 27 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello,

I would like help building an OpenWrt /Noauth setup for a simple captive website.  I don't really have any hardware today that will work well, so I would like to build a low cost/footprint system from scratch, thats a good setup.   

I am a basic Linux user and some of the steps are really beyond my skill or interest to figure out.  Anyone interested in helping me put one together?

Just to add, I am willing to pay a setup charge  for the help and hardware.   I am betting that someone already has a disk build out or another simple solution compared to  me spending two weeks working on the learning curve.   Email me if your interested at aw@lightwm .com

Hi what actually you need to do?  And what parts of process you need to help with?

Where are you?  Here's a simple, cheap solution if you are in North America.
1. Buy a WL-520gU from Newegg for $45US.
2. Flash it with trunk: http://downloads.openwrt.org/snapshots/ … uashfs.trx Use the Asus software on the router's CD after putting the router into "restore" mode by holding down the reset button while powering on (you can release after 2 seconds)
3. Telnet into 192.168.1.1 (download and use putty if you don't have a telnet program); change your password with passwd.  Change the router ip with "vi /etc/config/network" if you don't like 192.168.1.1 (I use 192.168.1.62--and add your gateway and dns, perhaps "option gateway 192.168.1.1" and "option dns 192.168.1.1" to give web access)
4.  Create your first web page with echo "<html><body><p>Hello, World from wl62</p></body></html>" > /www/hello.htm Enable it with chmod 755 /www/hello.htm
5.  Reboot
6.  Check out your web page at http://192.168.1.1/hello.htm
7.  Sign back in to make changes using ssh with putty or other ssh client.

Edit: fixed incorrect path to config file in step 3.

(Last edited by lizby on 14 Jan 2010, 19:23)

Hey Lisbey - Thanks very much!   This seems pretty straight forward and covers what I wanted it to do.   I will pick this up from Newegg and give it a try.

I just did exactly this to confirm that it works.  More:

Not enough space for your web site in the approximately 700K left in flash?  Install a USB drive.

8. opkg update
9. opkg install kmod-usb-storage  kmod-usb2 kmod-fs-ext2 kmod-fs-ext3 kmod-nls-cp437 kmod-nls-iso8859-1 kmod-usb-ohci
10. reboot
11. partition a usb drive on a linux machine with fdisk as linux 83 and then format it as ext3
12. plug it into the router.  check with df that it is there as /dev/sda1, mounted on /mnt/sda1
13. cp /www/hello.htm /mnt/sda1
14. mount /dev/sda1 /www
15. vi /www/hello.htm [modify the text in some way]
16. refresh your browser--it should show the modified text from your usb drive.  Now you have however much more storage to play with for your web site on /www--800 megabytes on mine as shown below.

root@wl62:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 1664      1664         0 100% /rom
tmpfs                     6600       964      5636  15% /tmp
tmpfs                      512         0       512   0% /dev
/dev/mtdblock3            1344       664       680  49% /jffs
mini_fo:/jffs             1664      1664         0 100% /
/dev/sda1               960976     35532    876628   4% /www

(Last edited by lizby on 10 Jan 2010, 04:48)

Want to make the usb drive mount on reboot or powerup?

17. vi /etc/init.d/custom-user-startup [insert the following text]
#!/bin/sh /etc/rc.common
START=86
start() {
mount /dev/sda1 /www
}
stop() {
umount /dev/sda1
}
18. chmod 755 /etc/init.d/custom-user-startup
19. /etc/init.d/custom-user-startup enable
20. reboot & log back in
21. confirm with df that /dev/sda1 is mounted on /www

Thats impressive, and looks like it will solve a lot common issues that I will face (and didn't think of)  - Thank you!    I ordered the WL-520gU last night from Newegg,  and will post when the hardware gets in and how it went.

Note that the WL-520gU is towards the bottom in features by current standards.  No wireless N, only 4 megabytes of flash, and only 16 of SDRam.  Nevertheless, it is a pretty powerful device with some earlier problems fixed--new devices run at 240mHz rather than the older 200, and openWrt now supports USB 2--you might find posts that say it doesn't.  Wireless is fixed for 2.6 kernel (sort of) in Kamikaze trunk (with fewer features, so far, compared to 2.4 kernel).

One of the router's best features is that it is dead easy to flash, and hard to brick.  To flash, as noted above, use the Asus "recovery" software that comes with the router (in Windows--in Linux use a tftp server), press the reset button while plugging in power, release after two seconds.  The power led will flash and you are in upgrade mode and can flash the device.

To continue:

Want to move masses of web page files from another PC?

18. opkg update, then opkg install openssh-sftp-server, reboot
19. From windows, download and use winSCP; from Linux (for example, Ubuntu 9.10), go to the desktop, Ctrl+L enter "ssh://ipaddress_or_hostname" (for my instance, ssh://192.168.1.62) to get a graphical file browser.  Copy and paste the files you want, for example, a new (proper html) file called "test.htm".
20. From your PC browser, http://192.168.1.62/test.htm

At this point, df shows 51% of my original 1344 blocks of jffs used:

root@wl62:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 1664      1664         0 100% /rom
tmpfs                     6600        44      6556   1% /tmp
tmpfs                      512         0       512   0% /dev
/dev/mtdblock3            1344       684       660  51% /jffs
mini_fo:/jffs             1664      1664         0 100% /
/dev/sda1               960976     35536    876624   4% /mnt/sda1
/dev/sda1               960976     35536    876624   4% /www

(Last edited by lizby on 10 Jan 2010, 17:27)

Want to have dynamic web pages, so that your users can enter data on forms and you can process their input?  Use Lua, a lightweight but powerful language which is available on openWrt by default.

First switch from the recent "lucid" http server demon, which doesn't handle cgi, to the older Busybox httpd.

21. /etc/init.d/lucid disable [this will disable a luci interface--but you probably don't want to have that on a device with 4 meg of flash]
22. /etc/init.d/httpd enable
23. reboot
24. vi /www/cgi-bin/test01.lua [insert the following code]

#!/usr/bin/lua

-- following is web page text
s0 = "Content-type: Text/html\n\n"
s1 = "<html><head><title>Lua Web Form</title></head>"
s2 = "<body>Calculate simple annual Interest at 5.5%"
s3 = "<form>Investment Amount: <input name=amt>"
s4 = " and <input type=submit value=\"go!\"></form>"
s5 = "<br>Return:<br><br><i>"
s6 = "" -- result or error message will go here
s7 = "</i></body></html>"

data = os.getenv("QUERY_STRING")

vals = {}  -- set up table of values

--get name, value pairs in tables
for name, tmp in string.gmatch(data .. '&', '(.-)%=(.-)%&') do
  tmp = string.gsub(tmp , '%+', ' ')
  tmp = string.gsub(tmp , '%%(%x%x)', function(dpc)
                return string.char(tonumber(dpc,16))
                end )
  vals[name] = tmp -- for name-amt, this is the amount value
end

--check for valid data
if vals["amt"] ~= ""  and vals["amt"] ~= nil then
  tmp = tonumber(vals["amt"])
  if tmp == nil then
    s6 = "Not a number - can't calculate"
  else
    s6 = tmp * .055
  end
  s6 = s6.."<br><i>input value was</i><br>"..tmp
else
  s6 = "<i>Result will be here</i>"
end

print(s0..s1..s2..s3..s4..s5..s6..s7)

25. chmod 755 /www/cgi-bin/test01.lua
26. in your browser, enter http://192.168.1.62/cgi-bin/test01.lua
You should see this (in IE):
http://i47.tinypic.com/p2gba.jpg
27. enter 12345 and press <enter> and you should see this:
http://i45.tinypic.com/4uj5zp.jpg

As with any cgi programming, you must use care with user-supplied input.  Depending on what you do with the input, malicious users can damage your machine, and even mistakes can corrupt your data and do other harm.

(Last edited by lizby on 12 Jan 2010, 18:41)

I got the router last night, flashed it and got the hello world web page up and running.   The Wifi was set to disabled,  and i found the area to comment out to make it start up , and I got connected that way.    Thanks! 

Somehow though, I messed it up when I put in this part:

Change the router ip with "vi /etc/network" if you don't like 192.168.1.1 (I use 192.168.1.62--and add your gateway and dns, perhaps "option gateway 192.168.1.1" and "option dns 192.168.1.1" to give web access)

The system didnt have a /etc/network file (or it was blank) and I put these two thing in
"option gateway 192.168.1.1"
"option dns 192.168.1.1"       

Just like that (no white space or anything).    then I rebooted and I cant connect anymore.  I tried on LAN to re-flash, and the reflash cant find the device.   The device is working , and I can connect to it with WIFI and LAN,  but putty calls using telnet or SSH fail.   

my ip config looks like this from the DHCP from LAN.   There is no gateway. 

Wireless - My other home wirless card info ( i tried this both enabled and disabled)
LAN -
DHCP IP - 169.254.37.205
Mask - 255.255.0.0
Gateway -  Blank

I did run some of the commands out of help with no optiosn just to see what they would do, and they did not appear to do any major "change"

Any ideas on to make contact with it again?

I tried connecting to 169.254.37.1 and it wont connect either.

I beg your pardon.  The command is not "vi /etc/network ", but "vi /etc/config/network".  Kamikaze configuration files are in /etc/config.  You may still be at 192.168.1.1, but if you can't get into the router, you'll have to reflash and start over.  Sorry.  I will edit the previous post to make the correction.

Thanks for being the designated, or non-voluntary, beta-tester. (Or are you Alpha?)

(Last edited by lizby on 14 Jan 2010, 19:21)

LOL - Hey no problem, I appreciate the help!    I tried reflashing it, but for some reason my system can find it anymore in restore mode?

>my system can find it anymore in restore mode

Do you have a direct cable from the PC to the router?  Is the PC in the 192.168.1 range?  If Windows, from a command prompt, type ipconfig to see what the Local Area Connection ip is.  From linux, ifconfig.  If not in that range, use control panel to reset in that range. 

I didn't understand your comment about your other wireless card: "DHCP IP - 169.254.37.205"

What is providing DHCP?  Is that under your control?

Remember if you reflash, you must telnet in first thing to reset your password so you can use ssh.

On a Windows Vista machine, you must run the Asus flash program "as administrator" (right click before launching). 

The above are all things which have tripped me up.

(Last edited by lizby on 14 Jan 2010, 20:48)

Yes i have had it plugged in by cable and in the restore mode, but the asus software never finds it. when it boots up normally, the ip address doesnt work anymore, or the website.  the link light is on but no activity, and i am hooked into and tried both the WAN and hub ports.    Its not giving dhcp, but the wireless network name does appear as a Wifi choice,  but it doesn't successfully give a DHCP ip address and work.   I think i might have killed it!

I don't think you can have killed it.  I have flashed three of them dozens of times trying out different configurations.  You need to have it plugged into a port other than the WAN port.  Are you getting the blinking power light when you try to flash?

Since you edited a "network" file in a directory where openWrt doesn't look for it, I wouldn't have thought that the original IP would have changed.  You have tried 192.168.1.1?  What does your whole configuration look like?  Broadband incoming to what to what ... ?  You're sure you don't have another router which might have that same address?  What happens if you are plugged into the router (and nothing else) and from a command prompt you do "ping 192.168.1.1"?

What is the ip address of your broadband connection--cable modem or dsl modem or what?

yeah it just didnt seem right and I could see wifi service was running still as well.  I have been playing with it and found that after I cleared the wireless connection settings, it connected through the asus utility to allow me to flash again.  I will go back through the steps to set it up.

ok,  I have flashed it a couple of times and gone through the steps and found that the problem starts when the router is rebooted.  The first time I can set it up through telnet and access the system, but after I type reboot,  the system never gives a dhcp address successfully or allows connection though SSH, telnet or any choice in putty. The website stops working  and it works before the reboot. 

This appears true whether I edit the Network file or not.  The only other thing i am changing is turning wireless on by commenting out the Wireless disabled line in the wireless file.  The wifi does appear,  but connection hangs during the IP part.  OK I found that if I dont reboot and I run the command wifi start,  it does know the system down (cant ssh, web site down, doesnt ping) and I have to reflash.   

any thoughts on what to check on DCHP or the reboot scenario?

(Last edited by AndrewW on 16 Jan 2010, 23:43)

When you telnet in the first time, are you using the passwd command to change the password?  That is necessary to enable the ssh. 

How about setting up a static ip--something appropriate for the ip range which your broadband connection.  I'll suppose it is 198.162.1.1/254.  If so, edit network config with "vi /etc/config/network". change the default openWrt ip address from 198.162.1.1 to 198.162.1.62, add "option gateway 198.162.1.1" and "option dns 198.162.1.1" (if those are right for your broadband ip), and reboot--don't set up the wireless.  See if everything looks ok.

By the way, wireless with the WL-520gU (or any broadcom 43xx router) works best with a Linux 2.4 kernel--but USB works best with a Linux 2.6 kernal.  Your original post didn't say anything about providing or using wireless, so my recommendations considered that you wouldn't enable it.  If you need to add wireless to your network, you might want to dedicate a router to that, and a different one to serving the web pages (wired in).

The discussion might have continued from here.