file path:/etc/sysctl.conf
Centos5 System
[email protected] ~]# vi/etc/sysctl.conf
Net.ipv4.tcp_fin_timeout = 2
(By default ,TCP remains in fin-wait-2 for socket connections that are disconnected at the end of the The time of the state. The other person may be disconnected or never end the connection or the unpredictable process dies)
Net.ipv4.tcp_tw_reuse = 1
(the default value of 0indicates whether to allow the time-wait State of the socket to be re-applied to the new TCP Connection, which is very helpful for quickly restarting certain services, and prompting the port to be used after startup)
Net.ipv4.tcp_tw_recycle = 1
(the default value of 0, turn on quick ttime-wait sockets recycling.) Please do not change this value unless you are advised or requested by a technical expert , and it is recommended to open it when doing NAT .
Net.ipv4.tcp_syncookies = 1
(the default value of 0 will only take effect if Config_syncookies isselected at kernel compilation time .) send syncookiesto the other when there is a syn wait queue overflow toprevent syn flood attacks)
Net.ipv4.tcp_keepalive_time =600
(the default value , 7200,is the time interval forTCP to send keeplive probe messages to confirm that the TCP Whether the connection is valid to prevent an attack on both sides to establish a connection but not send data
Net.ipv4.ip_local_port_range = 4000 65000
(the default value , 32765 61000, indicates the port range used for outward connection, the default is small, and this range is also introduced for NAT table scale)
Net.ipv4.tcp_max_syn_backlog = 16384
(Default value1024, the maximum number that needs to be saved in the queue for connection requests that still do not have a client acknowledgement. For more than128Mbmemory system, the default value is1024x768, below128Mbis the.if the server is overloaded frequently, try increasing this number. Warning!If you set this value to be greater than1024x768, it is best to modifyInclude/net/tcp.hinside thetcp_synq_hsize, to maintaintcp_synq_hsize*16(SYN FloodAttack UtilizationTCPthe agreement spreads the flaw of the handshake and forges the false sourceIPaddress sends a large number ofTcp-synsemi-open connection to the target system. In order to cope with this attack, modernUinxMulti-connection queue processing is widely used in the system to buffer (rather than resolve) this attack, is a song basic queue processing normal full-connected applications (Connect() andAccept()), which is a semi-open connection that is stored separately with another queue. This dual-queue approach and some other system kernel measures, such assyn-cookies/caches) can be used in combination to mitigate small-scaleSYN Floodattack (proof of fact)
Net.ipv4.tcp_max_tw_buckets = 36000
(the default value is 18000, the maximum number of timewait sockets that thesystem handles at the same time .) If this number is exceeded,the time-wait socket is immediately removed and a warning message is displayed, so that this limit is set purely to protect against simple Dos attack, however, if the network condition needs to be more than the default value, you can increase it (and perhaps increase the memory) (in fact, it is best to increase the value appropriately when doing NAT ))
Net.ipv4.route.gc_timeout = 100
(default value ,route cache refresh frequency, how long it takes to jump to another route after a route fails)
Net.ipv4.tcp_syn_retries = 1
(the default value of 5, for a new connection, how many syn connection requests the kernel sends to decide to discard, should not be greater than 255, the default value is 5 , which corresponds to A time of about three seconds, this value is high and can be modified to 2 for a network with good physical communication for large loads . This value is only for external connections, for incoming connections, is determined by tcp_retries1 )
Net.ipv4.tcp_synack_retries = 1
(the default value is 5, for a remote connection request syn, the kernel sends a syn+ack datagram to confirm receipt of the previous syn The connection request package. This is the second step of the so-called three-time handshake mechanism. This determines the number of Syn+ack that the kernel sends before discarding the connection , which should not be greater than 255, the default value of 5, corresponding to 189 seconds or so time)
Net.core.somaxconn = 16384
(Default value128To limit the monitoring (LISTENThe number of maximum packets in a queue that exceeds this number can cause the connection to time out or trigger a retransmission mechanism. Webin ApplicationListenof the functionBacklogThe default will give us the kernel parametersNet.core.somaxconnrestricted to -, whileNginxdefined byNgx_listen_backlogdefault is511, so it is necessary to adjust this value. For busy servers, increase this value to help network performance)
Net.core.netdev_max_backlog = 16384
(the default is the maximum number of packets that areallowed to be sent to the queue when each network interface receives a packet at a rate that is faster than the kernel processes the packet rate, which needs to be increased for heavy-duty servers)
Net.ipv4.tcp_max_orphans = 16384
8192tcp sockets Maximum number. If this number is exceeded, then links that are not part of any process are immediately reset dos attack, Don't rely on this or artificially reduce the limit. This value should be increased if the memory is large. (This value is redhat as version set to Span style= "FONT-FAMILY:CALIBRI;" >32768
# Once the parameters are optimized for the iptables Firewall, the firewall does not have a meeting hint and can be ignored.
Net.ipv4.ip_conntrack_max = 25000000
(the default value is 65536, the maximum number of IPv4 links supported by the system, the default 65536(This is also the theoretical maximum in real time), and this value is related to your memory size, If the memory is 128M, the value of the maximum 8192,1g is the default 65536, this value is affected by / Proc/sys/net/ipv4/ip_conntrack_max limit)
Net.ipv4.netfilter.ip_conntrack_max = 25000000
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180
(the default value is 432000, the time-out ofthe established TCP link, the default 432000, which is 5 days, Impact: This value is too large to cause some potentially unused links to reside in memory, consuming a significant number of linked resources, which could lead to NAT ip_conntrack:table full issues. Recommendation: when the Nat load is tight relative to the native Nat table size, you may want to consider narrowing this value to clear the connection as early as possible to ensure that the connection resources are available. If not tense, do not need to modify)
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120
(default ,time_wait Status time-out, which clears the connection over that time)
Net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60
(default value ,close_wait State Timeout, which clears the connection over that time)
net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120
(default ,fin_wait Status time-out, which is clear when the connection is over)
[email protected] ~]# Sysctl–p # make the configuration file effective
since the module name in the CENTOS6 system is not ip_conntrack, but nf_conntrack, etc/sysctl.conf optimization, you need to Net.ipv4.netfilter.ip_conntrack_max This old parameter, change to Net.netfilter.nf_conntrack_max , that's it.
Centos6
Net.nf_conntrack_max = 25000000
Net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
Net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
Linux kernel tuning