diff options
Diffstat (limited to 'contrib/ipchains')
| -rw-r--r-- | contrib/ipchains/README | 61 | ||||
| -rwxr-xr-x | contrib/ipchains/ipchainacc | 97 | ||||
| -rwxr-xr-x | contrib/ipchains/ipchainacc.rules | 36 |
3 files changed, 194 insertions, 0 deletions
diff --git a/contrib/ipchains/README b/contrib/ipchains/README new file mode 100644 index 0000000..170489a --- /dev/null +++ b/contrib/ipchains/README @@ -0,0 +1,61 @@ +ipchainacc 1.1.0 + +Author: John Lange john@darkcore.net +Date : September 12, 2000 + +ipchains accounting script for use with MRTG + +*** New in this version *** +*** please read before *** +*** using this script *** + +*** +In version 1.0.1, the script is actually counting packets, NOT bytes as +was intended. I apologize for this mistake. + +By default, this new version of the script also counts packets NOT bytes. +I've done this to maintain compatibility with the previous (buggy) version +so that people who blindly upgrade won't suddenly find all of their output +out of whack. + +To change to counting bytes, please edit the ipchainacc script. +*** + +In order for this script to work: + +1) +You need a kernel which was compiled with the configuration option +CONFIG_IP_FIREWALL set to y. You also need the front end to ip firewall and +ip accounting, that is, the tool 'ipchains'. I used version 1.3.9. + +2) +Add input and output rules to ipchains for accounting. I've included the +small script ipchainacc.rules. If you run it, it will do what it needs for +ipchains to work with this script. I recommend you have a look at it before +running it. It shouldn't break anything because it just adds some empty +rules at the top of the input and output chains for accounting purposes. One +concern however is that these rules have to be first on the chains to work. +If you have some bad IPs black-holed these rules will still count packets +from them which might be bad for server load. + +2) +edit the script ipchainacc for your system. You only need give it the path +to ipchains and hostname. Alternatively, you can just remove the call to +hostname and assign it manually. + +The ipchainacc script can also be run from the console if you want to see the output. + +3) edit your mrtg.cfg for your system. For this script to be incorperated +into mrtg, you need only add the following line to mrtg.cfg: + +Target[ipchains]: `/sbin/ipchainacc` + +4) set mrtg to run as a cron (see the mrtg docs) + +------ +NOTE: this script is very basic. It captures accounting information for +EVERYTHING coming in and out of your machine on all interfaces and IPs. + +If you need to narrow the accounting rules, you will have to edit the +ipchainacc.rules script. I've included a very simple example in that script +on how to narrow the accounting but it remains untested. diff --git a/contrib/ipchains/ipchainacc b/contrib/ipchains/ipchainacc new file mode 100755 index 0000000..db7862e --- /dev/null +++ b/contrib/ipchains/ipchainacc @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +# ipchainacc version 1.1.0 +# Author: John Lange, john@darkcore.net +# Date: September 12, 2000 +# +# This script was written to provide output for MRTG +# (multi router traffic grapher) via ipchains. +# +# http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html +# +## Changelog +# Sept 12, 2000 +# v1.1.0 added flag for selection of graphing either packets, or bytes. +# The default is packets (which is pretty useless), but since +# the previous releases were graphing packets I kept the default +# the same. +# I always meant for this to be bytes but I only recently noticed +# this bug so I added a config flag for bytes. +# Also changed the uptime slightly, but its still broken. When +# goes past 99 days, it will hack the last digit off (used to happen +# after 9 days) +# +# June 22, 2000 +# v1.0.1 added -x to ipchains to expand byte counters +# +# v1.0.0 Inital Release +# +# +# This command must return 4 lines of output: +# Line 1 : current state of the 'incoming bytes counter' +# Line 2 : current state of the 'outgoing bytes counter' +# Line 3 : string, telling the uptime of the target. +# Line 4 : string, telling the name of the target. + +# This script relies on you having setup your ipchains rules beforehand + +#--- sample ipchains rules that will work with this script +## Add some empty rules for accounting purposes only +# +#/sbin/ipchains -F acctin +#/sbin/ipchains -F acctout +# +## add the new rules +#/sbin/ipchains -N acctin +#/sbin/ipchains -N acctout +# +## empty rules on the chains +#/sbin/ipchains -A acctin +#/sbin/ipchains -A acctout +# +#/sbin/ipchains -I input -j acctin +#/sbin/ipchains -I output -j acctout +#----------- end --------------- + +## edit for your system + +$ipchains='/sbin/ipchains'; # path to ipchains +$host=`/bin/hostname --fqdn`; # local hostname (for information only) + +# if you use the ipchains rules above, you don't have to change these +$inrule='acctin'; # name of input accounting rule +$outrule='acctout'; # name of output accounting rule + +# What should we graph? packet counters = 0, bytes = 1 +# If you used this script before and you want to keep counting +# packets, then set this to 0. If you would rather do the +# sensible thing and count bytes, then set this to 1. If you change +# from one to the other, then you should delete all the previous +# history since it will be meaningless. +$bytec=0; + +## -- don't edit below here ---- + +# fetch the status from ipchains +$_=`$ipchains -L $inrule -v -n -x |grep -v -i Chain |grep -v -i pkts`; +@in_bytes = split; +printf "$in_line"; # just for debugging + +$_=`$ipchains -L $outrule -v -n -x |grep -v -i Chain |grep -v -i pkts`; +@out_bytes = split; +printf "$out_line"; # just for debugging + +#$c=1; +#foreach $value (@in_bytes) { +# printf "$c: $value\n"; +# $c++; +#}; + +# uptime of the machine +open(UPTIME,"uptime |cut -b 13-27|"); +$upTime=<UPTIME>; +close(UPTIME); +chop $upTime; + +# 4 lines of output only. +printf "$in_bytes[$bytec]\n$out_bytes[$bytec]\n$upTime\n$host"; diff --git a/contrib/ipchains/ipchainacc.rules b/contrib/ipchains/ipchainacc.rules new file mode 100755 index 0000000..3be5f63 --- /dev/null +++ b/contrib/ipchains/ipchainacc.rules @@ -0,0 +1,36 @@ +#!/bin/bash + +#--- sample ipchains rules for accounting + +# Flush the rules in case they exist already +/sbin/ipchains -F acctin +/sbin/ipchains -F acctout + +# add the new rule chains +/sbin/ipchains -N acctin +/sbin/ipchains -N acctout + +# add empty rules to the new chains just for accounting +/sbin/ipchains -A acctin +/sbin/ipchains -A acctout + +# insert rules into the input and output streams. +# Packets will first pass through these rules before +# returning to the other rules in the chains +# You might not want this if you are trying to +# completely ignore certain hosts. +/sbin/ipchains -I input -j acctin +/sbin/ipchains -I output -j acctout + +# if you wanted to narrow the accouting to a single IP +# you could do these lines instead of the above 2 (not tested) +# (assuming your IP address was 192.168.1.1) +#/sbin/ipchains -I input -d 192.168.1.1 -j acctin +#/sbin/ipchains -I output -s 192.168.1.1 -j acctout + +# By changing the rules, you can make it filter only exactly +# what you want as long as it jumps to acctin, or acctout. +# Be careful not to double count packets though. + +#----------- end --------------- + |
