Saturday, May 28, 2011

howto: DHCPD with multiple subnets on the same interface

It took me tons of Google research to figure this out. From a mix of various posts and forums, I was able to piece together how to do this interesting little setup.

The Scenario: You have a DHCP server running on your gateway (or other machine), and you want to segregate different devices to their own subnet. For example, say you have a group of terminals or thin clients you want on one subnet, your VOiP phones on another subnet, and people using laptops on another subnet.
Tools Needed: the ISC DHCP Server.

  • Ubuntu Linux
    • apt-get install isc-dhcp-server
  • Gentoo Linux
    • emerge dhcp

My network is dual-firewalled (at least from the perspective of my Thin Clients). My hardware firewall has a public IP address, and of course a lan address.

  • The lan address of my hardware firewall is with a netmask of
  • The lan address of my Thin Client Server is with a netmask of
  • The Thin Client Server has a SECOND lan address of with a netmask of

Why so many ip addresses you ask?

So here's what we do, we are going to take our VOiP phones, and put them on the subnet, because they dont need any other services (besides DNS and DHCP) off of our server. This well help avoid collisions on the network, and hopefully keep our conversations crisp and clear.

We are then going to take our Thin Clients and again give them their own subnet for the same reason. There is going to be alot of traffic between the clients and server, so we want to avoid disrupting phone the phone service.

The "everyone else" catagory: This could be employee laptops who need no direct interaction with our server (besides DHCP and DNS). But I also wanted them to be on a different subnet than the phone system.

The VOiP Phones get their IP address from the local DHCP server. Since they are then on the same subnet as the firewall, they are good to go. However, the Thin Clients and "Other Devices" are on 2 other subnets each. Therefor, the server has to act as a NAT for those devices if they wish to access the Internet. The IPTABLES rules for the server to make it use Network Address Translation for the 2 subnets on 10.* is no different than normal.
The trick is getting your DHCP server to assign addresses to all these different subnets. Here's the config!


# match the MAC addresses of our VOIP phones
class "voip"    { match if substring (hardware,1,3) = 00:04:f2; }

# match the MAC addresses of our LTSP clients.
class "clients" { match if substring (hardware,1,3) = 00:e0:c5; }

shared-network lan {

        # the phones
        subnet netmask {
                pool {
                        allow members of "voip";
                option routers;
                option domain-name-servers;
                option broadcast-address;
                option subnet-mask;
        # unknown devices / laptops / tables / cellphones
        subnet netmask {
                pool {
                        allow unknown-clients;
                option routers;
                option domain-name-servers;
                option broadcast-address;
                option subnet-mask;

        # Linux Terminals
        subnet netmask {
                pool {
                        allow members of "clients";
                option routers;
                option domain-name-servers;
                option domain-name "";
                option broadcast-address;
                option subnet-mask;

                option root-path "/opt/ltsp/i386";
                if substring( option vendor-class-identifier, 0, 9 ) = "PXEClient" {
                        filename "ltsp/i386/pxelinux.0";
                } else {
                        filename "ltsp/i386/nbi.img";

} # end shared net
Edit 2013-03-19: Tinman has another guide over here with even more advanced features.

Sunday, May 15, 2011

Linux BASH script to encode video for the Motorola Xoom

Just a quick an dirty linux bash script that you can use on the command line to convert any video supported by FFmpeg to your Motorola Xoom running Android OS.

I have this setup as a bash alias in $HOME/.bash_profile. You can of course use it as a stand alone script if that is your preference.

Usage is quite simple: to_xoom <input file> [<destination directory>]
to_xoom /path/to/some_video_file.mkv /tmp/

Then all you have to do is send it to your tablet using ftp, or by mounting it.

        # XOOM screen dimensions
        # set this to the width of your device, in pixels

        if [ -n "$2" ] && [ -d "$2" ]; then
        if [ ! -f "$in" ]; then
                echo "Error: File: $in does not exist."
                return -1

        width="`ffprobe -show_streams \"${in}\" 2>/dev/null \
                | grep width \
                | cut -d'=' -f2`"

        if [ "$width" -gt "$max_width" ]; then

        out="`echo $in | perl -pe '{ s/\..{3,4}$// }'`.mp4"
        if [ $set_dir -eq 1 ]; then
                out="`echo $out | perl -pe '{ s/^.*\/// }'`"

        echo "Converting $in to $out for Xoom playback"
        nice /usr/bin/ffmpeg \
                -i "${in}" \
                -vcodec libx264 \
                -vpre medium -crf 20 \
                -threads 0 -bf 1 \
                -b 20480k \
                -vf scale=${width}:-1 \
                -qscale 3 \
                -acodec libfaac -ab 192k \
                -ac 2 -ar 48000 -f mp4 "${dir}${out}"

        return $?