10

I'm running CentOS 5.3 and want to disable the nf_conntrack module to improve network performance for haproxy. I'm running iptables with some simple rules. I don't really need the connection tracking.

I'm running on Rackspace cloud servers, so I can't run a custom kernel. I've tried running modprobe, but that doesn't work.

[mmarano@w1 w1]$ sudo modprobe -n -r nf_conntrack
FATAL: Module nf_conntrack is in use.

[mmarano@w1 w1]$ uname -a
Linux w1.somewhere.com 2.6.24-23-xen #1 SMP Mon Jan 26 03:09:12 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux
[mmarano@w1 w1]$ cat /etc/redhat-release 
CentOS release 5.3 (Final)

I want to continue to run iptables after ripping this out, so I can't quite ditch all of netfilters. Anyone have any thoughts?

user22277
  • 261
  • 1
  • 2
  • 6

4 Answers4

16
  1. remove any reference to the state module in iptables. So, no rules like

    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

    the state module requires the nf_conntrack (ip_conntrack) module

  2. remove the following line (if it exists) in /etc/sysconfig/iptables-config

    IPTABLES_MODULES="ip_conntrack_netbios_ns"

    That module requires ip_conntrack which we are trying to ditch.

  3. reload iptables without your state rules.

    sudo iptables -F

    # add your real rules

  4. drop the modules. I had to use:

    sudo modprobe -r xt_NOTRACK nf_conntrack_netbios_ns nf_conntrack_ipv4 xt_state

    sudo modprobe -r nf_conntrack

  5. confirm you don't have a reference to /proc/net/nf_conntrack

user22277
  • 261
  • 1
  • 2
  • 6
5
  • What about adding the module to /etc/modprobe.d/blacklist.conf?

  • Have you tried:

    rmmod -f modulename
    

    Although:

           -f --force
              This  option can be extremely dangerous: it has no effect unless
              CONFIG_MODULE_FORCE_UNLOAD was set when the kernel was compiled.
              With  this  option, you can remove modules which are being used,
              or which are not designed to be removed, or have been marked  as
              unsafe (see lsmod(8)).
    
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
4

If you are running Haproxy, you need two types of rules in iptables to disable conntrack in the port 80: ones for the connections from the clients to your balancer and others from your balancer to the backends.

Here is a valid example:

iptables -t raw -I PREROUTING -p tcp --dport 80 -j NOTRACK
iptables -t raw -I PREROUTING -p tcp  --sport 80 -j NOTRACK
iptables -t raw -I OUTPUT -p tcp --dport 80 -j NOTRACK
iptables -t raw -I OUTPUT -p tcp --sport 80 -j NOTRACK
Greg Dubicki
  • 1,191
  • 1
  • 14
  • 30
0

When i do "modprobe -rf xt_state" and "modprobe -rf nf_conntrack_ipv6" it say "FATAL: Module xt_state is in use."(on centos).

"modused" may be useful, it can decrease the usage count of any module: http://www2.informatik.uni-freiburg.de/~danlee/fun/modused/

The key is: service ip6tables stop

and add nf_conntrack, xt_state, iptable_nat, nf_nat, nf_conntrack_ipv4, nf_conntrack_ipv6 into /etc/modprobe.d/blacklist.conf

diyism
  • 161
  • 5