Raccogliere il traffico di molti router con nprobe ed ntopng

From RVM Wiki
Jump to navigation Jump to search

Se si vogliono raccogliere dei Netflow da molti router, ci si può scontrare con alcuni limiti, ad esempio:

  • nprobe nella versione PRO, può raccogliere netflow da un massimo di 4 IP
  • ntop nella versione Enterprise L può supportare al massimo 32 interfacce

Per aggirare questi limiti, si adottano diverse strategie:

  • si utilizzano più interfacce di nprobe su porte diverse che vengono servite da regole iptables in base alll'indirizzo ip sorgente del flusso
  • si evita di aggregare il traffico per interfaccia, ma lo si analizza per flow exporter (router) o interfaccia SNMP del router

Configurazione di NTOPNG

Ntopng deve essere configurato con un Collector ZMQ (attenzione alla "c")

vi /etc/ntopng/ntopng.conf.d/ntopng-nprobe.conf 

-i tcp://127.0.0.1:5556c -m 10.0.0.0/8,172.16.0.0./12,192.168.0.0./16

Configurazione dei router

Tutti i router devono essere configurati per inviare i netflow alla porta 9995

Tutti i router devono essere configurati come SNMP devices in NTOPNG, ed eventualmente le loro interfacce arricchite tramite lo script apposito.

Configurazione di nprobe multipli

Si crea un file CSV nel formato:

indirizzo_ip_del_router;porta_istanza_nprobe

Esempio

10.11.12.11;10001
10.11.12.12;10001
10.11.12.13;10001
10.11.12.14;10001
10.11.12.15;10002

Avendo cura di assegnare al massimo 4 ip ad una porta nprobe.

Il seguente script si occupa di leggere il file CSV, creare le regole iptables e le configurazioni di nprobe:

vi /etc/nprobe/nprobe_map.sh
#!/bin/bash

# Flushes NAT table
iptables -t nat -F


INPUT=routers.csv
OLD_PORT="0"
OLDIFS=$IFS
IFS=';'

# Test if csv input file is present
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }

# Read fileds from CSV
while read IP PORT
do
        echo "$IP -> $PORT"
        # Creates iptables rules to redirect flows from router ip to the desires nprobe local instance
        iptables -t nat -A PREROUTING -p udp -i eno12399 --dport 9995 -s $IP -j DNAT --to-destination 172.30.77.216:$PORT

        # Creates nprobe instance config and start it if it does not exist

        if [ "$PORT" -ne "$OLD_PORT" ]
        then
                echo "Create nprobe-${PORT}.conf"
                cat > /etc/nprobe/nprobe-${PORT}.conf <<EOFile
--zmq=tcp://127.0.0.1:5556
-T=@NTOPNG@
-i=none
-n=none
--collector-port=${PORT}
--snmp-mappings /etc/nprobe/snmp_mappings.txt
--zmq-probe-mode
EOFile

                echo "Enable and restart nprobe-${PORT}"
                systemctl daemon-reload
                systemctl enable nprobe@${PORT}
                systemctl restart nprobe@${PORT}
        fi

        OLD_PORT=$PORT
done < $INPUT

IFS=$OLDIFS

# Restart also ntopng. Not needed, but ...

echo "Restart ntopng"
systemctl restart ntopng
  • Verificare che non ci siano errori in ntopng e nelle singole istanze di nprobe:
journalctl -f -u ntopng
journalctl -f -u nprobe@10001

Riferimenti