iptables ip_conntrack_max

iptables ip_conntrack_max

1、what

允许的最大跟踪连接条目

-允许的最大跟踪连接条目:CONNTRACK_MAX(默认值是 2^16=65536

-存储跟踪连接条目列表的哈西表的大小:HASHSIZE

-每个哈西表的条目(叫一个bucket),包含了一个链接起来的跟踪连接条目

-哈希表大小HASHSIZE,表现为 条目bucket的多少,在iptables启动时在日志中会显示。

First of all, let us see what IP_CONNTRACK is. It is nothing but the number of sessions that can be handled simultaneously by netfilter in kernel memory.

ip_conntrack_max计算公式:

CONNTRACK_MAX = RAMSIZE (in bytes) / 16384 / (x / 32)

这里x是指针的bit数,(例如,32或者64bit

通常,CONNTRACK_MAX = HASHSIZE * 8。这意味着每个链接的列表平均包含8conntrack的条目(在优化的情况并且CONNTRACK_MAX达到的情况下),每个链接的列表就是一个哈西表条目(一个桶)。

Linux kernel 2.4.23版本前,使用:

# cat /proc/sys/net/ipv4/ip_conntrack_max

Linux kernel 2.4.23版本后,使用:

# cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max

对于linux内核2.4.24以后,当前的HASHSIZE值可以在运行时使用下面的命令读取:

# cat /proc/sys/net/ipv4/netfilter/ip_conntrack_buckets

2、how

# vi /etc/sysctl.conf

# Append this line

>> net.ipv4.ip_conntrack_max = CONNTRACK_MAX

where,

CONNTRACK_MAX = RAMSIZE (in bytes) / 16384 / (x / 32)

where x is the number of bits in a pointer (for example, 32 or 64 bits).

To save the changes quit the editor and execute the command:

# sysctl -p

原文

[1]http://hi.baidu.com/dreamcast_sh/item/b378d6e04b83b9f42a09a4b5

[2]http://blog.sina.com.cn/s/blog_4078ccd601012crx.html

[3]http://wiki.khnet.info/index.php/Conntrack_tuning

[4]http://www.webhostrepo.com/blog/how_to_increase_ip_conntrack_value

原文地址:https://www.cnblogs.com/mydomain/p/3077027.html