In working on my new site layout, one thing I was wanting is when there are a lot of results (read, pictures in a particular gallery), is to split the results up into pages. Currently I just have it set to 12 pictures (and the pictures go 4 wide), so after 3 rows, I wanted it to have a link to a new page. I also wanted links to each individual page (this may change in the future when there are too many pictures in one gallery and there ends up being 30 some odd pages, but I will change it when it happens).

So to start out, I will assume you already have some basic things set up with your php document. One would be the correct variables passed through the address bar, another is a database setup with enough rows to have enough results to go into multiple pages.

So we first need to start with an sql query to find out how many results we will be dealing with. This gets us one of the primary numbers we need to start the calculations. In my db, I have a pic table that list all the info for all the pictures with a cell for it to link to the album table. In my address bar it passes the album id, which I then store in the $album variable.

// Specify the maximum amount of results per page, you could add a drop down box where the end-user
// can change it themselves
// Pretty straightforward mysql query
$sql="SELECT count(id) AS count FROM pic WHERE album=$album";
// This is part of the magic. First thing we do is take the amount of results returned ($pic_count['count'])
// and then we divide it by the maximum amount of pics allowed per page.
// Then we run the ceil function on the result which will round the answer up to the next whole number.
// This will give us the total number of pages that all the results will take.

So the above gets us a starting point with the total amount of pages that will display with the results and the maximum number of results we want on a page. The next process is to get the page number that we are currently on. Currently I am just doing this with a $_GET from the address bar (so the address would read index.php?page=2), but I may choose to redo this in the future to be more Search Engine Friendly.

We first need to do some error checking

// Check to make sure a page was passed and it is a number, if not set the page to the first one
if (isset($_GET['page']) && is_numeric($_GET['page']))
// Now we need to verify that the page is within the range of pages that we have, if not set to the first one
if ($cur_page < 1 || $cur_page > $total_page)

Now we need the mysql query that will get us just the results we want for the page. My query is pretty long, so I will be just putting in a simple query that will get you the results you need.

// First we need to get the starting result id, this is simply done by getting the current page minus one
// and then multiplying that by the maximum results you chose.
$start_result = ($cur_page - 1) * $max_pics;
// Next comes the actual query
$sql="SELECT * FROM pic WHERE album=$album LIMIT $start_pic, $max_pics";

Now we need the html code to display the pages and the links to the pages. I haven’t done much in the way of css or making it look nice, but it is still functional.

// First display the mandatory html, along with the current page, and how many total pages there are
echo '
<div class="page_list>
	<p class="show_page">
		Page: ' . $cur_page . ' of ' . $total_page . '
// Now if there is more than one page create the links for the other pages
if ($total_page > 1)
	echo '
	<p class="page_links">';
// Give the first page to start counting to display all the pages upto the total pages
	$page_count = 1;
	while ( $page_count <= $total_page )
// Check and see if the page link being created is the current page, because we don't need a link to the
// current page
		if ( $page_count == $curr_page )
			echo '
			<span style="font-weight: bold;">' . $page_count . '</span>';
// Otherwise create the links for the additional pages and point them back to the current php page
// Make sure you pass all the needed variables that were passed initially
			echo '
			<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $album . '&amp;page=' . $page_count . '">
				' . $page_count . '
// Up the $page_count for the while statement and then close the while statement
// Echo the closing p tag then close the if statement for if there is more than one page
	echo '
// Then close the div for the page info
echo '

I think that is all of the pertinent code out of my page. I will look over this when I get home so I can check and verify this all works properly. Hopefully I won’t have to make any changes.

If you want the quick fix (that worked for me) scroll to the bottom.

I noticed last night at work that 2.7.1 was available to upgrade. So I clicked on the link to upgrade it and it never proceeded past the downloading I figured it might be a problem because of the severe web-browsing restrictions my work has or the possibility of me running IE. I figured I would just do it when I got home. I did think this was kinda weird because I was able to update one of my plugins without a problem.

