So, this is a neat question.
Initially, I was surprised that you saw any connections in SYN_RECV state with SYN cookies enabled. The beauty of SYN cookies is that you can statelessly participate in the in TCP 3-way handshake as a server using cryptography, so I would expect the server not to represent half-open connections at all because that would be the very same state that isn't being kept.
In fact, a quick peek at the source (tcp_ipv4.c) shows interesting information about how the kernel implements SYN cookies. Essentially, despite turning them on, the kernel behaves as it would normally until its queue of pending connections is full. This explains your existing list of connections in SYN_RECV state.
Only when the queue of pending connections is full, AND another SYN packet (connection attempt) is received, AND it has been more than a minute since the last warning message, does the kernel send the warning message you have seen ("sending cookies"). SYN cookies are sent even when the warning message isn't; the warning message is just to give you a heads up that the issue hasn't gone away.
Put another way, if you turn off SYN cookies, the message will go away. That is only going to work out for you if you are no longer being SYN flooded.
To address some of the other things you've done:
net.ipv4.tcp_synack_retries
:
- Increasing this won't have any positive effect for those incoming connections that are spoofed, nor for any that receive a SYN cookie instead of server-side state (no retries for them either).
- For incoming spoofed connections, increasing this increases the number of packets you send to a fake address, and possibly the amount of time that that spoofed address stays in your connection table (this could be a significant negative effect).
- Under normal load / number of incoming connections, the higher this is, the more likely you are to quickly / successfully complete connections over links that drop packets. There are diminishing returns for increasing this.
net.ipv4.tcp_syn_retries
: Changing this cannot have any effect on inbound connections (it only affects outbound connections)
The other variables you mention I haven't researched, but I suspect the answers to your question are pretty much right here.
If you aren't being SYN flooded and the machine is responsive to non-HTTP connections (e.g. SSH) I think there is probably a network problem, and you should have a network engineer help you look at it. If the machine is generally unresponsive even when you aren't being SYN flooded, it sounds like a serious load problem if it affects the creation of TCP connections (pretty low level and resource non-intensive)
Try to tune down this one:
net.ipv4.tcp_keepalive_time = 7200
Something like
net.ipv4.tcp_keepalive_time = 600
should be a lot better for your situation.
Also, make sure you have tuned the local port range. By default in most distros it's
net.ipv4.ip_local_port_range = 32768 61000
Something like
net.ipv4.ip_local_port_range = 1025 65534
should work lot better.
Best Answer
Iptables can log connections or if you prefer you can use the
--tcp-flags SYN
option to match syn packets.netstat
can show active connections (pipe towc -l
for counts):Or just use tcpdump to examine the traffic.
man tcpdump