tag:blogger.com,1999:blog-16894851442370756572024-03-28T00:28:14.993-07:00WZR-HP-G300NH RouterAbout Buffalo WZR-HP-G300NH router and other Atheros based devices like Linksys WRT160NL, D-Link DIR-825, TP-LINK TL-WR1043ND, Netgear WNDR3700. Software hardware tips including dd-wrt/openwrt firmware and Samba/printer sharing/Asterisk/ftp/www servers.Unknownnoreply@blogger.comBlogger17125tag:blogger.com,1999:blog-1689485144237075657.post-29666417100682538962010-06-29T15:16:00.001-07:002010-06-29T15:18:46.005-07:00Asterisk, the VoIP Server on DD-WRT<p>I'm a big fan of Asterisk on router -- imho, it's the perfect platform for anyone want to try Asterisk at home -- 24x7, fanless and even the cheapest router can handle at least 2-3 concurrent conversation. Before this WZR-HP-G300NH, I had Asterisk running on a WRT54G-TM for over a year with lots of fun. </p> <p>Installing Asterisk on the router is easier now as current OpenWrt trunk build(the one we use) includes prebuilt Asterisk binaries. As always, since OpenWrt is designed to work with / not /opt, some adjustment is required to get Asterisk working properly.</p> <ol> <li><strong><font color="#008000">Install Asterisk 1.6<br></font></strong>Believe it or not, DD-WRT MEGA also has Asterisk included -- it's an old ver1.4 and some important files are missing -- I have no idea why DD-WRT decided to do so, too much flash ROM? Anyway, to install Asterisk 1.6 on our opkg enabled router, run<br><em>opkg install asterisk16<br></em><br>You may also want to install some additional modules like:<br><em>opkg install asterisk16-res-agi<br>opkg install asterisk16-res-musiconhold<br><br></em>To view a full list of Asterisk packages(lots of them!), run<br><em>opkg list | grep asterisk16<br><br></em></li> <li><strong><font color="#008000">The configuration file: asterisk.conf<br></font></strong>With our installation, the asterisk.conf is in /opt/etc/asterisk/asterisk.conf. Change it to the contents below:<br><br><font face="Courier New">[directories] ; remove the (!) to enable this<br>astetcdir => /opt/etc/asterisk<br>astmoddir => /opt/usr/lib/asterisk/modules<br>astvarlibdir => /opt/usr/lib/asterisk<br>astdbdir => /opt/usr/lib/asterisk<br>astkeydir => /opt/usr/lib/asterisk<br>astdatadir => /opt/usr/lib/asterisk<br>astagidir => /opt/usr/lib/asterisk/agi-bin<br>astspooldir => /var/spool/asterisk<br>astrundir => /var/run/asterisk<br>astlogdir => /var/log/asterisk </font></li> <p><font face="Courier New">[compat]<br>pbx_realtime=1.6<br>res_agi=1.6<br>app_set=1.6</font><br><br>As you can see, by modifying this file, we tell Asterisk to look for files at <em>/opt/etc/asterisk</em> and <em>/opt/usr/lib/asterisk</em> instead of default locations, which fits our installation.<br><br>Now try to launch asterisk by running:<br><em>asterisk -vvvvvc<br></em>Exit by pressing ctrl+c<br><br> <li><strong><font color="#008000">Asterisk configuration</font></strong><br>By default, asterisk loads lots of modules, you can change the settings to fit your needs and reduce memory usage.<br><br>Below is a sample of <em>/opt/etc/asterisk/modules.conf </em>with reduced modules:<br><br><font face="Courier New">[modules]<br>autoload=no ; only load explicitly declared modules<br>load => app_dial.so<br>load => app_echo.so<br>load => app_macro.so<br>load => app_playback.so<br>load => chan_sip.so<br>load => codec_ulaw.so<br>load => pbx_config.so<br>load => format_pcm.so<br>load => format_wav.so<br>load => func_callerid.so<br>load => func_strings.so<br>load => res_musiconhold.so<br>load => res_agi.so<br><br></font>For SIP users, other important files including <em>/opt/etc/asterisk/extensions.conf</em> and <em>/opt/etc/asterisk/sip.conf. </em>These are not covered here, please refer to website about Asterisk like <a href="http://www.asteriskguru.com/" target="_blank">asteriskguru</a> and <a href="http://www.voip-info.org/" target="_blank">voip-info.org</a>. Also, here is a must-read ebook: <em><strong>Asterisk: The Future of Telephony Second Edition</strong></em>(<a href="downloads.oreilly.com/books/9780596510480.pdf" target="_blank">download the PDF book</a>)<br><br></li> <li><strong><font color="#008000">Run it as service</font></strong><br>Create file <em>/opt/etc/init.d/asterisk</em> with below(delete previous contents if its not empty)<br><br><font face="Courier New">source /mnt/root/.profile<br>mkdir -p /var/run/asterisk<br>mkdir -p /var/spool/asterisk<br>mkdir -p /var/log/asterisk/cdr-csv<br>/opt/usr/sbin/asterisk -C /opt/etc/asterisk/asterisk.conf<br><br></font>And run<br><em>chmod a+x /opt/etc/init.d/asterisk<br>ln -s /opt/etc/init.d/asterisk /opt/etc/init.d/S95asterisk<br></em></li></ol> <p>That's all. Enjoy Asterisk and happy VoIP!</p> Unknownnoreply@blogger.com66tag:blogger.com,1999:blog-1689485144237075657.post-1100906483003914342010-06-29T02:20:00.001-07:002010-06-29T02:42:38.220-07:00Lighttpd and php on DD-WRT<p>Busybox httpd is good for simple static pages, now here is a tutorial for installing <strong>lighttpd and php with fastcgi support</strong> in the router. Here I choose <a href="http://www.lighttpd.net/" target="_blank">lighttpd</a> over Apache for its light cpu usage and small memory footprint.</p> <p>Since all our software are based in /opt folder, some modification must be done to get everything working:</p> <ol> <li><strong><font color="#008000">Install php5 and lighttpd<br></font></strong>To install php5 with fastcgi support, run<br><em>opkg install libsqlite3<br>opkg install php5-fastcgi<br>opkg install php5-modgd<br> <br></em>Along with php5, the popular <a href="http://www.libgd.org/Main_Page" target="_blank">libgd</a> module is also installed. Copy php.ini to its default location. <br><em>cp /opt/etc/php.ini /etc/php.ini<br></em><br>After that, test php installation by running:<br><em>php-cgi -v</em><br><br>You should see the version info and no warning/error message.<br><br>Install lighttpd and some modules<br><em>opkg install lighttpd<br>opkg install lighttpd-mod-fastcgi<br>opkg install lighttpd-mod-simple-vhost<br><br></em> <li><strong><font color="#008000">Modify php.ini</font></strong><br>Edit <em>/etc/php.ini<br></em>Find <em>doc_root = "/www"</em>(or whatever) and change it to <em>doc_root = "/opt/www"<br></em>Find <em>extension_dir = "/usr/lib/php"</em> and change it to <em>extension_dir = "/opt/usr/lib/php"<br></em>Find <em>;extension=gd.so</em> and remove the leading semicolon, i.e., change it to <em>extension=gd.so<br></em>Find <em>;date.timezone= , </em>remove the leading semicolon and change it to <br><em>date.timezone = "<font color="#ff0000">America/New_York</font>"<br></em>Replace the red part with yours, a full list is available <a href="http://www.php.net/manual/en/timezones.php" target="_blank">here</a>.<br><br> <li><strong><font color="#008000">Modify lighttpd.conf</font></strong><br>With our installation, the configuration file for lighttpd is located at <em>/opt/etc/lighttpd/lighttpd.conf</em>. Edit this file:<br><br>First, enable <em>mod_fastcgi</em> and <em>mod_simple_vhost</em>:<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="lighttpd-module-enable" border="0" alt="lighttpd-module-enable" src="http://lh6.ggpht.com/_g-JnOWjedOQ/TCm65AF4KWI/AAAAAAAAAB0/f6nTv_Urqt8/lighttpd-module-enable%5B6%5D.gif?imgmax=800" width="248" height="296"> <br><br>Then <br>find <em>server.document-root</em> and change its value to <em>"/opt/www"<br><br></em>find <em>#server.port = 81 </em>and change it to <em>server.port = 81<br></em>This will set lighttpd server to listen port 81. If you want to use port 80, make sure to move the DD-WRT's web admin to another port, <a href="http://g300nh.blogspot.com/2010/06/simple-busybox-http-server-on-dd-wrt.html" target="_blank">details here, step 1</a>.<br><br>add following at the end of the file: <p><font face="Courier New">fastcgi.server = ( ".php" => ((<br> "bin-path" => "/opt/usr/bin/php-cgi",<br> "socket" => "/tmp/php.socket"<br> )))<br><br></font></p> <li><strong><font color="#008000">Lighttpd startup script</font></strong><br>Create or edit file <em>/opt/etc/init.d/lighttpd </em>with below. Remove any previous contents if its not empty.<br><br> <p><font face="Courier New">#!/bin/sh </font> <p><font face="Courier New">source /mnt/root/.profile</font></p><font face="Courier New"><br>BIN=lighttpd</font><font face="Courier New"><br>LOG_D=/var/log/$BIN<br>RUN_D=/var/run<br>PID_F=$RUN_D/$BIN.pid </font> <p><font face="Courier New">COND=$1<br></font><font face="Courier New">[ $# -eq 0 ] && COND="start" </font> <p><font face="Courier New">case $COND in<br> stop)<br> killall lighttpd<br> killall php-cgi<br> ;;<br> start)<br> mkdir -p $LOG_D<br> mkdir -p $RUN_D<br> $BIN -f /opt/etc/lighttpd/lighttpd.conf -m /opt/usr/lib/lighttpd<br> ;;<br> *)<br> exit 1<br>esac</font> <p><font face="Courier New"><br></font>Set it as a service<br><font face="Courier New"><font face="Times New Roman"><em>chmod a+x /opt/etc/init.d/lighttpd<br>ln -s <em>/opt/etc/init.d/lighttpd</em> <em>/opt/etc/init.d/S80lighttpd<br></em></em></font></p></font> <li><strong><font color="#008000">Test lighttpd server</font></strong><br>First create the home folder<br><em>mkdir /opt/www<br><br></em>Then the test file <em>/opt/www/phpinfo.php </em>with contents below:<br><br><font face="Courier New"><?php<br>phpinfo();<br>?><br><br></font>After that, launch lighttpd<br><em>/opt/etc/init.d/lighttpd<br></em>#to stop the lighttpd server, run <em>/opt/etc/init.d/lighttpd stop</em><br><br>Open browser and navigate to <a href="http://router_ip:81/phpinfo.php">http://router_ip:81/phpinfo.php</a> to check the output.<br></li></ol> Unknownnoreply@blogger.com38tag:blogger.com,1999:blog-1689485144237075657.post-80168856558449857412010-06-28T15:10:00.001-07:002010-06-28T15:13:14.645-07:00Simple busybox http server on DD-WRT<p>By default DD-WRT runs its own http server(/usr/sbin/httpd), providing web management interface to configure the router. The server is highly integrated and hard to reuse for our own contents. If you just want to host some web pages without CGI support, the httpd server in busybox is a good alternative.</p> <ol> <li><strong><font color="#008000">(Optional)Move DD-WRT's web admin to another port<br></font></strong>The best way to do so is changing a nvram value as described <a href="http://www.dd-wrt.com/wiki/index.php/WEB_server" target="_blank">here</a>.<br>So login the router and run<br><em>nvram set http_lanport=<font color="#ff0000">88</font><br>nvram commit</em><br><br>Then after rebooting, the new port will be 88 and you can access the web admin at <a href="http://router_ip:88/">http://router_ip:88/</a>. Everything should work just as before including firmware upgrade.<br><br></li> <li><font color="#008000"><strong>Configure busybox httpd<br></strong></font>The OpenWrt's busybox is installed if you followed the <a href="http://g300nh.blogspot.com/2010/06/wireless-schedule-with-cron-job.html" target="_blank">previous post</a>. This busybox provides more features than the DD-WRT one, including a small web server. To launch it, run</li> <p><em>/opt/usr/sbin/httpd -p 80 -c /opt/etc/httpd.conf -h /opt/www<br><br></em>the server(<em>/opt/usr/sbin/httpd</em>) will listen port 80(<em>-p 80</em>) with <a href="http://oldwiki.openwrt.org/OpenWrtDocs(2f)httpd(2e)conf.html" target="_blank">configuration file</a> /opt/etc/httpd.conf(<em>-c /opt/etc/httpd.conf</em>) and use /opt/www as home folder(<em>-h /opt/www</em>).<br><br>Everything looks good, except, both our http server and dd-wrt's are called <em>httpd</em>. This will be a problem as DD-WRT will kill and restart the httpd service when applying some settings. If that ever happens, our httpd service will be terminated unexpectedly. So let's change the service name.<br><br>Here is (another) dirty hack but works for me. Log in PuTTY and run:<br><br><em>cp /opt/bin/busybox /opt/bin/busybox.orig<br>cp /opt/bin/busybox /tmp/busybox<br>sed -i 's/httpd$/httpe/g' /tmp/busybox<br>cp /tmp/busybox /opt/bin/busybox<br>ln -s /opt/bin/busybox /opt/usr/sbin/httpe<br><br></em>So now we have changed the name of busybox's http server from httpd to <em><strong>httpe</strong></em>. If it's messed up, restore the old busybox:<br><em>/bin/cp /opt/bin/busybox.orig /opt/bin/busybox</em><br></p> <li><strong><font color="#008000">Run it as service<br></font></strong>Create file /opt/etc/init.d/httpd<br><br><font face="Courier New">source /mnt/root/.profile<br>/opt/usr/sbin/httpe -p 80 -c /opt/etc/httpd.conf -h /opt/www<br><br></font>And run<br><em>chmod a+x /opt/etc/init.d/httpd<br>ln -sf /opt/etc/init.d/httpd /opt/etc/init.d/S20httpd</em></li></ol> Unknownnoreply@blogger.com65tag:blogger.com,1999:blog-1689485144237075657.post-22524475600732115652010-06-27T23:45:00.001-07:002010-07-06T03:06:10.853-07:00Upgrade DD-WRT and Keep Installed Applications<p>The DD-WRT support for these new 11N Gigabit routers are still in early stage with new builds rolling out every one to two weeks. The old good "if its not broken then don't fix it" rule might not apply here and I suggest to stay with latest release if you have the time(and guts).</p> <p>Upgrading a DD-WRT firmware with loaded software is pretty easy, considering the extra work we've done. Take the trouble not to mess with important system folders like /lib /usr and /bin and now its the reward time. </p> <ol> <li><strong><font color="#008000">Stop installed software</font></strong><br>Log in the router, rename the <em>/mnt/optware.enable</em><br><em>mv /mnt/optware.enable /mnt/optware.disable<br><br></em>Then reboot the router. After rebooting, the router is back to standard DD-WRT with no extra load and ready for flashing.<br><br> <li><strong><font color="#008000">Upgrade firmware<br></font></strong>Get the new DD-WRT build, the name should be <em>wzr-hp-g300nh-dd-wrt-webupgrade-MULTI.bin. </em>Some suggests a <a href="http://www.dd-wrt.com/wiki/index.php/Hard_reset_or_30/30/30" target="_blank">hard reset</a> before and after upgrading but I usually just select "Reset to Default Settings" during flash.<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="firmware-reset-to-default" border="0" alt="firmware-reset-to-default" src="http://lh5.ggpht.com/_g-JnOWjedOQ/TChE-2XtfQI/AAAAAAAAABw/eDn6xdL3vk8/firmwareresettodefault6.gif?imgmax=800" width="725" height="454"> <br>After flashing, all settings will be erased and then you have to start over again.<br><br> <li><strong><font color="#008000">Set the router</font></strong><br>Set the router as usual. Here is a quick list for additional setup, all are covered in other posts, I just put these together for easy reference.<br><br>Enable SSH and USB Support. <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">Details here, Step 2</a>.<br>Customized startup script. <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">Details here, Step 10</a>.<br>Disable DD-WRT's NTP Client if you're about to use local time. <a href="http://g300nh.blogspot.com/2010/06/set-dd-wrt-to-use-local-time.html" target="_blank">Details here, Step 1.</a><br>Disable built-in FTP server(should be off by default). <a href="http://g300nh.blogspot.com/2010/06/vsftpd-ftp-server-for-dd-wrt.html" target="_blank">Details here, Step 1</a>.<br><br>Then some nvram variables:<br><br>#use local time. <a href="http://g300nh.blogspot.com/2010/06/set-dd-wrt-to-use-local-time.html" target="_blank">details here, step 3</a>. Change it accordingly<br><em>nvram set time_zone=</em><em><font color="#ff0000">PST8PDT,M3.2.0,M11.1.0<br></font>#</em>move dd-wrt's web admin to another port. <a href="http://g300nh.blogspot.com/2010/06/simple-busybox-http-server-on-dd-wrt.html" target="_blank">Details here, step 1</a><br><em>nvram set http_lanport=<font color="#ff0000">88</font><br>nvram commit<br><br></em>After that, reboot the router.<br><br> <li><strong><font color="#008000">Update writable /etc and re-enable installed apps</font></strong><br>After reboot, login the router and run:<br><br><em>cp -a /etc/* /mnt/etc/<br>mv /mnt/optware.disable /mnt/optware.enable<br><br></em><strong>The first line is very important. It's for synchronizing our the customized /etc folder with the new firmware's /etc folder. Forget to do so will break the web management interface!<br><br></strong>Somewhat modified, the files in /etc folder are only added(like /etc/TZ) or dynamically updated(the adduser script), so it's safe to overwrite the /etc folder with new contents and all our work is kept intact. After that, reboot the router, and you should have a new DD-WRT with all previously installed software running.<br><br> <li><strong><font color="#008000">Fix the broken web interface</font></strong><br>You'll get this error ONLY if you forget to update the /etc folder, see Step 4 above. If this ever happens:<br>SSH or telnet login the router, run<br><br><em>mv /mnt/optware.enable /mnt/optware.disable<br>reboot<br></em><br>the web interface should be back after rebooting, then follow Step 4. <br><br>If the web interface is messed and you can't login from PuTTY, unplug the USB disk and power cycle the router. Then manually mount the USB disk(<a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">details here, step 2 and 6</a>) and update /etc folder following Step 4.</li></ol> Unknownnoreply@blogger.com38tag:blogger.com,1999:blog-1689485144237075657.post-56335289874992082982010-06-27T22:26:00.001-07:002010-06-28T18:38:45.364-07:00Workaround for Stuck Beacon Problem<p>Stuck beacon is a <a href="http://madwifi-project.org/wiki/StuckBeacon" target="_blank">notorious problem on madwifi</a> (the wireless driver DD-WRT used for Atheros routers). If you never experienced any wireless interruptions with DD-WRT then just ignore this article. However, if you're annoyed by this stuck beacon problem with constantly dropping wireless connection, then I hope this can be of help.</p> <p>I personally prefer the open source ath9k driver which doesn't suffer from this, but some important feature like WDS is missing from ath9k. So to each its own, DD-WRT has the perfect reason to stick with madwifi and I don't expect the switch to ath9k anytime soon. And, seems that the problem only happens under certain circumstance. In my case, the connection drops with an Atheros wireless N card -- same card works great with stock firmware -- but works fine with another Intel WiFI 1000 11N card. So if a stable wireless connection is very important, the best solution might be flashing back to stock firmware or just try another card. </p> <p>Below is a quick hack, not a completely fix but would make life a little easier. The idea is to watch the output of dmesg and when the "stuck beacon" error messages flood, reset the wireless interface to bring it back to life.<br></p> <ol> <li><strong><font color="#008000">The watchdog script</font></strong><br>When wireless connection is dropeed, a typical out from <em>dmesg</em> would like this<br><font size="2" face="Courier New"><br>ath_bstuck_tasklet : Entering<br>Resetting; Code: 01<br>ath_bstuck_tasklet : Entering<br>Resetting; Code: 01<br>ath_bstuck_tasklet : Entering<br>Resetting; Code: 01<br>ath_bstuck_tasklet : Entering<br>Resetting; Code: 01<br>ath_bstuck_tasklet : Entering<br>Resetting; Code: 01<br>ath_bstuck_tasklet : Entering<br>Resetting; Code: 01<br><br></font>the same error message will keep repeating and flood the kernel log. So we can use this as a trigger and reset wireless interface when the error occurs.<br><br>Below is the <em>/opt/usr/local/bin/wifi-watchdog.sh</em> script<br><br><font size="2" face="Courier New">#!/bin/sh </font> <p><font size="2" face="Courier New">dmesg | tail -n 5 | grep -q ath_bstuck_tasklet || exit </font> <p><font size="2" face="Courier New">echo fixing...<br>#a log file<br>echo `date` >> /tmp/wifi-wathdog.log<br><br>ifconfig ath0 down<br>#for VAP, bring additional interface(s) down<br>#ifconfig ath0.1 down<br>sleep 2<br>ifconfig ath0 up<br>#bring it back<br>#ifconfig ath0.1 up<br><br></font>Set permissions<br><em>chmod a+x /opt/usr/local/bin/wifi-watchdog.sh<br></em></p> <li><font color="#008000"><strong>Set cron job</strong></font><br>With the watchdog script ready, we can use <a href="http://g300nh.blogspot.com/2010/06/wireless-schedule-with-cron-job.html" target="_blank">cron</a> to set it run every one minute. <br>Add a new job: <p><font face="Courier New">* * * * * /opt/usr/local/bin/wifi-watchdog.sh<br><br></font></p> <p>and it's done. Again, its not a completely fix just save the trouble of resetting the router each time.<br></p></li></ol> Unknownnoreply@blogger.com25tag:blogger.com,1999:blog-1689485144237075657.post-9315729135658009222010-06-27T03:57:00.001-07:002010-06-29T03:05:29.466-07:00Wireless Scheduler with Cron Job<p>Cron is a time-based job scheduler in Linux systems which enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. In this example, we'll use cron to control the wireless signal, set it to turn on only at given time.</p> <p>DD-WRT is shipped with cron support but again we'll use our own cron daemon as it's easier for future update and will save some flash wearing.</p> <ol> <li><strong><font color="#008000">Disable DD-WRT's Cron</font></strong><br>From the web interface, Administration->Management, find "Cron" and disable it, then click "Apply Settings"<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="cron-disable" border="0" alt="cron-disable" src="http://lh5.ggpht.com/_g-JnOWjedOQ/TCcuhRSQK8I/AAAAAAAAABo/t1dVL-PyqHg/cron-disable%5B5%5D.gif?imgmax=800" width="382" height="96"> <br><br> <li><font color="#008000"><strong>Install cron(busybox) service<br></strong></font>The cron is provided by busybox and should've been installed. If not, run<br><em>opkg install busybox<br><br></em>and create the scheduling file folder:<br><em>mkdir /etc/crontabs<br><br></em>Set it to run on startup by creating <em>/opt/etc/init.d/crond</em> with following:<br><br><font face="Courier New">source /mnt/root/.profile<br>kill -9 $(pidof crond)<br>/opt/usr/sbin/crond<br><br></font>Then:<br><em>chmod a+x /opt/etc/init.d/crond<br>ln -s <em>/opt/etc/init.d/crond</em> <em>/opt/etc/init.d/S80crond<br><br></em></em> <li><font color="#008000"><strong>The script to switch wireless</strong></font><br>Now create a file <em>/opt/usr/sbin/wireless-off.sh<br><br></em><font face="Courier New">#!/bin/sh<br>/sbin/ifconfig ath0 down<br></font><br>another one: <em>/opt/usr/sbin/wireless-on.sh<br><br></em><font face="Courier New">#!/bin/sh<br>/sbin/ifconfig ath0 up<br><br></font>On VAP enabled routers, additional interfaces like ath0.1, ath0.2...etc. also need to be taken care of:<br><em>/sbin/ifconfig ath0.1 down<br></em>and<br><em>/sbin/ifconfig ath0.1 up<br></em>The full list of wireless interfaces can be found by running <em>/sbin/ifconfig<br></em><br>Don't forget the permission:<br><em>chmod a+x /opt/usr/sbin/wireless-on.sh /opt/usr/sbin/wireless-off.sh<br><br></em> <li><font color="#008000"><strong>Edit Cron Scheduler</strong></font><br>DD-WRT's wireless scheduling is available only for Broadcom routers(see picture below) but missing from Atheros builds.<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="radio-sheduling-broadcom" border="0" alt="radio-sheduling-broadcom" src="http://lh6.ggpht.com/_g-JnOWjedOQ/TCcuiPtedtI/AAAAAAAAABs/Kg99Wvc0yaM/radio-sheduling-broadcom%5B5%5D.gif?imgmax=800" width="614" height="167"> <br>However, its not hard to implement this on Atheros routers with the help of <em>cron</em> and the scripts above.<br>For example, to turn on wireless only from 5pm to 11pm, run <br><em>crontab -e<br></em>which will bring you the cron job editor. Add two lines like that<br><br><font face="Courier New">0 17 * * * /opt/usr/sbin/wireless-on.sh<br>0 23,0-16 * * * /opt/usr/sbin/wireless-off.sh</font><br><br>Save. The wireless-on script will runs only once at 5PM(17:00) but the wireless-off script runs every hour(23:00, 0:00 ... 16:00) to ensure the wireless can still be turned off in case the router is rebooted halfway.<br><br>Now how about turning off wireless only on weekdays?<br><br><font face="Courier New">0 17 * * * /opt/usr/sbin/wireless-on.sh<br>0 23,0-16 * * 1-4 /opt/usr/sbin/wireless-off.sh<br>0 0-16 * * 5 /opt/usr/sbin/wireless-off.sh<br><br></font><br>Refer <a href="http://kb.iu.edu/data/afiz.html" target="_blank">here</a> for the full instruction about cron.</li></ol> Unknownnoreply@blogger.com349tag:blogger.com,1999:blog-1689485144237075657.post-18999187290659416642010-06-27T01:08:00.001-07:002010-06-27T22:52:13.235-07:00BitTorrent Client: Transmission on DD-WRT<p>If you've followed the <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">previous guides</a> to set the opkg system, then installing transmission on the USB enabled DD-WRT system is a no-brainer. Only one little thing needs to be taken care of...</p> <ol> <li><strong><font color="#008000">Install transmission</font></strong><br>To do so, Use PuTTY to log in and run the command below:<br><em>opkg install transmission-web<br><br></em>This will install libevent(required library) transmission-daemon(the actual program) and transmission-web(the web interface).<br><br> <li><strong><font color="#008000">Setup transmission</font></strong><br>Run <br><em>transmission-daemon<br></em>wait for 10 seconds then stop it:<br><em>killall transmission-daemon<br><br></em>This will create default configuration file for transmission, the file is located at <em>/mnt/root/.config/transmission-daemon/settings.json<br></em>Edit this file with following(delete all previous contents)<br><br><font face="Courier New">{<br>"blocklist-enabled": 1,<br>"download-dir": "\/mnt\/share\/torrents",<br>"download-limit": 100,<br>"download-limit-enabled": 1,<br>"encryption": 2,<br>"max-peers-global": 35,<br>"peer-port": 25000,<br>"pex-enabled": 1,<br>"port-forwarding-enabled": 1,<br>"rpc-authentication-required": 0,<br>"rpc-password": "",<br>"rpc-port": 9091,<br>"rpc-username": "",<br>"rpc-whitelist": "192.168.1.*",<br>"upload-limit": 200,<br>"upload-limit-enabled": 1<br>}</font> <br><br>Above is taken from <a href="http://www.dd-wrt.com/wiki/index.php/Transmission_daemon#Install_Optware_Transmission" target="_blank">DD-WRT wiki</a> with some modification. Also create the download folder<br><em>mkdir -m 777 /mnt/share/torrents<br><br></em>So now all configure files for transmission are in <em>/mnt/root/.config</em>(or <em>/tmp/root/.config</em>, its the same). Downloaded files will be in <em>/mnt/share/torrents</em><br><br> <li><strong><font color="#008000">Set transmission for web access</font></strong><br>This is usually not a problem, however, in our setup, the web pages is are in non-standard location. So we must let transmission aware of the change.<br><br>To do so, a variable must be set for transmission. Run the command lines below:<br><em>export TRANSMISSION_WEB_HOME='/opt/usr/share/transmission/web/'<br>transmission-daemon<br><br></em>Now access transmission web manage interface at <a href="http://ip_of_the_router:9091/">http://ip_of_the_router:9091/</a><br>If everything works out, move to next step.<br><br> <li><font color="#008000"><strong>Run it as service</strong></font><br>To do so, add the following line to /mnt/root/.profile<br><br><font face="Courier New">export TRANSMISSION_WEB_HOME='/opt/usr/share/transmission/web/'<br><br></font>Then create the startup script <em>/opt/etc/init.d/transmission</em>(delete all previous contents if its not empty)<br><br><font face="Courier New">source /mnt/root/.profile<br>killall </font><font face="Courier New">transmission-daemon</font><br><font face="Courier New">sleep 2<br>transmission-daemon -g /mnt/root/.config/transmission-daemon/</font><br><br>Set it to run as service:<br><em>chmod a+x /opt/etc/init.d/transmission<br>ln -s /opt/etc/init.d/transmission /opt/etc/init.d/S60transmission</em><br></li></ol> Unknownnoreply@blogger.com171tag:blogger.com,1999:blog-1689485144237075657.post-48450051083498479062010-06-26T16:46:00.001-07:002010-06-27T14:17:56.670-07:00Advanced Printer Sharing with hotplug<p>Hotplug is a set of scripts running upon certain predefined conditions. On today's Linux system, hotplug can do many things from auto mounting USB drive, pairing bluetooth devices to network configuration.</p> <p>Seldom mentioned, but DD-WRT does offer (very preliminary) hotplug support. With almost no info on the web, the job is done by digging though DD-WRT's source code and various Linux documents.</p> <ol> <li><strong><font color="#008000">Replace DD-WRT's event handler with our own</font><br></strong>By default, DD-WRT registers <em>/sbin/hotplug</em> to handle all hotplug requests but the program, <em>/sbin/hotplug</em> doesn't follow standard hotplug rules, and, per my understanding, is a dummy and does nothing at all. So let's replace it with our own<br><br>Create a startup script <em>/opt/etc/init.d/hotplugd</em> with only one line:<br><br><font face="Courier New">echo /opt/sbin/hotplug > /proc/sys/kernel/hotplug<br></font><br>Then set it to run upon start up<br><em>chmod a+x /opt/etc/init.d/hotplugd</em><br><em>ln -s /opt/etc/init.d/hotplugd /opt/etc/init.d/S95hotplugd<br><br></em>run<br><em>/opt/etc/init.d/hotplugd<br></em>and check the result:<br><em>cat /proc/sys/kernel/hotplug<br></em><br>The output should be <em>/opt/sbin/hotplug, </em>which is our new event handler.<br><br> <li><font color="#008000"><strong>Test drive hotplug</strong><br></font>So how does the hotplug work? below script will give you some idea to start with:<br>Create <em>/opt/sbin/hotplug</em> with following:<br><br><font face="Courier New">#!/bin/sh </font> <p><font face="Courier New">#For Debugging<br>echo "Customized hotplug" >> /tmp/hotplug.log<br>echo -------------$(date)----------- >> /tmp/hotplug.log<br>set >> /tmp/hotplug.log<br><br></font>set it as executable<br><em>chmod a+x /opt/sbin/hotplug</em><br><br>Unplug the printer, wait few seconds and plug the printer back. Check the log by typing:<br><em>cat /tmp/hotplug.log<br><br></em>You can see there are bunch of environmental variables logged, two of them are worth noting:<br><em>ACTION </em>The value for "ACTION" variable can be "add" or "remove", corresponding to device plugin and removal.<br><em>PRODUCT </em>This is the unique device ID for the USB device, my printer is HP 1020 and value is 3f0/2b17/100. <br><br>In a full Linux system, hotplug is much more complex. My script is a quick dirty hack but should be sufficient to handle USB printers.<br></p> <li><strong><font color="#008000">Configure hotplug to upload firmware to the printer<br></font></strong>Some GDI printer(aka Windows printer) will require extra work on Linux. Below is an example of my HP Laserjet 1020 but also applies to other HP laser printers like 1000, 1005, 1018, P1005, P1008, P1505 etc..<br>You'll need two things to start with:<br><strong>The printer's firmware</strong> -- this must be in the printer before printing. Some of popular HP printers' can be downloaded from <a title="http://oleg.wl500g.info/hplj/" href="http://oleg.wl500g.info/hplj/">http://oleg.wl500g.info/hplj/</a><br><strong>usb_printerid</strong> -- this is used to detect if the firmware is already in place to prevent duplicated firmware uploading. Above link has one but that's for Broadcom devices. So I compile one for Atheros routers. <a href="http://www.box.net/shared/c6isfk0ldt" target="_blank">Download here</a>. Extract and put it to the router(samba, ftp or WinSCP).<br><br>Assume we have the firmware in <em>/opt/usr/local/lib/</em> and usb_printerid in <em>/opt/usr/local/bin/, </em>run<br><em>chmod a+x /opt/usr/local/bin/usb_printerid<br><br></em>And finally, here is the full script <em>/opt/sbin/hotplug</em> <p><font size="2" face="Courier New">#!/bin/sh </font> <p><font size="2"><font face="Courier New">#For Debugging<br>#echo "Customized hotplug" >> /tmp/hotplug.log<br>#echo -------------$(date)----------- >> /tmp/hotplug.log<br>#set >> /tmp/hotplug.log</font> </font> <p><font size="2"><font face="Courier New">P910ND='/opt/usr/sbin/p910nd'<br>PRINTERID='/opt/usr/local/bin/usb_printerid'<br>FIRMWARE='/opt/usr/local/lib/<font color="#ff0000">sihp1020.dl</font>'<br>#replace it with your printer's firmware.</font> </font> <p><font size="2" face="Courier New">if [ $DEVTYPE == 'usb_device' ] && [ $PRODUCT == <font color="#ff0000">'3f0/2b17/100</font>' ]; then<br>#replace with your printer's device id.<br> if [ $ACTION == 'add' ]; then<br></font><font size="2" face="Courier New"> #check and upload firmware<br> ${PRINTERID} /dev/usb/lp0 | grep -q FWVER || cat ${FIRMWARE} > /dev/usb/lp0 <br></font><font size="2" face="Courier New"> #kill and restart p910nd<br> kill -9 $(pidof p9100d)<br> ${P910ND} -b -f /dev/usb/lp0 0<br> fi </font> <p><font size="2" face="Courier New"> if [ $ACTION == 'remove' ]; then<br></font><font face="Courier New"><font size="2"> #printer removed, lets stop p910nd<br> kill -9 $(pidof p9100d)<br> fi<br>fi<br></font><br></font>The above script will upload firmware to printer then start p910nd daemon upon printer plug-in and stop p910nd when it's removed.<br></p> <li><strong><font color="#008000">Modified p910nd startup script</font></strong><br>With above script, DD-WRT will automatically configure the printer after the router is fully booted. However, similar approach has to be done during startup as the hotplug does not take effect at that moment.<br>For unknown reasons, DD-WRT will NOT create <em>/dev/usb/lp0</em> for printer even we have printer support enabled. As a result, we can't use this device node to detect the printer's presence.<br><br>Here is a modified version of <em>/opt/etc/init.d/p910nd</em> startup script.<br><br><font size="2" face="Courier New">source /mnt/root/.profile </font> <p><font size="2" face="Courier New">mkdir -m 755 -p /dev/usb<br>mknod -m 660 /dev/usb/lp0 c 180 0<br>sleep 1 </font> <p><font size="2"><font face="Courier New">P910ND='/opt/usr/sbin/p910nd'<br>PRINTER_ID='/opt/usr/local/bin/usb_printerid'<br>FIRMWARE='/opt/usr/local/lib/<font color="#ff0000">sihp1020.dl</font>'<br>#replace with yours<br>PNAME='<font color="#ff0000">LaserJet</font>'<br>#printer name id string, see below</font> </font> <p><font size="2"><font face="Courier New">i=$(find /sys/devices/platform/ -name product -exec cat {} \; | grep -c ${PNAME})</font> </font> <p><font face="Courier New"><font size="2">if [ $i != '0' ]; then<br> ${PRINTER_ID} /dev/usb/lp0 | grep -q FWVER || cat ${FIRMWARE} > /dev/usb/lp0<br> kill -9 `pidof p9100d`<br> ${P910ND} -b -f /dev/usb/lp0 0<br>fi<br></font><br></font>Notice the <em>PNAME='<font color="#ff0000">LaserJet</font>'</em> line. The 'LaserJet" is part of the printer's name and can be used to check if the printer is plugged. To determine yours, run<br><br><em>find /sys/devices/platform/ -name product -exec cat {} \; <br><br></em>The result looks like that:<br><em>HP LaserJet 1020 #</em>printer<br><em>DataTravelerMini #</em>USB flash drive<br><em>Atheros AR91xx built-in EHCI controller #</em>USB controller<br></p></li></ol> <p>After that, follow the <a href="http://g300nh.blogspot.com/2010/06/printer-server-for-dd-wrtthe-simple.html" target="_blank">previous tutorial</a> to install printer in Windows if you haven't done so. Now enjoy the convenience of hotplug.</p> Unknownnoreply@blogger.com54tag:blogger.com,1999:blog-1689485144237075657.post-14509952859897751192010-06-26T03:01:00.001-07:002010-06-26T04:06:39.093-07:00Printer Server for DD-WRT(the simple version)<p>With USB port on the router, a normal USB printer can be hooked and become a network printer with wired or wireless capabilities. As the router is usually on 24x7, there is no need to invest a (usually overpriced) dedicated printer server or plug the printer around.</p> <p>The printer server program we use here is <strong><em>p910nd. </em></strong>It's a very small(only 8KB) daemon which simply redirects all printing command from PC to the printer.</p> <p>Setting p910nd on the router can be a snap or very comprehensive depends on the printer. The best scenario would be sharing a Postscript/PCL compatible one and will be covered here.</p> <p><strong>Before start, you'll need a USB hub if your router has only one USB port </strong>as we now need to connect a USB drive and a USB printer. Unpowered hub is good for USB flash drive or hard drive with external power supply while I would suggest a powered hub for hard drive solely relied on USB power to prevent overload or damage to the HDD.</p> <ol> <li><strong><font color="#008000">Set DD-WRT support for USB printer<br></font></strong>If you haven't done so, check <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">earlier post</a> step #2. Make sure the USB printer support is selected.<br><br> <li><strong><font color="#008000">Install p910nd server and run it as a service</font></strong><br>Log in from PuTTY and run<br><em>opkg install p910nd<br><br></em>Now create /opt/etc/init.d/p910nd(delete all previous contents if the file is not empty)<br><br><font face="Courier New">source /mnt/root/.profile <br>mkdir -m 755 -p /dev/usb<br>mknod -m 660 /dev/usb/lp0 c 180 0<br>sleep 1<br>P910ND='/opt/usr/sbin/p910nd'<br>kill -9 $(pidof p9100d)<br>${P910ND} -b -f /dev/usb/lp0 0</font><br><br>Then set it to run as a service<br><em><br>chmod a+x /opt/etc/init.d/p910nd<br>ln -s /opt/etc/init.d/vsftpd /opt/etc/init.d/S30p910nd</em><br><br>Reboot or manually run <em>/opt/etc/init.d/p910nd</em> to make the change take effect.<br><br> <li><strong><font color="#008000">Install printer in Windows<br></font></strong>So we have p910nd running in the router now back to the PC(and Windows). First, you need to have the printer driver installed on the local computer. Exact procedures depend on the printer, but a foolproof way is to plug the printer back to PC then run manufacturer provided driver setup file. <br><br>After driver installation, in Windows XP, <a href="http://technet.microsoft.com/en-us/library/cc976760.aspx" target="_blank">follow this guide</a>. <br><br>Can't find a detail guide for Windows 7 but its essentially the same as earlier Windows editions. Anyway, here is a quick one:<br><br>For Windows 7, Open Control Panel->Hardware and Sound->Devices and Printers, then right click the printer icon. Select "Printer Properties" then click the "Ports" tab on the properties window.<br><br>The default port might be USB001 that's for local USB port. Click "Add Port..." button, then select "Standard TCP/IP Port" from the list. Click "New Port..." which will open "Add Standard TCP/IP Printer Port Wizard". Click next and fill the "Printer Name or IP Address" with router's IP.<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="add-printer-1" border="0" alt="add-printer-1" src="http://lh5.ggpht.com/_g-JnOWjedOQ/TCXP4Eaj-4I/AAAAAAAAABk/owL_o-L4yIQ/add-printer-1%5B5%5D.gif?imgmax=800" width="612" height="454"> <br>After clicking "Next", Windows will try to detect the printer port and will fail. That's OK. On the next page, select "Custom" then click "Settings...". This will bring you another window, the default setting with Protocol Raw and Port Number 9100 should work. Confirm the change then back to original "Ports" tab. Select the newly added 192.168.1.1 port as default and click "Apply". <br><br>Now plug the printer back to router and try to print from Windows machine.<br> </li></ol> <p>This is a ten-minute work if your printer is well supported aka. Linux friendly. However, things can get nasty for some GDI printer -- just name a few, the popular HP Laserjet 1010, 1018 and 1020. Also, you might want the p910nd to run only when the printer is connected. To solve all these problems, we need to make the router aware of printer's status change(plugging or removal) and run commands upon that. This is called <em>hotplug </em>and we can make some really neat solution with that.</p> Unknownnoreply@blogger.com382tag:blogger.com,1999:blog-1689485144237075657.post-14831795090919384692010-06-26T01:29:00.001-07:002010-06-28T21:05:28.922-07:00vsftpd: FTP Server for DD-WRT<p>I generally prefer Samba over FTP as it gives a better experience by allowing user to access the files as if they're still on local disk. And, unlike FTP, media files can be played directly from Samba share. But one might still need FTP server as it offers better performance over Samba.<br><br>If the router has at least 8MB flash ROM and happens to run DD-WRT MEGA build, very likely there is a proftpd FTP server built in. But here I'll take some extra trouble to use lightweight vsftpd instead.</p> <p>So why vsftpd? The main reason is its size. The proftpd is 500KB while vsftpd is only 100KB! This makes it perfect for embedded systems. Also, vsftpd is easy to use and setup.</p> <ol> <li><strong><font color="#008000">Disable stock ProFTPD server</font></strong><br>For DD-WRT, it's in Services->NAS. Set it to Disable then click "Apply Settings". <br><br> <li><strong><font color="#008000">Install vsftpd</font></strong><br>Assume you have followed <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">previous tutorials</a> and has a working opkg system, now use PuTTY to log in the router and run<br><em>opkg install vsftpd<br><br></em> <li><strong><font color="#008000">(optional)Add a user for anonymous FTP access<br></font></strong><em>*ignore this part if you've follow the <a href="http://g300nh.blogspot.com/2010/06/samba-sharing-in-dd-wrt.html" target="_blank">Samba guide</a>, then this user is already in the system</em>.<br><br>Create or add to <em>/opt/etc/init.d/adduser </em>with following line:<br><br><font face="Courier New">grep -q nobody /etc/passwd || echo 'nobody:x:65534:65534:nobody:/mnt:/bin/false' >> /etc/passwd<br><br></font>Above is one single line and will create a new user "nobody" with no valid password and login shell(thus can't be used for login). Then set it to run during boot up:<br><br><em>chmod a+x /opt/etc/init.d/adduser<br>ln -s /opt/etc/init.d/adduser /opt/etc/init.d/S05adduser<br><br></em> <li><strong><font color="#008000">vsftpd.conf, the configuration file for vsftpd<br></font></strong>Edit file <em>/opt/etc/vsftpd.conf</em> with below(delete all previous contents if the file is not empty) <p><font face="Courier New">background=YES<br>listen=YES<br>listen_port=21<br>#Change it if you want to use other port<br>anonymous_enable=YES<br>#Set it to NO if you don't want anonymous FTP access<br>ftp_username=nobody<br>#local user used for anonymous FTP access, here is "nobody"<br>local_enable=YES<br>write_enable=YES<br>local_umask=022<br>check_shell=NO<br>session_support=NO<br></font><font face="Courier New"><br></font>For a full list of options, please refer to <a href="http://vsftpd.beasts.org/vsftpd_conf.html" target="_blank">vsftpd website</a>. These basic options here should be enough for home use. With the settings above, the anonymous user will be locked to "/mnt" folder(if you enable the anonymous option). Can also login with other valid user accounts like "root" or "share" with no restriction.</p> <li><strong><font color="#008000">Set vsftpd to run as a service</font></strong><br>Create file <em>/opt/etc/init.d/vsftpd</em>(delete all previous contents if the file is not empty)<br><br><font face="Courier New">[ -d /var/run/vsftpd ] || mkdir /var/run/vsftpd<br>kill -9 $(pidof vsftpd)<br>vsftpd /opt/etc/vsftpd.conf</font> <p>Then set it to run as a service<br><em><br>chmod a+x /opt/etc/init.d/vsftpd<br>ln -s /opt/etc/init.d/vsftpd /opt/etc/init.d/S60vsftpd</em></p></li></ol> Unknownnoreply@blogger.com9tag:blogger.com,1999:blog-1689485144237075657.post-2977147326950538692010-06-25T03:51:00.001-07:002010-07-03T21:57:29.914-07:00Samba the File Share Server in DD-WRT<p>It's not an easy job to configure Samba share in standard DD-WRT because by default, the /etc folder is read-only. So before start, please following the <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">previous tutorial</a> to set a writable /etc. Also, might to your surprise, DD-WRT does have a Samba3 built in the firmware and it works just fine. In this article, you'll be guided through the whole process to set up a password protected samba share with customized username/password.</p> <ol> <li><font color="#008000"><strong>Check if there is a Samba server built in<br></strong></font>Log in the router, then run <br><em>smbd --version<br></em>Output should be "Version 3.0.24", which means the firmware has Samba 3.0.24 included.<br>If the Samba server is missing, install it by running<br><em>opkg install samba3<br><br></em> <li><font color="#008000"><strong>Add dedicated users for Samba<br></strong></font>For security reasons, I strongly suggest NOT to use "root" to access your Samba share. Instead, here we'll create users for Samba(and ftp) only with minimal privilege and no login shell.<br>First, add the following lines to file <em>/etc/passwd<br><br></em><font face="Courier New">nobody:x:65534:65534:nobody:/mnt:/bin/false<br>share:x:65534:65534:share:/mnt/share:/bin/false<br></font><br>Save the /etc/passwd file, then run <br><em>passwd share</em><br><br>to change the password for user "share". Now check the content of the updated <em>/etc/passwd</em> file, the line for user "share" will look like:<br><br><em>share:<font color="#ff0000">$1$2zhNidn9$DJK7SG8aqMg2hDsBYv6yZ.</font>:65534:65534:share:/mnt/share:/bin/false<br></em><br>The red part is the encrypted password. In the example line above, the password is also set to "share".<br><br>To make the change permanent, create a new script <em>/opt/etc/init.d/adduser</em> <br><br> <p><font face="Courier New">grep -q nobody /etc/passwd || echo 'nobody:x:65534:65534:nobody:/mnt:/bin/false' >> /etc/passwd<br>grep -q share /etc/passwd || echo 'share:<font color="#ff0000">$1$2zhNidn9$DJK7SG8aqMg2hDsBYv6yZ.</font>:65534:65534:share:/mnt/share:/bin/false' >> /etc/passwd<br><br></font>Don't forget to change the red part. Then set it to run during boot up:<br><em>chmod a+x /opt/etc/init.d/adduser<br>ln -s /opt/etc/init.d/adduser /opt/etc/init.d/S05adduser</em><br><br>The Home folder for user <em>share</em> will be <em>/mnt/share, </em>create it if its not present.<br><br><em>mkdir -m 777 /mnt/share<br></em><br>Then use <em>smbpasswd</em> to add a samba user with username "share" and password "share"<br><br><em>mkdir /etc/samba<br>touch /etc/samba/smbpasswd<br>smbpasswd share <font color="#ff0000">share</font></em><br>#replace the red part with your own password<br><br>Copy the newly created /etc/samba/smbpasswd to /opt/etc/samba/smbpasswd to keep the /etc/ folder clean and in the future all configuration files will be stored in /opt/etc/samba folder. Please leave /etc/samba folder there(don't delete it) as its also required by Samba.<br><br><em>mkdir -p /opt/etc/samba/<br>cp -a /etc/samba/* /opt/etc/samba/<br>chmod 644 /opt/etc/samba/smbpasswd<br><br></em></p> <li> <p><font color="#008000"><strong>smb.conf, the configuration file for Samba<br></strong></font>Use vi or nano, create file <em>/opt/etc/samba/smb.conf</em> with contents below: <br><br><font face="Courier New">[global]<br> netbios name = DD-WRT<br> workgroup = WORKGROUP<br> server string = DD-WRT<br> syslog = 10<br> encrypt passwords = true<br> passdb backend = smbpasswd<br> obey pam restrictions = yes<br> socket options = TCP_NODELAY<br> preferred master = no<br> os level = 20<br> security = user<br> guest account = nobody<br> invalid users = root<br> smb passwd file = /opt/etc/samba/smbpasswd<br> unix charset = UTF-8<br> dos charset = UTF-8 <br></font><font face="Courier New">[homes]<br> comment = Home Directories<br> browseable = no<br> read only = no<br> create mode = 0750 <br></font><font face="Courier New">[USBDrive]<br> path = /mnt/<br> read only = no<br> guest ok = no<br> create mask = 0700<br> directory mask = 0700</font><br><br>Now test the file by running<br><br><em>smbd -s /opt/etc/samba/smb.conf<br><br></em>and access the Samba server by typing <a href="file://\\192.168.1.1"><em>\\192.168.1.1</em></a> in the address bar. Login with user "share". You should see two folders: "Share"(/mnt/share) and "USBDrive"(the whole /mnt folder).<br><br><strong>For Windows Vista/7 machine, a compatibility bit must be set to work with the Linux Samba share. See the end of the post.<br></p></strong> <li><font color="#008000"><strong>Run Samba as a service<br></strong></font>If everything works out, it's time for the startup script<br>Create file <em>/opt/etc/init.d/samba</em>(delete all previous contents if its not empty). <br><br><font face="Courier New">kill -9 $(pidof smbd)<br>kill -9 $(pidof nmbd)<br>/usr/sbin/smbd -s /opt/etc/samba/smb.conf<br>#if you installed samba3 through opkg, use<br>#/opt/bin/smbd -s /opt/etc/samba/smb.conf</font> <br><br>Then set it to run upon bootup:<br><br><em>chmod a+x /opt/etc/init.d/samba<br>ln -s /opt/etc/init.d/samba /opt/etc/init.d/S50samba</em><br><br> <li><strong><font color="#008000">(Optional)Fix Samba and Windows Vista/7<br></font></strong>When accessing Samba from a Windows Vista/7 machine, the password will always be rejected regardless whatever you input. That's because the Samba we used here does not support the new password authorization scheme in Windows. <br>To fix:<br>Run <em>secpol.msc <br></em>Go to: Local Policies -> Security Options <br>Find "Network Security: LAN Manager authentication level" and change setting from "Send NTLMv2 response only" to "Send LM & NTLM - use NTLMv2 session security if negotiated" <br><br>Some Windows versions may not have <em>secpol.msc</em>, in this case, save these 3 lines below to file <em>sambafix.reg</em> and run it: <br><br><font face="Courier New">Windows Registry Editor Version 5.00 <br>[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa] <br>"LmCompatibilityLevel"=dword:00000001<br><br></font>Reboot the Windows to make the change take effect.</li></ol> Unknownnoreply@blogger.com86tag:blogger.com,1999:blog-1689485144237075657.post-91225902625880231172010-06-24T22:57:00.001-07:002010-06-25T15:26:10.958-07:00Set DD-WRT to Use Local Time<p>This never <em>looks</em> to be a problem since DD-WRT provides such extensive options. Unfortunately, unlike Tomato and OpenWrt, which do a good job, DD-WRT's approach is way off and completely wrong.</p> <p>A Linux box can keep its time in either local time or UTC -- both are fine as long as the corresponding time zone info is presented. However, in DD-WRT, the time zone info is completely missing and instead of standard implementing used in almost all Linux distros, DD-WRT coins a weird scheme to setup(and keep) the time.</p> <p>For example, 8AM PST(GMT-8) should be 4PM GMT, but a DD-WRT router would "think" the current time is 8AM GMT. Now if you change the time zone to EST(GMT-5), what will the router think? 11AM GMT!! Yes, that's after you've set all the "time zone" info in DD-WRT web management page. This is usually not a problem if you just want to use it as a router but for a Linux server, you definitely don't want to deal with any file created in future.</p> <p>Now here is the fix:</p> <ol> <li><strong><font color="#008000">Disable DD-WRT's own NTP client<br></font></strong>From DD-WRT's web interface, Setup->Basic Setup, at the bottom of the page, disable the whole NTP part.<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ntp-disable" border="0" alt="ntp-disable" src="http://lh6.ggpht.com/_g-JnOWjedOQ/TCRFVuAPc4I/AAAAAAAAABg/nmNn3YVqH50/ntp-disable%5B5%5D.gif?imgmax=800" width="485" height="149"> <br>Then click "Apply Settings"<br><br> <li><strong><font color="#008000">Install our own NTP client<br></font></strong>Use PuTTY to login the router, then run<br><br><em>opkg install ntpclient<br></em><br>Then we need to get the newly installed ntpclient running as a service. To do so, use vi or nano and create a file named <em>/opt/etc/init.d/ntpclient<br><br></em><font face="Courier New">source /mnt/root/.profile<br>/opt/usr/sbin/ntpclient -i <font color="#ff0000">600</font> -D -s -l -h <font color="#ff0000">pool.ntp.org</font> -p 123<br>#600 means it will sync every 10 minutes(600 seconds)<br>#pool.ntp.org is the NTP server to use<br><br></font>Give it executable permission and then set it to run on start up.<br><br><em>chmod a+x /opt/etc/init.d/ntpclient<br>ln -s /opt/etc/init.d/ntpclient /opt/etc/init.d/S20ntpclient<br><br></em> <li><strong><font color="#008000">Set time zone info for DD-WRT</font></strong><br>First, we need to create the /etc/TZ file with proper time zone info<br><br><em>echo <font color="#ff0000">PST8PDT,M3.2.0,M11.1.0</font> > /etc/TZ<br></em><br>The red part an example(US Pacific) and the full list can be found <a href="http://wiki.openwrt.org/doc/uci/system" target="_blank">here(the time zone table)</a>. Replace it with yours accordingly. And, don't worry about daylight saving time, it's already taken care of.<br><br>We also need to set the TZ variable by adding a line in <em><a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-2.html" target="_blank">/mnt/root/.profile</a><br><br>export TZ=$(cat /etc/TZ)<br><br></em>Finally, there is a hidden nvram value used by DD-WRT internally, it's also needed to be fixed or the web page will display a wrong time. From PuTTY, run:<br><br><em>nvram set time_zone=<font color="#ff0000">PST8PDT,M3.2.0,M11.1.0</font><br>nvram commit</em><br>#replace the red part with <a href="http://wiki.openwrt.org/doc/uci/system" target="_blank">yours</a>.<br></li></ol> <p>It's done. Reboot the router and login with PuTTY, type <em>date </em>to check the output. DD-WRT should start using local time now.</p> Unknownnoreply@blogger.com137tag:blogger.com,1999:blog-1689485144237075657.post-38925786622104309452010-06-24T14:45:00.001-07:002010-06-28T20:49:05.141-07:00Software Installation on DD-WRT -- Part 2<p>In <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">previous part</a>, we have everything settled(almost). Now its the time for some more fine tune.</p> <p>By employing the techniques in Part 1, we have the following setup upon each reboot:</p> <ul> <li>A USB drive mounted and accessible at /mnt <li>A writable /etc folder(actually /mnt/etc) and has exact same content as original /etc folder <li>A writable /opt folder(actually /mnt/opt) -- where all future software will be installed and run from(/opt/bin, /opt/sbin, /opt/usr/bin, just name a few) and keep the original DD-WRT folders like /bin /sbin untouched. <li>A writable and persistent /tmp/root(actually /mnt/root). This will be the home folder for user <em>root</em> <li>An empty file <em>/mnt/optware.enable. </em>This is used to control the whole optware installation. By renaming or deleting this file, all customized software/modification <strong>WILL</strong> <strong>BE DISABLED</strong> and thus put the router back to standard DD-WRT. This is useful for debugging and firmware upgrading.</li></ul> <p>Still, there is something left to do, notably that, with current setup, the LD_LIBRARY_PATH and PATH variables have to be set each time before running any command. We might also want to run some installed software as service.</p> <ol> <li><strong><font color="#00ff40"><font color="#008000">Set the initial variables</font></font></strong><br>Login with PuTTY then copy/paste the commands below to PuTTY window to create a script running each time when user <em>root </em>logins.<br><br><em>cat > /mnt/root/.profile << EOF<br>export LD_LIBRARY_PATH='/opt/lib:/opt/usr/lib:/lib:/usr/lib:/opt/usr/local/lib'<br>export PATH='/sbin:/opt/bin:/opt/usr/bin:/opt/sbin:/opt/usr/sbin:/bin:/usr/bin:/usr/sbin:/opt/usr/local/bin'<br>export PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'<br>export TERMINFO='/opt/usr/share/terminfo' <br>EOF<br><br></em>The above script will set the variables for us and also provide a nice colored command line prompt. Now exit the current PuTTY window and connect again, if you see a colored prompt then it's working correctly. Run <br><em>opkg update <br></em>directly and it should work now -- no need to set the lengthy variables each time. Also, if you're not familar with vi, time to get the nano editor<br><em>opkg install nano<br></em>Then type <em>nano </em>to launch it. <br><br> <li><strong><font color="#008000">Run installed software as service<br></font></strong>In <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-1.html" target="_blank">previous guide(Part 1)</a>, our DD-WRT startup script does nothing more than mounting several folders. We don't use it to launch any programs simply because its not necessary as DD-WRT has a feature that, it will run any script during startup automatically once it's in correct location with correct name.<br><br>To run a script with our current setup, all we need to do is to put the scripts to <em>/opt/etc/init.d</em> folder and name them in the format of <font color="#ff0000">S##ScriptName</font>. The ## is two digit from 00 to 99, script with smaller number will run first. For example, to run Samba file server and p910nd printer server as services, we just need to create two startup script<br><em>/opt/etc/init.d/p910nd<br>/opt/etc/init.d/samba<br></em>then make symbolic links:<br><em>ln -s</em> <em>/opt/etc/init.d/p910nd </em><em>/opt/etc/init.d/S30p910nd<br>ln -s <em>/opt/etc/init.d/samba </em><em>/opt/etc/init.d/S50samba</em></em><em><br> </em><br>and p910nd will start up first then samba. And, in case you don't need them as service, delete the symbolic links(S30p910nd/S50samba) but keep the original startup script so it can be easily recovered. The program can also be launched directly by running the corresponding script(<em>/opt/etc/init.d/p910nd </em>and <em>/opt/etc/init.d/samba)</em></li></ol> <ol>Guide for <a href="http://g300nh.blogspot.com/2010/06/samba-sharing-in-dd-wrt.html" target="_blank">Samba server</a> and the <a href="http://g300nh.blogspot.com/2010/06/printer-server-for-dd-wrtthe-simple.html" target="_blank">p910nd printer server</a> will be detailed in future articles. This is just to get you an idea how the startup control system works.</ol> Unknownnoreply@blogger.com99tag:blogger.com,1999:blog-1689485144237075657.post-68463962233705100382010-06-24T02:52:00.001-07:002010-07-02T14:42:00.262-07:00Software Installation on DD-WRT -- Part 1<p>One thing interesting about the router is its exotic hardware specification -- 400MHz processor, 32MB flash ROM, 64MB RAM and most important of all, a USB port. All these make the router a very versatile little Linux box with tons of capabilities. However, one thing might confuse non-experienced users is that, the CPU in the router is MIPS(MIPS in big-endian), while the popular Broadcom routers(such as Linksys WRT54G) are MIPSEL(MIPS in little-endian). I don’t want to go into technical detail here, but just remember, even both are MIPS, they’re different and prebuilt binary for Broadcom routers <strong>WILL NOT</strong> work on this WZR-HP-G300NH and other Atheros based devices.</p> <p>Thanks to the OpenWrt guys, with some effort, we can now put the OpenWrt binary on this router and it will run as good as the popular “optware”.</p> <p>In this tutorial, I'll guide you through the process and all software will be installed on USB disk though the Buffalo router has a gorgeous 32MB flash ROM. The reason is simple – the flash ROM jffs partition will NOT survive during a firmware upgrade and you definitely don’t want to reinstall everything again each time. Also, USB disk is much faster than internal flash.</p> <p>This guide will also work with other USB enabled Atheros routers such as <a href="http://www.tp-link.com/products/productDetails.asp?pmodel=TL-WR1043ND">TP-LINK TL-WR1043ND</a>, <a href="http://homesupport.cisco.com/en-us/wireless/lbc/WRT160NL" target="_blank">Linksys WRT160NL</a>, <a href="http://www.dlink.com/products/?pid=681" target="_blank">D-LInk DIR-825 RevB</a> and <a href="http://www.netgear.com/ultimatewifi" target="_blank">Netgear WNDR3700</a></p> <ol> <li><strong><font color="#008000">Prepare the USB disk</font></strong><br>Here we can use a USB flash drive or a USB hard drive and the drive must be preformatted to ext2 or ext3(recommended) before plugging into the router.<br>Any Linux live CD should do the trick and I personally recommend <a href="http://gparted.sourceforge.net/livecd.php" target="_blank">GParted</a>, which can be installed in CD or USB disk. <br><br> <li><strong><font color="#008000">Set up DD-WRT accordingly<br></font></strong>a. Turn on ssh.<br>This is under Services->Service->Secure Shell. See the picture below. Then click “Apply Settings” at the bottom of the page.<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssh-enable" border="0" alt="ssh-enable" src="http://lh5.ggpht.com/_g-JnOWjedOQ/TCMq5i4ftkI/AAAAAAAAABM/8LbdBQz6g8w/ssh-enable%5B6%5D.gif?imgmax=800" width="615" height="459"> <br><br>b. Set USB Support<br>Under Services->USB tab. Will disable “Automatic Drive Mount” here. After that, click “Apply Settings”<a href="http://lh6.ggpht.com/_g-JnOWjedOQ/TCMq6b2RRfI/AAAAAAAAABQ/H1v9TvAJHGc/s1600-h/usb-enable%5B5%5D.gif"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="usb-enable" border="0" alt="usb-enable" src="http://lh3.ggpht.com/_g-JnOWjedOQ/TCMq7eqC1kI/AAAAAAAAABU/WnyHOOCMw9s/usb-enable_thumb%5B3%5D.gif?imgmax=800" width="632" height="475"></a> <br><br>c. Disable the jffs partition<br>Under Administration->Management, disable “JFFS2 Support”. After that, click “Apply Settings”.<br><br> <li><strong><font color="#008000">Download </font></strong><a href="http://winscp.net/eng/download.php#download2" target="_blank"><strong><font color="#008000">WinSCP</font></strong></a><strong><font color="#008000">, </font></strong><a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank"><strong><font color="#008000">PuTTY</font></strong></a><strong><font color="#008000"> and prebuilt libraries</font></strong><br><a href="http://winscp.net/eng/download.php" target="_blank">WinSCP</a> is used to copy file between PC and router and <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html" target="_blank">PuTTY</a> is for router shell login. Both are freeware. <br>Also, you’ll need some prebuilt OpenWrt libraries called <em>lib.tar(</em>thanks Luyi@DD-WRT forum check <a href="http://www.dd-wrt.com/phpBB2/viewtopic.php?t=67678" target="_blank">original discussion thread</a>) <br>Get it from <a href="http://www.dd-wrt.com/phpBB2/download.php?id=13515" target="_blank">DD-WRT forum</a>(login required) or <a href="http://www.box.net/shared/gsosdajvzm" target="_blank">mirror site</a>.<br><br> <li><strong><font color="#008000">Now plug in the USB drive and reboot the router.<br><br></font></strong> <li><font color="#008000"><strong>After rebooting, login the router with PuTTY.</strong></font> <br>Fill in router’s IP(192.168.1.1 in most cases), left everything else on default(port 22 and Connection type SSH) and click “Open”. <br>The login username is always <em>root </em>and password is the web password you set. <br><br> <li><strong><font color="#008000">Mount the USB drive</font></strong><br>Type the command in PuTTY window<br><em>ls /dev/discs/disc0/ <br></em>and the result might look like this<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="disc-partitions" border="0" alt="disc-partitions" src="http://lh6.ggpht.com/_g-JnOWjedOQ/TCMq8C36rjI/AAAAAAAAABY/9cQhg8p6zKg/disc-partitions%5B5%5D.gif?imgmax=800" width="419" height="93"> <br>Now here is the tricky part. If you’re using a USB flash drive with only one partition, most likely, you will only see “disc” but not “part1” and “part2”. If you’re using a USB HDD with multi partitions you might expect an output similar to mine. Both are OK.<br><br>If you see “disc” only, use the command line below to mount an ext3 USB drive to /mnt<br><em>mount -t ext3 -o noatime /dev/discs/disc0/disc /mnt<br></em>*Use <em>mount -t ext2 /dev/discs/disc0/disc /mnt</em> for ext2 drive<br><br>For USB drive with multi partition, the command below will mount the first partition to /mnt. Adjust accordingly.<br><em>mount -t ext3 -o noatime /dev/discs/disc0/<font color="#ff0000">part1</font> /mnt<br></em>*Use<em> mount -t ext2 /dev/discs/disc0/<font color="#ff0000">part1</font> /mnt </em>for ext2 partition<br><br> <li><strong><font color="#008000">Now create and prepare necessary folders<br></font></strong>Type the commands below in PuTTY<br><br><em>cd /mnt<br>mkdir etc opt root<br>touch optware.enable<br>chmod 755 etc opt root<br>mkdir opt/lib<br>chmod 755 opt/lib<br>cp -a /etc/* /mnt/etc/ <br>mount -o bind /mnt/etc /etc <br>mount -o bind /mnt/opt /jffs<br><br></em>So now we have a writable /etc and /jffs folders while they both reside in the USB drive. All other folders -- especially /bin, /usr and /sbin – will be left untouched to keep the change minimal. The /etc folder will also be handled with extra caution.<br><br> <li><strong><font color="#008000">Extract <em>lib.tar</em> and upload all files to router’s <em>/jffs/lib</em> folder by using WinSCP.</font></strong><br>Same as PuTTY, the username will always be <em>root</em>, the file protocol must be set to SCP. See the picture below<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="winscp-login" border="0" alt="winscp-login" src="http://lh6.ggpht.com/_g-JnOWjedOQ/TCMq9ZDhvLI/AAAAAAAAABc/2tbHyoqgzvw/winscp-login%5B5%5D.gif?imgmax=800" width="549" height="394"> <br>After that, ignore all warning messages and click “yes” all the way. You’ll see the file transfer Window then. Also please refer to <a href="http://www.dd-wrt.com/wiki/index.php/WinSCP" target="_blank">DD-WRT Wiki</a> if there is any other question.<br><br><strong>Now extract <em>lib.tar</em>(using WinRAR or 7Zip)<em> </em>and upload everything to router’s <em>/jffs/lib</em> folder.<br></strong><br>In the Putty window, run<br><em>ls /jffs/lib <br></em>to make sure all files are uploaded, then run <br><em>chmod a+x /jffs/lib/* <br></em>to set the properties.<br><br> <li><strong><font color="#008000">Install OpenWrt’s opkg</font></strong><br>Now in the PuTTY window, type<br><em><br>cd /tmp<br>wget http://downloads.openwrt.org/backfire/10.03/ar71xx/packages/opkg_513-2_ar71xx.ipk<br>ipkg install /tmp/opkg_513-2_ar71xx.ipk<font color="#ff0000"><br></font></em><br>After that, run the command to create the configuration file for newly installed opkg<br><br><em>cat > /etc/opkg.conf << EOF<br>src/gz snapshots http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/ <br>dest root <u>/opt</u> <br>dest ram /tmp <br>lists_dir ext /tmp/var/opkg-lists<br>EOF<br><br></em>Also notice the underlined <u>/opt</u>. In the future, all software will be installed to /opt folder in case some might still want to use internal flash. The /jffs folder is only necessary for initial setup.<br><br> <li><strong><font color="#008000">Set the startup script to make the changes take effect each time upon reboot</font></strong><br>Under DD-WRT’s web interface, Administration->Commands, input the following command in the window then click “Save Startup” <p><font face="Courier New">#!/bin/sh </font> <p><font face="Courier New">sleep 5<br>#mount -t ext3 -o noatime /dev/discs/disc0/disc /mnt<br>mount -t ext3 -o noatime /dev/discs/disc0/part1 /mnt <br><font color="#ff0000">#choose one for your drive, see Step #6</font> </font> <p><font face="Courier New">sleep 2<br>if [ -f /mnt/optware.enable ]; then<br>mount -o bind /mnt/etc /etc<br>mount -o bind /mnt/root /tmp/root<br>mount -o bind /mnt/opt /opt<br>else<br>exit<br>fi </font> <p><font face="Courier New">if [ -d /opt/usr ]; then<br>export LD_LIBRARY_PATH='/opt/lib:/opt/usr/lib:/lib:/usr/lib'<br>export PATH='/opt/bin:/opt/usr/bin:/opt/sbin:/opt/usr/sbin:/bin:/sbin:/usr/sbin:/usr/bin'<br>else<br>exit<br>fi</font> <br><br>Reboot to make the change take effect.<br></p> <li> <p><strong><font color="#008000">Test opkg package system</font></strong><br>After reboot, login with PuTTY again, run <br><br><em>export LD_LIBRARY_PATH='/opt/lib:/opt/usr/lib:/lib:/usr/lib'<br>export PATH='/opt/bin:/opt/usr/bin:/opt/sbin:/opt/usr/sbin:/bin:/sbin:/usr/sbin:/usr/bin'<br>opkg update<br><br></em>to check if opkg(the OpenWrt’s variant of ipkg) is installed and working properly.<br>Then install/upgrade some base libraries and the busybox utility<br><br><em>opkg install libc<br>opkg install libgcc<br>opkg install uclibcxx<br>opkg install libncurses</em><br><em>opkg install busybox</em></p></li></ol> <p>Almost done! There’re still some work and fine tune left which will be covered in <a href="http://g300nh.blogspot.com/2010/06/software-installation-on-dd-wrt-part-2.html" target="_blank">the next part</a>. Unknownnoreply@blogger.com308tag:blogger.com,1999:blog-1689485144237075657.post-40920740198019033142010-06-23T00:14:00.000-07:002010-06-30T18:00:56.330-07:00Firmware flash and brick recovery through TFTP<div>Though the whole flashing process can be done via Web interface(dd-wrt to stock and vice versa) without getting your hands dirty, still, there're cases that the Web flashing is not sufficient. One common scenario is a bricked WZR-HP-G300NH, i.e., no web access and no ping response due to bad firmware or wrong operation, or you just want to try other firmware like OpenWrt. Luckily that the WZR-HP-G300NH has a robust bootloader and the router can be recovered by using TFTP, either in Windows, Linux or OSX.<br></div> <div><br>It's a little tricky comparing to traditional Broadcom routers, as the WZR-HP-G300NH will not broadcast its MAC during initial bootup process, as a result, we must tell the computer how to communicate with the router by manipulating its arp table.<br><br><span style="color: rgb(0,153,0); font-weight: bold">TFTP recovery in Windows</span></div> <div><em>*Untested, credit goes to </em><a href="http://www.dd-wrt.com/phpBB2/viewtopic.php?p=426099#426099" target="_blank"><em>ermax at D-WRT forum</em></a></div> <ol> <li>Get your router's MAC, its the 12 digit default SSID printed on the sticker at the back of the router, starting with 00. Then you'll need to break it down every two digit by inserting <span style="font-style: italic">:</span> or <span style="font-style: italic">-</span> between them.<br> <li><span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)">Download the latest official firmware(in case of recovery) from <a href="http://www.buffalotech.com/support/downloads/nfiniti-wireless-n-high-power-router-access-point-wzr-hp-g300nh/">Buffalo's official website.</a> Extract to get the firmware, in my case, its 1.74 and the firmware name is <span style="font-style: italic">wzrhpg300nh-174</span>, ~20MB.<br><br>Also download the </span></span><span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)"><a href="http://www.dd-wrt.com/dd-wrtv2/downloads/others/tornado/Windows-TFTP/tftp2.exe">Linksys TFTP utility</a>.</span></span><br> <li>(May not necessary) Do a<a href="http://www.dd-wrt.com/wiki/index.php/Hard_reset_or_30/30/30"> hard reset or 30/30/30</a> on the router.<br> <li>Unplug all the ethernet cable and the power cable and connect the computer directly to the router(still leave it off)<br> <li>Set the computer's static IP to 192.168.11.2, netmask 255.255.255.0, gateway/DNS 192.168.11.1.<br> <li>Open a Windows command prompt as Administrator. This is default on Windows XP, under Windows Vista/7, type <span style="font-style: italic">cmd </span>in the search box from Start menu, then press Ctrl+Shift+Enter. You will be prompted with the User Account Control dialog. <br> <li>Type <span style="font-style: italic">route print</span> to get a list of your NIC(s). Write down the interface number for the LAN card, in my case, it's 12.<br><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="interface" border="0" alt="interface" src="http://lh5.ggpht.com/_g-JnOWjedOQ/TCMMIk0r3nI/AAAAAAAAABE/x1FPi_zqaH0/interface%5B5%5D.gif?imgmax=800" width="665" height="157"> <br> <li>Now type the command below to get the ARP binding(thanks <a href="http://www.dd-wrt.com/phpBB2/viewtopic.php?p=426099#426099" target="_blank">ermax at DD-WRT forum</a>):<br><br><span style="font-style: italic">netsh interface ipv4 add neighbors </span><span style="font-style: italic; color: rgb(255,0,0)">12</span><span style="font-style: italic"> 192.168.11.1</span><span style="color: rgb(255,0,0)"><span style="font-style: italic"> 00-1d-12-34-56-78</span><br><br><span style="color: rgb(0,0,0)">Replacing the number 12 with the interface number and 00-1d-12-34-56-78 with the router's MAC address.</span><br></span> <li><span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)">R</span></span><span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)">un <a href="http://www.dd-wrt.com/dd-wrtv2/downloads/others/tornado/Windows-TFTP/tftp2.exe">Linksys TFTP utility</a>.</span></span><span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)"> Put <span style="font-style: italic">192.168.11.1</span> as Server address, Password empty, File is </span></span><span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)"><span style="font-style: italic">wzrhpg300nh-174 </span>just extracted<span style="font-style: italic">, </span>set retry time to <span style="font-style: italic">30</span>.</span></span><span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)"></span></span><br> <li>Click "Upgrade" in the TFTP utility and quickly plug the power back to turn on the router. There might be few failed attempts but the flash process should start later. Wait patiently the router will reboot itself when the upgrade is done. Navigate to http://192.168.11.1(for stock firmware) to configure your router.<br></li></ol> <p><span style="color: rgb(0,153,0); font-weight: bold">TFTP recovery in Linux</span><br><em>*Most of this part is from </em><a href="http://www.dd-wrt.com/wiki/index.php/Buffalo_WZR-HP-G300NH#Old_install_procedure_.28now_obsolete.29" target="_blank"><em>DD-WRT wiki</em></a><em> with some tweak. <strong>TEST WORKING</strong></em><br><br>Will use Ubuntu Live CD as an example but other distro should also work. The Ubuntu LiveCD can be booted from a USB flash drive. <a href="http://www.pendrivelinux.com/create-a-ubuntu-9-10-live-usb-in-windows/" target="_blank">See here</a>.</p> <ol> <li>Do Step 1-4 in "TFTP recovery in Windows" except we don't need Linksys TFTP utility here. So we have MAC address ready, router unpowered and the computer is directly connected to the router.<br> <li>After booting into Ubuntu, open a terminal and type:<br><br><span style="font-style: italic">sudo apt-get update</span><br><span style="font-style: italic">sudo apt-get install tftp-hpa</span><br><span style="font-style: italic">sudo /etc/init.d/networking stop</span><br><span style="font-style: italic">sudo ifconfig eth0 192.168.11.2</span><br><span style="font-style: italic">sudo ifconfig eth0 netmask 255.255.255.0 </span><br><span style="font-style: italic">sudo arp -s 192.168.11.1 </span><span style="font-style: italic; color: rgb(255,0,0)">00:1D:12:34:56:78<br></span>#change to the folder where you put the firmware image, if it's on desktop then it's<br>#"/home/ubuntu/Desktop". <br><em>cd <font color="#ff0000">/home/ubuntu/Desktop</font></em><br><span style="font-style: italic">tftp 192.168.11.1</span><br><span style="font-size: 85%">*from this point, you're under tftp command prompt, the "tftp>" is the prompt tftp gives you, you just need to type the command AFTER that.</span><br>tftp> <span style="font-style: italic">verbose</span><br>tftp> <span style="font-style: italic">binary</span><br>tftp> <span style="font-style: italic">trace</span><br>tftp> <span style="font-style: italic">rexmt 1 </span><br>tftp><span style="font-style: italic"> timeout 60 </span><br>tftp><span style="font-style: italic"> put <span style="color: rgb(255,0,0)">wzrg300nh-firmware.tftp</span></span><br><br>Replace the fictional MAC in red with the router's. All command you need to input is in italic. Also replace<span style="font-style: italic"><span style="color: rgb(255,0,0)"> </span>wzrg300nh-firmware.tftp</span> with the firmware you need, in case of stock firmware, its <span style="color: rgb(255,0,0)"><span style="color: rgb(0,0,0)"><span style="font-style: italic">wzrhpg300nh-174.<br><br></span></span></span>Also, at this point, the router is still unpowered and that's OK. Tftp will keep trying to send the firmware to the router and when it fails (because the router isn't yet on or hasn't yet brought up it's tftp interface) it will wait 1 second and retry, up to 60 times as that's how we set up the tftp client.<br> <li>Now quickly plug the power cord back to the router. The router will start up and you will see some lights blinking (possibly). About 10-20 seconds in, you should notice that tftp is sending the file. instead of the retry message over and over you will see some progress scrolling down the screen and at the end it will tell you how many blocks or bytes were transferred in how many second.<br> <li>After the transfer is complete, wait about 5-10 minutes the router will reboot itself. When the wireless LED is on you're good to go.<br> <li>Bring the network back in Linux by typing<br><br><span style="font-style: italic">sudo service networking start</span><br></li></ol> <div><span style="color: rgb(0,153,0); font-weight: bold">TFTP recovery in OSX<br></span>*Untested, credit goes to <a href="http://www.dd-wrt.com/phpBB2/viewtopic.php?p=421698#421698" target="_blank">BDawg at DD-WRT forum</a><span style="color: rgb(0,153,0); font-weight: bold"></div></span> <ol> <li>Do Step 1-4 in "TFTP recovery in Windows" except we don't need Linksys TFTP utility here. So we have MAC address ready, router unpowered and the computer is directly connected to the router.<br> <li>Set the computer's static IP to 192.168.11.2, netmask 255.255.255.0, gateway/DNS 192.168.11.1.<br> <li>Open a terminal and type<br><br><span style="font-style: italic">sudo arp -s 192.168.11.1 <span style="color: rgb(255,0,0)">00:1D:12:34:56:78</span> ifscope en0 </span><br><br>Replace with your own router's MAC.<br> <li>Type<span style="font-style: italic"><br><br>tftp 192.168.11.1</span><br>tftp> <span style="font-style: italic">put </span><span style="font-style: italic; color: rgb(255,0,0)"><span style="color: rgb(0,0,0)">wzrhpg300nh-174</span></span><br><br>Don't press Enter<br> <li>Now plug the power cord back and hit Enter to start tftp transfer.</li></ol> Unknownnoreply@blogger.com835tag:blogger.com,1999:blog-1689485144237075657.post-29527126419885468512010-06-21T00:13:00.000-07:002010-06-21T01:12:51.435-07:00Flash between DD-WRT and official firmware on WZR-HP-G300NHFlashing DD-WRT on this router is extremely easy now -- thanks to the hard work of DD-WRT developers and <a href="http://www.buffalotech.com/press/releases/buffalo-and-dd-wrt-collaborate-to-create-the-most-comprehensive-consumer-and-small-business-wireless-offering/">the officially partnership with Buffalo</a>.<br /><br /><span style="color: rgb(0, 153, 0); font-weight: bold;">Flash from the stock firmware to DD-WRT</span><br />*Use releases after r14402 to be safe as earlier releases had some problem with certain WZR-HP-G300NHs and might brick the router(can be recovered).<br /><br />Goto <a href="http://www.dd-wrt.com/site/support/router-database">DD-WRT Router Database</a> and type <span style="font-style: italic;">WZR-HP-G300NH</span> in the search box. There are two files listed:<span style="text-decoration: underline;"></span><br /><ul><li>buffalo_to_ddwrt_webflash-MULTI.bin<br />This is used to upgrade from stock firmware to dd-wrt, which includes an encrypted file header to make it compatible with Buffalo's official web upgrade page. Use it when flashing from stock firmware to dd-wrt.<br /><br /></li><li>wzr-hp-g300nh-dd-wrt-webupgrade-MULTI.bin<br />This is for future update from a DD-WRT loaded router.<br /></li></ul>The upgrade process is very straightforward and there is really nothing to elaborate here. Just load <span style="font-weight: bold;">buffalo_to_ddwrt_webflash-MULTI.bin</span> on the firmware upgrade page then wait patiently. Also note that the router's IP will change from 192.168.11.1(Buffalo's stock firmware) to 192.168.1.1(DD-WRT), use DHCP or set the static IP accordingly.<br /><br /><span style="color: rgb(0, 153, 0); font-weight: bold;">Revert DD-WRT to stock firmware<br /><br /></span>DD-WRT for this router is still in early stage so one might want to back to the stock firmware. We can always go through the bulletproof <span style="font-style: italic;">TFTP</span> route but if you just need to revert from DD-WRT, there is a shortcut.<br /><ol><li>Download this modified <a href="http://www.dd-wrt.com/phpBB2/download.php?id=13418">Buffalo firmware</a>(mirror <a href="http://www.box.net/shared/1edtrud64v">download</a>)<br />Its a stock 1.65 firmware and has been modified to work with DD-WRT web upgrade interface. The firmware is on DD-WRT forum and you'll need to register to download it. Or you can download from the mirror link without registration.<br /><br /></li><li>Load file <span style="font-weight: bold;">wzrg300nh_original.bin</span> within DD-WRT web upgrade page to do the conversion. Be patient, it longer than usual and will take like 5-10 minutes.<br /><br /></li><li>After reboot, router's IP will change from 192.168.1.1 -- if you're using DD-WRT's default -- to 192.168.11.1.<br /><br /></li><li>The router will now have firmware 1.65 loaded and you can upgrade it to newer release from this point. Save <span><span style="font-weight: bold;">wzrg300nh_original.bin</span></span><span style="font-style: italic;"> </span>for future use if you're about to try DD-WRT(again)<br /></li></ol>Unknownnoreply@blogger.com27tag:blogger.com,1999:blog-1689485144237075657.post-13312195374977648032010-06-18T22:24:00.000-07:002010-06-29T09:15:53.498-07:00About WZR-HP-G300NH and this blogHave been looking for a new router to replace my old trusty WRT54G-TM(the T-Mobile version of WRT54GS v3) since early this year. My case might be somewhat unusual than others, as besides standard routing jobs, this router will also serve as a 24x7 Linux box, so open source firmware compatibility is a must.<br><br>To keep up with today's standards I made a checklist for my purchase:<br> <ol> <li><span style="font-weight: bold"><font color="#008000">Open source firmware support</font></span><br>DD-Wrt, OpenWrt or Tomato...Well...Linux FTW :)<br><br> <li><font color="#008000"><span style="font-weight: bold">11N Wireless+Gigabit LAN</span><br></font><br>802.11N capable router is getting cheaper today and the performance boost over the old 802.11G is phenomenal. Its not hard to get at least 4-5MB/s even in a crowded apartment with tons of 2.4G AP around.<br><br>For Gigabit LAN, one might think you need expensive cat6 cable to get it working, while in my test, I get ~60MB/s in real world file transferring, which I believe the speed is actually limited by the (slow) notebook hard drive. In <a href="http://sourceforge.net/projects/iperf/">Iperf</a> theoretical test, I get around 900Mb/s throughput -- and its all on some old cat5e cables.<br><br> <li><font color="#008000"><span style="font-weight: bold">USB ports for storage and printer</span><br></font>More storage means more possibility. There're lots we can do with the USB ports, right now, I made it a samba file server and a wireless 11N printer sharing server.<br><br> <li><span style="font-weight: bold"><font color="#008000">At least 4MB of flash ROM and 32MB of RAM</font></span><br>This is not really a problem for today's 11N router expect a few(DIR-655 comes to mind). Anyway, Linux likes RAM, the more the merrier.<br><br> <li><span style="font-weight: bold"><font color="#008000">Reasonable price, sub $100</font></span><br></li></ol>And I finally laid eyes on the routers below:<br> <ul> <li><a href="http://www.netgear.com/Products/WirelessRouter/WirelessRoutersforWorkandPlay/WNR3500L.aspx">Netgear WNR3500L</a><br>Broadcom based router with a powerful 480MHz CPU, 8MB Flash/32MB RAM and USB port. Street price $90.<br><br> <li><a href="http://www.asus.com/product.aspx?P_ID=WAa6AQFncrceRBEo">ASUS RT-N16</a><br>Also Broadcom based and same processor as 3500L(BCM4718@480MHz, initial press release said 533MHz but the final product is downclocked to 480 due to overheating). 32MB Flash and 128MB RAM. Street price $90-$100.<br><br> <li><a href="http://www.tp-link.com/products/productDetails.asp?pmodel=TL-WR1043ND">TP-LINK TL-WR1043ND</a><br>Atheros based solution with 3T3R antenna. 400MHz AR9132 CPU, 8MB ROM and 32MB RAM. Street price is $60-$70.<br><br> <li><a href="http://www.buffalotech.com/products/wireless/routers-and-access-points/nfiniti-wireless-n-high-power-router-access-point-wzr-hp-g300nh/">Buffalo WZR-HP-G300NH</a><br>Similar spec with the TP-Link WR1043ND except 32MB ROM and 64MB RAM. Street price is $80-$90.<br></li></ul>Linksys routers are not on my list because they're seriously overpriced, for example, the WRT160NL, same CPU/ROM/RAM as the TP-Link WR1043ND but only 100Mb switch and Linksys wants $90 for that!<br><br><br>Anyway, I go for Atheros based solution mainly because of the ath9k opensource driver. Comparing to the proprietary Broadcom binary blob, its almost no-brainer for a long time OpenWrt user like me. Also, the Atheros based routers, namely the WZR-HP-G300NH and TL-WR1043ND, are using Realtek switch with Jumbo frame support, which is also a big plus.<br><br>Between TP-Link and Buffalo, I went for Buffalo for the extra 32MB RAM. Others might find the "HP"(High Power) to be useful as well.<br><br>The router was bought on March, shortly after the announcement of OpenWrt and DD-WRT support. Still, as of today, very few documents are available on the G300NH(and other Atheros based routers) so I decided to put this blog to record and share my work. Unknownnoreply@blogger.com18