Internet @ Meetings: Checking The Number of Leases A DHCP Server Gives Out

The project on Internet connection sharing over cellular networks during meetings I reported on in two previous posts is not quite over yet and I've been working on refining my setup ever since. One thing that often goes wrong in non-optimized hardware setups is the number of devices the built-in DHCP server can give out IP addresses to. In many home grown routers this is actually quite limited, even if the DHCP server range can be specified from .1 to .254. To find out exactly where the limit is, here's a script I've came up with that can be run under Linux and will send 268 requests to the DHCP server, each with a different Ethernet hardware address. Some routers stop giving out IP addresses after 50 leases, some after 60 and only few go to the full range.

#!/bin/bash

for l in {1..99}
do
  sudo ifconfig eth0 down
  sudo ifconfig eth0 hw ether 70:00:00:00:00:$l
  sudo dhclient -r
  sleep 2
  sudo ifconfig eth0 up
  sudo dhclient
  sleep 3
  echo $l " "
  ifconfig | grep "inet addr:192.168."
  ifconfig | grep "HWaddr"
done

for l in {1..99}
do
  sudo ifconfig eth0 down
  sudo ifconfig eth0 hw ether 70:00:00:00:01:$l
  sudo dhclient -r
  sleep 2
  sudo ifconfig eth0 up
  sudo dhclient
  sleep 3
  echo $l " "
  ifconfig | grep "inet addr:192.168."
  ifconfig | grep "HWaddr"
done

for l in {1..70}
do
  sudo ifconfig eth0 down
  sudo ifconfig eth0 hw ether 70:00:00:00:02:$l
  sudo dhclient -r
  sleep 2
  sudo ifconfig eth0 up
  sudo dhclient
  sleep 3
  echo $l " "
  ifconfig | grep "inet addr:192.168."
  ifconfig | grep "HWaddr"
done

Note: Only run this script on your own setup that you can reset afterwards as once the script is through the DHCP server won't give out further IP addresses. Something you don't want to have in a life network…