Search code examples
linux-kerneliptables

Conntrack on single interface - is it possible?


I want to use conntrack to track per-connection bytes, packets etc. on an end-host with a single network interface, rather than connections through a router with multiple interfaces. That means I will track only connections which terminate on the host.

I have set up conntrack on multiple linux distributions, and the answer to conntrack -L is always the same: "0 flow entries have been shown".

Is there any way of tracking per-connection stats in this way using with conntrack or something else on a Linux end-host?


Solution

  • Conntrack will be the best way as it stores tuple for each connection. Moreover load the necessary conntrack module in /lib/modules/xxx/kernel/net/netfilter/yyy.ko and /lib/modules/kernel/xxx/net/ipv4/netfilter/yyyy.ko Though you want connection as you PC as end point Conntrack tool will work if the necessary conntrack module is installed.

    Another approach will be write a kernel module and hook it at PRE-ROUTING as you want to catch as end-point and parse the skbs to fullfill you requirements.