So I got home and the link still wouldn’t work. I then ssh’ed into my server (hosted with 1&1) and found that multiple copies of the were saved in my wp-contents folder (additional numbers were added before the extension) all at 0 bytes. So my next step was to google the problem. Unfortunately with this being a new release, not much was indexed at that point. I then went onto wordpress’s support forum and found that some people were having the same issue, but no one had posted a response. In one of the threads that I looked at (which ended up being unrelated to my issue) one of the posters had asked if the topic starters host was listed in the Core Update Host Compatibility list that wordpress had put out. I had never even heard of this list, so I figured I would look through it. It showed 1&1 under the “Works with caveats” section. It mentioned that the upgrade fails with PHP4, but works properly in PHP5. I thought I was already using PHP5, but I figured lets give it a shot. The instructions are very simple.

Go to the root of your wordpress installation and edit the .htaccess file (you might have to FTP in and copy the file to your machine and make the changes then upload it back). Add AddType x-mapp-php5 .php to the end of the file (you can put it above the # END WordPress comment if you like, but it won’t matter either way).

Maybe this will make it so I can install plugins through the dashboard (they would always fail before), but I will look into this later.

EDIT: I just checked and I am now able to install plugins through the dashboard.

EDIT2: As others have mentioned in the comments, the WordPress Automatic Upgrade plugin is incompatible with WordPress 2.7+. All the functionality (that I used at least) has been integrated directly into WordPress. As such, I had already disabled mine, but if you have not disabled it, you will run into issues with upgrading. Your best option is to Deactivate the plugin. You can then ftp/ssh in and delete the directory (not necessary, but I see no reason to keep the plugin). After that, you should be able to upgrade without a problem.

UPDATE (20 FEB 2009): The author of the Worpress Automatic Upgrade plugin has released a fix for the incompatibilities with 2.7.1. I am not sure if the plugin has any benefit over the built-in upgrade feature, but the fix should at least fix issues with the upgrade process. More details here.

Also for those of you who can’t find your .htaccess file. Under most webservers, a period (.) at the beginning of a file makes the file hidden, so you need to be able to view hidden files. If it still doesn’t show up, it may not exist. If not you can just create it with your favorite text editor (do not use a file extension), and add the information and upload it to your server.

We all like quests… right?? Well, mine has to do with getting the most out of my battery on my aging laptop. Aging that includes the power-providing battery. I already have a head start on this with my laptop specs. It is a Dell Inspirion 700m. It is also based on the Centrino platform, which was Intel’s first major play into laptop powersaving. Included within are an arsenal of powerful components that use minimal power (at the time).

My specific laptop was based off of the Carmel platform. It includes an Intel Pentium M 1.6GHz processor with variable speeds ranging from 600MHz to 1.6GHz, the Intel 2200BG wireless networking card, and the (unfortunately) low-powered 855 Chipset which includes Intel Extreme Graphics 2. Also included is a 12.1″ widescreen LCD, which I am sure uses less power than some of the larger screens out there.

I already had low power-consumption in mind when I installed Slackware (started with 10.2). I installed cpufreq-utils and cpufreqd which allowed me to adjust my processor speed depending on certain power conditions. I also purchased a larger battery (on this model the battery is in the back, so the larger one extends further out the back). The original was a 4-Cell that provides 2200mAh. I replaced that with an 8-cell that provides 4400mAh of power. When the battery was new it provided a whooping 5 hours of battery life. Sadly batteries will dwindle and the power it is capable of putting out will shorten over time.

So to get to the point of my quest, my goal was to get the maximum life out of my laptop. The reason was that I was getting ready to go on leave. I currently am stationed at Ramstein Air Base in Germany, and flight times back to the states are kinda long. So I wanted to be able to use my laptop for as long as possible while I was flying (partially due to the fact that I can’t sleep on planes, even when assisted with sleep medication). So with the help of Google, I was able to come up with the following.

First things first, I found I needed to re-compile my kernel. This will be distro-specific, due to different distros compiling kernels different ways. Mine will all be based off of Slack 12.1 which is the version I was running at the time. The biggest reason for me, was to included tickless-support, which basically only wakes up the processor when there is something for it to do.

Next was to get a program called PowerTOP (PowerTOP needs certain things built into the kernel, the items needed are listed on their site). It is developed by Intel and is used to show what is causing your processor to wake from its low power state. The other benefit it gives is it will tell you some information on how to use less power, such as disabling Bluetooth, or setting a lower scan rate for your wireless. It provides hotkeys so you can change these directly in the program without exiting. It also provides the actual commands that it uses to change these. This way you can make them into a script (like I did).

Some of the functionality it wants to change may not be beneficial for everyday use of a laptop (like disabling Bluetooth). So if you want some of these to run everytime you run your laptop you could add them to your system startup, which in Slackware is under /etc/rc.d/rc.local (distros vary in their startup procedures, so yours may be different). For other times (like when on a plane and you don’t want any wireless devices running) you can make a specific script for it that you run when needed.

Another tool worth mentioning is laptop-tools. This is a script that will run in the background and whenever the laptop starts using the battery, it automatically will provide powersavings. There is a detailed article about what it does here.

Now come the common sense items. People should realize these, but lets face it… everyone has brain-farts.

  • Dim your laptop screen to the lowest level still viewable. The higher the brightness of your LCD screen, the more power your backlight will consume.
  • Don’t use your CD/DVD drive. It uses a lot of power to spin a disc. Their are plenty of tutorials to convert your dvd’s to a file on your hard drive.
  • Don’t use external devices. Even an external mouse or usb drive will use additional power.
  • Depending on your distro you may want to consider using a different window manager. Some window managers have a lot of programs running in the background that will take up processing power and in turn use more of your battery. While I normally run KDE 4, I use windowmaker when I am trying to save power.
  • Disable 3D acceleration. Again, this will use unnecessary processing power. You can do this in your /etc/X11/xorg.conf file by commenting out the Load dri and glx modules. Just put a # in front of them.
  • Disable any unused services. If you won’t be using your webserver or database software, there is no reason to be running those in the background. You can add any of these to your powersave script.
  • Disable any unused hardware. You can do this by removing the modules. If you won’t be using usb, then remove it. Some of the devices you may want to consider disabling are: firewire, pcmcia slot, bluetooth, wireless, card readers, and more.
  • The more obvious one is, if possible, buy a larger battery. This will be dependent on the laptop, because some laptops do not have any larger batteries available. Worst case, buy a new one to replace your aging battery.

Unfortunately I don’t have an amount of extra life this gave me, but I did lower my wake-ups from idle per second by more than 400 wake-ups. And this is just when I am using KDE4. With switching to windowmaker I was able to lower the total amount to 40-60 wake-ups per second. Granted, when I am running my video player that number does go up, but the lower the number of wake-ups the less power your processor will consume.

I know this is old, but I have loved it for years. I try and share it every so often, just for those who have never seen it before. Today I found the original here on BBspot.


Wednesday  June 14 10:10 PM EDT

Student Suspended Over
Suspected Use of PHP

By Brian Briggs

Topeka, KS – High school sophomore Brett Tyson was suspended today after teachers learned he may be using PHP.

“A teacher overheard him say that he was using PHP, and as part of our Zero-Tolerance policy against drug use, he was immediately suspended. No questions asked,” said Principal Clyde Thurlow.   “We’re not quite sure what PHP is, but we suspect it may be a derivative of PCP, or maybe a new designer drug like GHB.”

php_logoParents are frightened by the discovery of this new menace in their children’s school, and are demanding the school do something.  “We heard that he found out about PHP at school on the internet.  There may even be a PHP web ring operating on school grounds,” said irate parent Carol Blessing.  “School is supposed to be teaching our kids how to read and write.  Not about dangerous drugs like PHP.”

In response to parental demands the school has reconfigured its internet WatchDog software to block access to all internet sites mentioning PHP.  Officials say this should prevent any other students from falling prey like Brett Tyson did.  They have also stepped up locker searches and brought in drug sniffing dogs.

Interviews with students suggested that PHP use is wide spread around the school, but is particularly concentrated in the geeky nerd population.  When contacted by, Brett Tyson said, “I don’t know what the hell is going on dude, but this suspension gives me more time for fraggin’.  Yee haw!”

PHP is a hypertext preprocessor, which sounds very dangerous.  It is believed that many users started by using Perl and moved on to the more powerful PHP.  For more information on how to recognize if your child may be using PHP please visit

It has been a little while since I made an entry, but there is good reason for that. I have been hard at work redesigning my Gallery layout for my picture galleries on My Air Force Life. The main thing I have been pushing for was integration into MySQL. There are obvious benefits of switching to that rather than just having static pages, but that is not the point of this entry.

The reason for this entry is to show how I did the little counter at the bottom of the pages. You know the ones…

Page created in seconds with X queries.

Well I was wanting to figure out how to get this to work on my site. Part of the reason, is I am using my laptop as a testbed, so I want to see how resource intensive some of my queries may be. This is my first time actually developing something with MySQL, rather than editing existing code, and I wasn’t sure that my queries were going to be all that resource friendly.

Well to start since I will be doing many different queries on many different pages, I felt that I needed to create a function in a separate file that I would just include on my other files. I called the file func.query_time.php

Within that file, I had two separate functions. One which will time the query, add it to the total time, and add the amount of queries. The second function is just to display the actual info at the bottom of the pages. I will go through these functions separately, so people understand how they work. But I will have everything all together at the bottom.

So to start out we need to declare the function and we are calling it query.

function query($sql, $querycount, $totaltime)
   if (empty($querycount))
   if (empty($totaltime))

All this does is recieve the query ($sql) and the querycount and totaltime amounts. And if the latter two were not passed when the function was called then it automatically sets them at zero. Next we need to get the time it takes to process the query.

   list($usec, $sec) = explode(' ',microtime());
   $querytime_before = ((float)$usec + (float)$sec);
   // run the query
   $result = mysql_query($sql);
   list($usec, $sec) = explode(' ',microtime());
   $querytime_after = ((float)$usec + (float)$sec);

The first part grabs the time before the query was run and stores it in $querytime_before. Then we actually run the MySQL query, then we get the time again and store it in $querytime_after. Now we need to get the totals of everything.

   $querytime = $querytime_after - $querytime_before;
   $totaltime += $querytime;

The first line take the time before and subtracts it from the time after which gives us the time it takes to make that query. Then we add the $querytime to $totaltime (the += is for adding another variable to the one it will be stored in ie. $totaltime = $totaltime + $querytime;). The last line is to add 1 to the querycount. The final part of this function is to return the info so you can use it on your regular page.

   return array($result, $querycount, $totaltime);

This returns the results back into the orginal file and closes out the function. Now onto the file itself and how you call the query.

Now the first time you call the function “query” there will be no variables set for $querycount or $totaltime, so you can just leave those out, but those variables will be returned. And since they are returned in an array there are a couple of ways to get them out. I prefer the list() function as it is simple and you can name the variables however you want.

   "sql = SELECT * FROM database";
   list($result, $querycount, $totaltime) = query($sql);

So the $sql query we have stored above is being passed to the function on the right, and then it runs through the function and returns us our info. On the second query it is only slightly different.

   $sql = "SELECT * FROM database WHERE id = 1";
   list($result2, $querycount, $totaltime) = query($sql, $querycount, $totaltime);

In this one we need to pass the $querycount and the $totaltime to the function. Otherwise it won’t know the numbers. Also note that you should change the variable for the MySQL query result depending on how your page is setup.

Now we have the displaying of the info. In the func.query_time.php file I had a second function declared. This function is small enough I won’t break it down.

function display_time($querycount, $totaltime)
   $strQueryTime = 'Page created in %01.4f seconds';
   echo '<p class="querytime">' . sprintf($strQueryTime, $totaltime) . ' with ' . $querycount . ' queries.</p>

So the function gets the querycount and totaltime variables passed to it. Then we store the string for the page created in x seconds into $strQueryTime. The %01.4f is used to shorten up the totaltime. Right now it will pad any unused spaces with 0′s and will go four decimal places to the right. We then use the sprintf function to display that with the totaltime added in and then the total number of queries that were counted. All that is left to do is show that on the page. This is done with

display_time ($querycount, $totaltime);

Now to show it all together. First the php file followed by the function file.

  $sql="SELECT * FROM database";
  list($result, $querycount, $totaltime)=query($sql);
  $sql="SELECT * FROM database WHERE id='1'";
  list($result2, $querycount, $totaltime)=query($sql, $querycount, $totaltime);
  display_time($querycount, $totaltime);
function query($sql, $querycount, $totaltime)
  list($usec, $sec) = explode(' ',microtime());
  $querytime_before = ((float)$usec + (float)$sec);
  list($usec, $sec) = explode(' ',microtime());
  $querytime_after = ((float)$usec + (float)$sec);
  $querytime = $querytime_after - $querytime_before;
  $totaltime += $querytime;
  return array($result, $querycount, $totaltime);
function display_time($querycount, $totaltime)
  $strQueryTime = 'Page created in %01.4f seconds';
  echo '<p class="querytime">' . sprintf($strQueryTime, $totaltime) . ' with ' . $querycount . ' queries.</p>';

So there you have it. Any questions or things you believe I could do better, let me know in the comments. And I am sure that there will be more code that I will post before the gallery overhaul is complete. Stay tuned…

I recently had some issues with my DVD+/-RW drive. It is a 16x Sony drive. I was trying to burn DVD’s with it and it would easily take 45 minutes to burn a disc. Normally I can burn a disc within 15 minutes. I just figured it was having issues buffering the content from a shared virtual machine drive. Then I tried watching a DVD movie and it was slowing down my computer severely. Then I tried the DVD disc in my DVD-ROM/CD-RW drive and it played flawlessly. This got me thinking that it was something else entirely, so I checked my device properties for my Master IDE Channel (I only have a master on my motherboard as everything else is SATA). It showed one device using DMA and the other was set to PIO only. Well that is weird. So I switched it to Use DMA if Available. Rebooted and it was still showing PIO mode. I knew that this drive at one point was using DMA, so I initially thought that my drive might be going out.

I did a bunch of digging online, and found that this happens occasionally because of a little-known counter in Windows. It turns out that windows keeps a count of how many times a device’s transfer times out. On hard drive and disc drives that limit is 6 times. I then remembered that I was trying to watch a movie that had a scratch on the disc. I remember trying it multiple times thinking it was a problem with the media playing software I normally use (Smplayer, but that is another topic) due to mplayers issues with certain dvd’s.

So the fix for this is to go into the registry (beware in the registry, I will not be held responsible for any issues you cause). Click on your Start -> Run and type in regedit and hit enter. Then navigate to the key:


Under this key there will be several subkeys. These will be for your various IDE controllers. Go through them and delete MasterIdDataChecksum or SlaveIdDataChecksum, which will depend on whether it is your Master or Slave device. It does not matter if you delete ones that are not having issues, because windows will automatically create them when you reboot. This will reset the counter.

Now there is a way to reduce the probability of you running into this issue again. To do this you will need to create a new DWORD Value. To do this go into one of the subkeys (the 0001 and such) and right click on an empty part or go to click on edit and go to New -> DWORD Value. Type in ResetErrorCountersOnSuccess and hit enter. Now change the value to 1. I did this in all the subkeys that I deleted the above items. What this will do is make it so that those time out errors needs to be consecutive (ie happening without a successful attempt) before it reverts back to PIO. So if you have a problem playing a dvd a couple of times and you try another disc and it works it will reset the counter.

To start… My priority was to get my laptop to work at full capacity. So I immediately worked on building the CPU Frequency Daemon. This required me to build the CPU Frequency Utilities. I built versions 2.2.1 and 003 respectively. I have links for the Slackpacks and the bottom of this page. Once I was finished building these, I had to set up my config file for the daemon.

Below is the pertinent sections out of my config file, although you will want to read through the documentation so you can make sure it is set up the way you want.

name=On Demand High

name=On Demand Low

name=Performance High
#exec_post=echo 8 > /proc/acpi/sony/brightness

name=Powersave Low

# Full Power when plugged in
name=AC Rule
ac=on                    # (on/off)
profile=Performance High

# conservative mode when not AC
name=AC Off - Low Battery
ac=off                   # (on/off)
profile=Powersave Low

# conservative mode when not AC
name=AC Off - Medium Battery
ac=off                   # (on/off)
profile=On Demand Low

# stay in performance mode for the first minutes
name=AC Off - High Power
ac=off                   # (on/off)
profile=On Demand High

I was unable to get the default compiz to run without crashing the system. I then figured I would try to get the newer compiz-fusion (CF) installed. I grabbed some packages from here. Installed everything and went to try to get compiz fusion to run.

compiz --loose-binding  --replace   ccp  &
kde-window-decorator --replace&

fusion-icon &
sleep 10

I put that in my ~/.kde/Autostart directory and restarted KDE. Almost everything seemed to work except for the multiple desktops. Whatever KDE was set to CF would quadruple that number. So if KDE was set for one desktop, CF would show four, but only one would be usable. With the default on Slackware being 4 desktops, with CF it would show 16 desktops. I read quite a few things online to try and fix this and nothing worked. CF isn’t a big deal to me, I mainly wanted it to show off to other people. As such, I didn’t try very hard to fix this.

Now that KDE 4.1 is out, I would love to give it a shot, but so far I have been unable to find any packages that will co-exist with KDE3. One of these days, I may decide to build it all myself, but I have never built a window manager before.

The last big thing for me is to set up the synaptics driver. The mouse still works, but I like the extra features that the synaptics driver provides. I ended up building the with the aid of SlackBuilds, due to the need of a patch to be able to build it with the current xorg. All the files needed were located there. Once I built and installed the driver, my mouse stopped functioning in KDE. After a lot of digging around, I ended up needing to comment out the last line in the file /etc/modprobe.d/psmouse. I think you could probably just delete the file, but that is up to you. Now I just needed to set up the X options so I could use the scroll and the various other options it provides.

Section "InputDevice"

# Identifier and driver

Identifier    "Mouse1"
Driver      "synaptics"
Option     "Device"      "/dev/mouse"
Option    "Protocol"    "ps2"
Option    "LeftEdge"      "1700"
Option    "RightEdge"     "5300"
Option    "TopEdge"       "1700"
Option    "BottomEdge"    "4200"
Option    "FingerLow"    "25"
Option    "FingerHigh"    "30"
Option    "MaxTapTime"    "180"
Option    "MaxTapMove"    "220"
Option    "VertScrollDelta" "100"
Option    "MinSpeed"    "0.09"
Option    "MaxSpeed"    "0.18"
Option    "AccelFactor"    "0.0015"
Option    "SHMConfig"    "on"
#   Option    "Repeater"    "/dev/ps2mouse"


Just make sure you load the synaptics driver in the modules section.

[code]Load "synaptics"[/code]

Now come the various packages.

For the compiz-fusion packages, they can be located here, but you can get them all and install them with these commands:

mkdir compiz-fusion
cd compiz-fusion
wget -rnd
installpkg *tgz

A while ago, I was working on creating a script to create thumbnails of all the pictures I had taken so I could put them up on my personal site for family/friends to view. It started out as a very basic script but as I developed my website, I found new ways to display the photos. Namely using css for the image to come up double sized by mousing over on the picture. Well this created quite a challenge to put all the code for my pictures in the HTML. So I went a step further and adjusted the script to create the php necessary for the galleries. The way I create all my pages is to use a standard header and footer file and include them into my individual pages. So I then changed the script so it created a full blown page ready to be used. The script is below. You may have to modify it slightly for your own needs, but it should work fine. The main requirement is the imagemagick software. In Slackware it is included with the default install. With your own distro you may need to add it yourself.


echo "Resizing Pictures and Creating PHP"
mkdir thumbs previews view
cp ../rhine-river/view.php .
cp ../rhine-river/download.php .


if [ $1 = y ]
for i in *.jpg *.JPG; do

picnum=$(($picnum + 1))

pic=`echo $i | awk -F . '{print $1}'`
rename="${name}-`printf "%03d" $picnum`.jpg"
mv "$i" $rename


for i in *.jpg; do

totalcount=$(($totalcount + 1))


echo "There are $totalcount pictures to convert."

# Create the header
echo \<\?php > index.php
echo \$pagetitle \= \"Insert Title Here\"\; >> index.php
echo include_once\(\"../../includes/header.php\"\)\; >> index.php
echo ?\> >> index.php
echo \
Page Description Here\ >> index.php
echo \

I recently read a blog post on the How-To Geek about setting up OpenDNS and the options it gives you to secure your internet browsing. I have found I love the OpenDNS service and the filtering control it gives me. But I tend to try and fight the system. Rather, I try to figure out ways to bypass the filtering service. This way I can find out ways that others would be able to get around services I set up.

Well OpenDNS is fairly straightforward. You add their DNS Server IP’s to your static IP’s in your router, then any computer behind that router will automatically use those DNS servers. So what if you were to change the DNS servers on your local machine? It would bypass your router for those queries and in turn bypass OpenDNS. This doesn’t cut it for me. It is way to easy to change that, and enough people know how to change their IP settings that this is too unsecure for me. So I did some research online and found an easy way to bypass that. Block port 53 on your router.  Some routers may not have this functionality by default, so I can highly recommend checking out if your router is supported by DD-WRT. They support quite a few routers, and I personally love their firmware.

Since I am running DD-WRT that is what this guide will be based on, but it should apply for any router based on linux that you can have it run your own code.

Once you login into your router, go to Administration -> Commands.
From here you just need to paste this in:

[code]iptables -I FORWARD 1 -p tcp --dport 53 -j DROP; iptables -I FORWARD 2 -p udp --dport 53 -j DROP[/code]

Then at the bottom hit the Run Command button. This should block any attempts for the computer to go to another server to resolve names.

This should apply to any router that uses iptables and allows you to run your own code. This is also able to be done through ssh/telnet if your router supports it.

I recently read a blog post on the How-To Geek about setting up OpenDNS and the options it gives you to secure your internet browsing. They have quite a few filtering options including Phishing sites, along with blocking adult-related sites, and about 50 other categories along with a fully redundant DNS nameserver resolving. I decided to try it and set it up on my home network. The problem is that if you have an internet provider that provides you with a dynamic IP (IP address changes occasionally, if you aren’t sure what you have you probably have a dynamic address), you need to update the IP with OpenDNS. They have a lot of clients out there to do it, but as far as I found there were no linux clients. So I created a short linux script to do just that.


# Copyright (C) 2006 Jeremy Brent Hansen
# These are for your OpenDNS username and password. At this time, I do
# not know how to hide this info, so you will need to make sure you have the
# correct file permissions.

# This is where the log file will be stored. Currently it only logs the current IP
# and the response back from OpenDNS. The log will keep one backup. I
# just used a folder in my home directory (make sure the folder exists).

# Revolves the log file. Keeps one backup.
mv $log_dir/log $log_dir/log.1

while [ 1 ]

date >> $log_dir/log
/usr/bin/curl -i -m 60 -k -u $username:$passwd ‘’ -silent >> $log_dir/log
echo -e “\n” >> $log_dir/log

# Resends the info after 5 minutes. Eventually I plan on changing it,

# so it only updates when your IP changes.
sleep 600


So, there you have it. No root permissions are required, so I just have it in my .profile for my normal user. Just run it with the & at the end, so it will background the process.