1. 程式人生 > >Linux下nf_conntrack(最全面)

Linux下nf_conntrack(最全面)

總結如下:

dmesg |grep nf_conntrack

連線跟蹤表nf_conntrack:如果輸出值中有“nf_conntrack: table full, dropping packet”,說明伺服器nf_conntrack表已經被打滿

如果伺服器上跑著iptables,必須使用的情況下:

1:高併發伺服器核心調整(8核16G為例,不懂請自行百度):

net.nf_conntrack_max = 8388608

net.netfilter.nf_conntrack_generic_timeout = 120

net.netfilter.nf_conntrack_tcp_timeout_established = 54000


模版:

net.ipv4.ip_forward = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

net.bridge.bridge-nf-call-ip6tables = 0

net.bridge.bridge-nf-call-iptables = 0

net.bridge.bridge-nf-call-arptables = 0

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

vm.swappiness = 0

net.ipv4.tcp_fin_timeout = 10

net.ipv4.tcp_keepalive_time = 1200

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.neigh.default.gc_stale_time=120

net.ipv4.conf.all.rp_filter=0

net.ipv4.conf.default.rp_filter=0

net.ipv4.conf.default.arp_announce = 2

net.ipv4.conf.all.arp_announce=2

net.ipv4.tcp_max_tw_buckets = 90000

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_max_syn_backlog = 2048

net.ipv4.tcp_synack_retries = 2

net.ipv4.conf.lo.arp_announce=2

net.nf_conntrack_max = 8388608

net.netfilter.nf_conntrack_generic_timeout = 120

net.netfilter.nf_conntrack_tcp_timeout_established = 54000

其他:

net.ipv4.ip_local_port_range = 10000 65000

net.core.somaxconn = 262144


同時增加iptables規則(80埠為例):

*raw表下:

-A PREROUTING -p tcp -m tcp --dport 80 -j NOTRACK

-A OUTPUT -p tcp -m tcp --sport 80 -j NOTRACK

-A PREROUTING -p tcp -m tcp --sport 80    -j NOTRACK

-A OUTPUT -p tcp -m tcp --dport 80    -j NOTRACK

同時修改iptables配置檔案

vim /etc/sysconfig/iptables-config 

IPTABLES_MODULES_UNLOAD="no"


二:這種方法比較徹底:直接解除安裝模組