19 Feb 2015
nf_conntrack: table full, dropping packet — A solution for CentOS Dedicated Servers
nf_conntrack: table full, dropping packetThis happens when your IPtables or CSF firewall is tracking too many connections. This can happen when you are being attacked, or is also very likely to happen on a busy server even if there is no malicious activity. Connections will be tracked if you have a firewall rule that does NAT or SNAT, or if you are tracking the number of connections per IP for rate limiting reasons. These scenarios are common either in linux router / firewalls, or in the case of firewall rules that are there for brute force protection / ddos protection.By default, Centos will set this maximum to 65,536 connections. This is enough for lightly loaded servers, but can easily be exhausted on heavily trafficked servers with a lot of firewall rules. On our heavy production servers, we’ve increased this limit to half a million, which has made a big improvement on the amount of workload those servers can handle.It is interesting to note, that the kind of servers most likely to have this problem, are ones where the user has set a lot of strict firewall rules to “help ward off attacks”. Unfortunately, the reality is that the firewall rules themselves are causing the downtime, not any attack! One way to solve the problem is to disable your firewall entirely, but before you go to that extreme, it is worth trying to increase the maximum connections here.In this article, I’ll give you instructions on how to increase the maximum allowed connections for the conntrack connection tracker in Centos. Centos 5 and Centos 6 store the relevant data in different places, so I’ll have instructions for each below. The instructions below assume you’ll be entering commands in an SSH shell / command prompt window:
Table of Contents
Centos 5.x: Increasing maximum connection tracking for nf_conntrack
First of all, you may want to know what the maximum connection limit is alreadycat /proc/sys/net/ipv4/ip_conntrack_maxThis will output the current maximum number of connections that IPtables can track.If you want to see the current number of connections being tracked, you can run the following command:
cat /proc/sys/net/ipv4/netfilter/ip_conntrack_countYou’ll be given a number of connections here. If this number is more than 20% of the maximum, it’s probably a good idea to increase the maximum.If you want to temporarily increase this to a half million, enter the following:
echo 524288 > /proc/sys/net/ipv4/ip_conntrack_maxAnd if you’d like the change to persist across reboots, you’ll need to edit the following file:
nano /etc/rc.d/rc.localCopy / paste the following line to the end of the file, and then save your changes:
echo 524288 > /proc/sys/net/ipv4/ip_conntrack_maxThat’s all there is to it. On heavily trafficked servers, it’s not unusual to see 100k – 200k connections being tracked even if there is no malicious activity. 500k should be a safe maximum, but if you really need to you could increase this further.
Centos 6.x: Increasing maximum connection tracking for nf_conntrack
On Centos 6, the general idea is the same as Centos 5, but the file locations are slightly different.To view the current maximum configured connections, run:cat /proc/sys/net/netfilter/nf_conntrack_maxTo see the current used connections, run:
cat /proc/sys/net/netfilter/nf_conntrack_countTo temporarily increase this to a half million, run:
echo 524288 > /proc/sys/net/netfilter/nf_conntrack_maxTo make this change persist after a reboot, you’ll need to edit the following file:
nano /etc/rc.d/rc.localAnd copy and paste the following line to the end of the file, and then save your changes:
echo 524288 > /proc/sys/net/netfilter/nf_conntrack_maxThat’s it. You should be in good shape now. Just like in Centos 5, on heavily trafficked servers, it’s not unusual to see 100k – 200k connections being tracked even if there is no malicious activity. Therefore, 500k should be a safe maximum, but if you really need to you could increase this further.
The reason we have Centos instructions above is because we’re most familiar with Centos, using it for most of our internal systems. I understand that a lot of other people prefer Ubuntu or Debian. We don’t want to leave those folks out in the cold here, we just aren’t familiar with this fix for those OS’s. If you have any instructions on doing the same for Ubuntu, Debian, or other Linux distributions, please share them with us by emailing sales [at] ioflood.com. If you do send that along, we will be glad to post an update with that information, and also credit your contribution if you’d like.