В этой записке будет описан процесс установки модуля ipt_netflow на операционную систему CentOS 5. Модуль ipt_netflow быстро и эфективно экспортирует информацию о проходящем трафике в формате Cisco Netflow, работает в ядре Linux. Разработан для Linux роутеров которые испытывают интенсивные тяжелые сетевые нагрзуки (прокачка гигабитного трафика). Если вы пользуетесь сенсорами ulog или ipcad, и они сильно грузят процессор, значить вам пора обратить внимание на ipt_netflow.
Мы будем устанавливать ipt_netflow версии 1.7.1 c iptables 1.3.5
# uname -a
Linux localhost.localdomain 2.6.18-238.19.1.el5.centos.plus #1 SMP Mon Jul 18 10:07:01 EDT 2011 i686 athlon i386 GNU/Linux
# iptables --version
iptables v1.3.5
Скачаем исходники ipt_netflow и iptables/netfilter:
wget http://sourceforge.net/projects/ipt-netflow/files/ipt-netflow/ipt_netflow-1.7.1.tgz/download
wget http://ftp.netfilter.org/pub/iptables/iptables-1.3.5.tar.bz2
Распакуем их:
tar -xvzf ipt_netflow-1.7.1.tgz
tar -xvjf iptables-1.3.5.tar.bz2
Теперь осталось установить ipt_netflow:
cd ipt_netflow-1.7.1
./configure --ipt-ver=1.3.5 --ipt-bin=/sbin/iptables --ipt-src=../iptables-1.3.5 --ipt-lib=/lib/iptables
make all install; depmod
Запуск ipt_netflow на локальной машине:
modprobe ipt_NETFLOW destination=127.0.0.1:5006 debug=1
Автозапуск при старте системы:
gedit /etc/rc.d/rc.local
Вставляем в него строчку:
modprobe ipt_NETFLOW destination=127.0.0.1:5006 debug=1
Получится так:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
modprobe ipt_NETFLOW destination=127.0.0.1:5006 debug=1
Теперь создадим файл (скрипт) правил iptables:
gedit /etc/sysconfig/fw
Впишем в него текст:
#!/bin/bash
# добавляем правила для сбора статистики
iptables -I FORWARD 1 -j NETFLOW
iptables -I INPUT 1 -j NETFLOW
iptables -I OUTPUT 1 -j NETFLOW
Сохраняем файл.
chmod 750 /etc/sysconfig/fw
После открываем файл rc.local который находится в /etc/rc.d/:
gedit /etc/rc.d/rc.local
И вписываем в него строчку (в конец), путь до нашего файла:
/etc/sysconfig/fw
Сохраняем...
Перезагрузим машину:
reboot
Проверка на наличие ipt_netflow в системе:
lsmod | grep ipt_NETFLOW
ipt_NETFLOW 30456 0
x_tables 17349 3 ipt_NETFLOW,iptable_nat,ip_tables
cat /proc/net/stat/ipt_netflow
Flows: active 0 (peak 0 reached 0d0h7m ago), mem 0K
Hash: size 8191 (mem 31K), metric 1.0, 1.0, 1.0, 1.0. MemTraf: 0 pkt, 0 K (pdu 0, 0).
Timeout: active 1800, inactive 15. Maxflows 2000000
Rate: 0 bits/sec, 0 packets/sec; Avg 1 min: 0 bps, 0 pps; 5 min: 0 bps, 0 pps
cpu# stat: <search found new, trunc frag alloc maxflows>, sock: <ok fail cberr, bytes>, traffic: <pkt, bytes>, drop: <pkt, bytes>
Total stat: 0 0 0, 0 0 0 0, sock: 0 0 0, 0 K, traffic: 0, 0 MB, drop: 0, 0 K
sock0: 127.0.0.1:5006, sndbuf 110592, filled 0, peak 0; err: sndbuf reached 0, other 0
iptables -L -n -v | grep NETFLOW
130 15248 NETFLOW all -- * * 0.0.0.0/0 0.0.0.0/0 NETFLOW
0 0 NETFLOW all -- * * 0.0.0.0/0 0.0.0.0/0 NETFLOW
129 15180 NETFLOW all -- * * 0.0.0.0/0 0.0.0.0/0 NETFLOW