stefankittel
Goto Top

Datenmonitoring nat bei iptables

Hallo,

ich habe hier einen Proxy der mit iptable und NAT funktioniert.
Der Server läuft unter Ubuntu 16.04. LTS. Die Zugriffssteuerung erfolgt über ein Webinterface mit angepassten Shell-Zugriff.

Jetzt möchte ich gerne wissen über welchen NAT hier wieviel Traffic läuft.
Ich bin frei auf dem Server was Software und Zugriffe angeht.

iptables -n -t nat -vL zeigt mir die Regeln.
Leider sind die bytes zähler aber "leer".

Chain PREROUTING (policy ACCEPT 3 packets, 144 bytes)
 pkts bytes target     prot opt in     out     source               destination
    3   156 DNAT       tcp  --  *      *       XXX       XXX       XXX
    2   104 DNAT       tcp  --  *      *       XXX       XXX       XXX
    5   260 DNAT       tcp  --  *      *       XXX       XXX       XXX
    3   156 DNAT       tcp  --  *      *       XXX       XXX       XXX
    2   100 DNAT       tcp  --  *      *       XXX       XXX       XXX
    0     0 DNAT       tcp  --  *      *       XXX       XXX       XXX

Chain INPUT (policy ACCEPT 3 packets, 144 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 24 packets, 1724 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 24 packets, 1724 bytes)
 pkts bytes target     prot opt in     out     source               destination
    3   156 SNAT       tcp  --  *      *       0.0.0.0/0            XXX       XXX
    2   104 SNAT       tcp  --  *      *       0.0.0.0/0            XXX       XXX
    5   260 SNAT       tcp  --  *      *       0.0.0.0/0            XXX       XXX
    3   156 SNAT       tcp  --  *      *       0.0.0.0/0            XXX       XXX
    2   100 SNAT       tcp  --  *      *       0.0.0.0/0            XXX       XXX
    0     0 SNAT       tcp  --  *      *       0.0.0.0/0            XXX       XXX

iptables -L -v -n zeigt mit die Werte, aber ohne NAT zuordnung

Chain INPUT (policy ACCEPT 55817 packets, 6202K bytes)
 pkts bytes target     prot opt in     out     source               destination
  948 59148 f2b-sshd   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            multiport dports 12345

Chain FORWARD (policy ACCEPT 754K packets, 313M bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 49036 packets, 39M bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain f2b-sshd (1 references)
 pkts bytes target     prot opt in     out     source               destination
  948 59148 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Kann mir Jemand sagen wie ich an die Werte pro NAT-Regel komme?

Danke

Stefan

Content-Key: 369278

Url: https://administrator.de/contentid/369278

Printed on: April 25, 2024 at 16:04 o'clock

Member: aqui
aqui Mar 26, 2018 at 18:43:30 (UTC)
Goto Top
Member: brammer
brammer Mar 27, 2018 at 06:12:13 (UTC)
Goto Top
Hallo,

nat:
This table is consulted when a packet that creates a new connection is encountered.

Quelle: http://ipset.netfilter.org/iptables.man.html

Die Option NAT greift nach der Formulierung aber nur bei neuen Verbindungen... nicht bereits bei bestehenden....
Wenn du einmal "iptables -n -t nat -vL" aufrufst und dann einen ping startest und dann den Befehl ein 2. mal aufrufst bleibt dann der Counter auch auf 0?

brammer
Member: StefanKittel
StefanKittel Mar 27, 2018 at 06:41:33 (UTC)
Goto Top
Moin,

Be aware that the nat table is traversed only by the first packet of each connection. The example above is unusual because every outbound packet is considered to be part of a separate connection. For TCP-based protocols you would typically see only a small fraction of the total traffic in the nat table counters.

ich habs geahnt.
Leider handelt es sich hier ausschlieslich um RDP-Verbindungen.
Ich sehe hier also nur den Verbindungsaufbau und nicht den Traffic.

If more detail is needed then the LOG target can be used to record packets in the system log.

Ich werde wohl log-filter verwenden müssen um den Traffic zu zählen.
Die Beispiel in dem Link sind für ICMP. Ich müßte dies aber für TCP mit bekannter IP und Port machen.
Ich schaue mal was ich so finde.

Oder hat Jemand ein "fertiges" Beispiel zum anschauen?

Stefan
Mitglied: 135799
135799 Mar 27, 2018 updated at 07:43:08 (UTC)
Goto Top
Im Link von @aqui steht doch wie du es machen musst, lege einfach Regeln ohne Jump an die deinen jeweiligen Zielhost und Port in der Forward-Chain matcht, dessen Zähler wertest du dann aus.

To achieve this you may need to insert rules purely for the purpose of counting packets. iptables does not have a ‘no operation’ target as such, but you can achieve the same effect by inserting a rule without a target. For example, the following would count the number of ICMP packets to or from the test machine in the scenario above as they enter the FORWARD chain:

iptables -t filter -I FORWARD 1 -p icmp -s 192.168.0.2
iptables -t filter -I FORWARD 2 -p icmp -d 192.168.0.2
Denn alle DSTNAT-Packets passieren ja anschließend immer die Forward-Chain.

Schnuffi