On Thu, 2003-10-16 at 16:31, Brian Horncastle wrote:
> Just wondering if anyone knows of any good bandwidth monitoring programs for
> Linux?  I'm looking for something that will monitor total incoming and
> outgoing traffic for an interface.  Also, I'm looking preferably for a
> console app.  I don't care about graphing too much, and really don't want to
> put Apache on the box in question.

I myself use one of the most simplest way of monitoring bandwidth: using
the iptables counters. I setup a few rules to log traffic by service so
I know how much bandwidth http, smtp, this that and whatever uses and a
total. All you need is a 2.4 kernel with iptables running.

I've attached the script that I use to set it up and a config file to go
with it (just a list of port numbers used in the for-loop in the
script). Use "iptables -L -v" to see the numbers you'll be interested
in.

Nothing elegant about it, but it serves my purpose and I don't need to
install special software that make it look pretty.

-- 
Gerard Beekmans
http://www.linuxfromscratch.org
http://www.beekmansworld.com

/* Linux Consultant --- OSDN / DevChannel *
 * Technical Writer --- CheapBytes        */

/* If Linux doesn't have the solution, you have the wrong problem */

80
25
6667
873
993
995
119
22
2401
53
#!/bin/bash

cd /root/iptables-bandwidth-logging

case $1 in
	start)
		iptables -N ACCOUNTING
		iptables -A OUTPUT -o eth+ -j ACCOUNTING
		iptables -A INPUT -i eth+ -j ACCOUNTING

		for port in $(cat services); do
			iptables -A INPUT -i eth+ -p tcp \
				--dport $port -j ACCOUNTING
			iptables -A OUTPUT -o eth+ -p tcp \
				--sport $port -j ACCOUNTING
		done

		iptables -A OUTPUT -o eth+ -p tcp \
				--dport 25 -j ACCOUNTING

		iptables -A INPUT -i eth+ -p udp \
				--dport 53 -j ACCOUNTING
		iptables -A OUTPUT -o eth+ -p udp \
				--sport 53 -j ACCOUNTING
	
		;;
	stop)
		iptables -L -v > iptables-$(date +%Y%m%d-%H%M)

		iptables -D OUTPUT -o eth+ -p udp \
				--sport 53 -j ACCOUNTING
		iptables -D INPUT -i eth+ -p udp \
				--dport 53 -j ACCOUNTING

		iptables -D OUTPUT -o eth+ -p tcp \
				--dport 25 -j ACCOUNTING
		
		for port in $(cat services); do
			iptables -D INPUT -i eth+ -p tcp \
				--dport $port -j ACCOUNTING
			iptables -D OUTPUT -o eth+ -p tcp \
				--sport $port -j ACCOUNTING
		done

		iptables -D INPUT -i eth+ -j ACCOUNTING
		iptables -D OUTPUT -o eth+ -j ACCOUNTING
		iptables -X ACCOUNTING
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		;;
esac

Reply via email to