Running iperf to your network

Lets think that you have a LAN with a DHCP server and a number of clients (i.e. a computer lab). For whatever reasons you want to test your LAN bandwidth between your server and clients simultaneously. This can be done with iperf which is a standard tool in a typical Linux distribution. In this example we’re using Debian/Ubuntu.

Preparation in the Client Side

Install iperf:

# apt-get install iperf

At this point you might want to decide a port number for iperf clients (which really are servers but running in the clients). In this example we use 6001. To make sure only your DHCP host may execute the tests you may want to allow traffic to port 6001 (both UDP and TCP) only from your host.

Add following line to your /etc/rc.local just above “exit 0”:

start-stop-daemon --start -x /usr/bin/iperf -n iperf -b -- -s --udp -p 6001

This starts the iperf on boot in your client. It sits waiting the server to connect.

Running the Test from the Server Side

In my server I use dnsmasq as a DHCP server. It reports all DHCP activity in /var/log/syslog. In order to get all IP addresses given to the clients after the last logrotate enter following command:

#!/bin/sh

IP_ALL=`grep DHCPACK /var/log/syslog | grep -o -P "\d+\.\d+\.\d+\.\d+"`

# Go through IP_ALL and ping all IPs. Collect online IPs to IP_UP.

for this_ip in $IP_ALL
do
        # Check with PING
        echo -n "pinging: $this_ip   "
        this_count=0
        this_count=$(ping -c 1 $this_ip | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}')

        if [ $this_count -eq 1 ]; then
                # this_ip is up
                IP_UP="$IP_UP $this_ip"
                echo "up"
        else
                echo "down"
        fi
done

# Go through IP_UP and run iperf to them

for this_ip in $IP_UP
do
        echo -n "starting iperf: $this_ip   "
        iperf -c $this_ip -p 6001 -t 10 --udp -b 100k -d -y csv >/tmp/bwtest.csv 2>&1 &
        echo "done"
done

# Wait for iperf processes to end
PROC_COUNT=1
until [ $PROC_COUNT -eq 0 ]
do
        sleep 1
        PROC_COUNT=`ps | grep -c "iperf"`
        echo -n "Processes running: $PROC_COUNT\r"
done

echo ""

Leave a Reply

Your email address will not be published. Required fields are marked *

+ sixty six = 72