NOTE: I no longer use DD-WRT and am unable to answer any questions about it.
Expanding on my last post of setting up a static page, this post will create dynamic content (albeit at boot time) to be served statically using the embedded HTTP server in DD-WRT.
For small home networks with a mix of leased and non-leased IP addresses, it is sometimes useful to see all of the allocated addresses at one time. Or maybe you can’t remember the name of a device in which name lookup does you no good. You can use this method to create a static web page that has both hosts you define with static addresses, and hosts with dynamic addresses assigned by the DD-WRT DHCP server. Of the latter, it will include DHCP addresses that have reservations.
Why separate the static addresses from the reserved DHCP addresses?
- I assign hardware devices like printers, set top boxes, and game consoles with static addresses. Set and forget, almost. I use a range of address outside of the DHCP pool for this purpose and I keep track of it on a spreadsheet. These devices should never have to change, ever, so I don’t need them managed by DHCP.
- I have two ranges with a single DHCP pool for two different purposes. The first is the equipment in our family; laptops, phones, etc. I want these in the first range. I want them to grab DNS and gateway information from the router as well as their address so I don’t have to maintain them at each device, but I also want them to have the same IP at each boot, so I set them up with reservations in DHCP (within the first range). The second range is for guest equipment (visitors phones, etc). I apply two different QOS (quality of service) settings to these ranges. If you’re a guest, you get no P2P and your traffic has the lowest priority on my network. Sorry.
End Result
What you’ll end up with is a web page that has two panes. One pane shows all the static addresses you create, the other pane shows all the DHCP leases (at router boot time). You will access it by entering the following URL into your device’s browser: “http://router_address/user/hosts.html”. If you have setup the router so that DNSmasq resolves local DNS names, you can substitute the router address for its name on the network – I covered that in an earlier post here. This is what the web page will look like when complete:
It’s simple, small, and fast. You can customize the headers, footers, and titles to be as pleasing as you want. Keep in mind the HTTP server doesn’t have all the bells and whistles you would normally have.
Setup, File Creation
First you need to create a hosts file containing the entries for the statically assigned (not reserved DHCP). These are the printers, set top boxes, game consoles, etc. Devices that don’t leave the house and have no reason to ever change.
- Login to the router as the administrator.
- Change directory to /jffs/www: “cd /jffs/www”
- Create the hosts file with vi: “vi hosts”. The syntax is IP address, tab, device name, device name alias. The content will be similar to this:
192.168.56.20 dsnas nas
192.168.56.40 wii
192.168.56.41 xbox
192.168.56.60 zinohd bluray dvd
192.168.56.70 mg6120 printer
- Create the file that will be served by the HTTP server (hosts.html). This will use a frame set, yes I know it can be done with CSS but I was keeping this pure HTML. Still in the “/jffs/www” directory, using vi: “vi hosts.html”:
<!--DOCTYPE html>
<html>
<frameset cols="50%,50%">
<frame src="hoststat.html" />
<frame src="hostdhcp.html" />
</frameset>
</html>
- Create a header stub file (“hosts_head.html”) which will be used in the dynamic creation of the pages contents. In the same directory “/jffs/www”, again using vi: “vi hosts_head.html”:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" />
<title>DNS Hosts - home</title>
</head>
<body>
- Create a footer stub file (“hosts_foot.html”) which will be used in the dynamic creation of the pages contents. In the same directory “/jffs/www”, again using vi: “vi hosts_foot.html”:
</code>
</body>
</html>
- Create the Static pane’s title file (“hosts_title_stat.html”). In the same directory “/jffs/www”, again using vi: “vi hosts_title_stat.html”:
<h3>DNS Hosts (Static) - home</h3>
<code>
- Create the DHCP (leased) pane’s title file (“hosts_title_dhcp.html”). In the same directory “/jffs/www”, again using vi: “vi hosts_title_dhcp.html”:
<h3>DNS Hosts (Leased) - home</h3>
<code>
Setup, Activation
- Now the router has to be told to create the pages at boot. You will utilize the boot script to do it. If you already have one, append this to it. If you don’t have one, create it. In the directory “/jffs/bin”, again using vi: “vi boot_set.sh”:
# Setup DNS Host web page
# Copy the hosts.html file from /jffs/www to the serving location /tmp/www
cp /jffs/www/hosts.html /tmp/www/hosts.html
# Setup DNS Static web page frame
# Copy the header to a new file in /tmp/www as hoststat.html.
cp /jffs/www/hosts_head.html /tmp/www/hoststat.html
# Concatenate the title stub onto the new file.
cat /jffs/www/hosts_title_stat.html >> /tmp/www/hoststat.html
# Parse the contents of the hosts file you created above into the new file.
while read line; do
echo "${line}
" >> /tmp/www/hoststat.html
done < /jffs/etc/hosts
# Concatenate the footer stub onto the new file
cat /jffs/www/hosts_foot.html >> /tmp/www/hoststat.html
# Setup DNS Leased web page frame
# Copy the header to a new file in /tmp/www as hostdhcp.html.
cp /jffs/www/hosts_head.html /tmp/www/hostdhcp.html
# Concatenate the title stub onto the new file.
cat /jffs/www/hosts_title_dhcp.html >> /tmp/www/hostdhcp.html
# Parse the contents of the hosts file generated by DNSmasq into the new file.
while read line; do
echo "${line}
" >> /tmp/www/hostdhcp.html
done < /tmp/hosts
# Concatenate the footer stub onto the new file
cat /jffs/www/hosts_foot.html >> /tmp/www/hostdhcp.html
- If you have just created the boot script, you need to tell DD-WRT to use it. I showed you how in a previous post here.
- Reboot the router so it will go through the file generation steps.
That’s all there is to it. Enjoy!