{"id":1866,"date":"2010-09-17T10:35:53","date_gmt":"2010-09-17T10:35:53","guid":{"rendered":"http:\/\/www.icocean.com\/blog\/?p=1866"},"modified":"1970-01-01T07:00:00","modified_gmt":"1970-01-01T07:00:00","slug":"%E8%AE%A9linux%E7%B3%BB%E7%BB%9F%E9%98%B2%E6%AD%A2%E9%83%A8%E5%88%86syn%E6%94%BB%E5%87%BB","status":"publish","type":"post","link":"https:\/\/www.icocean.com\/blog\/?p=1866","title":{"rendered":"\u8ba9Linux\u7cfb\u7edf\u9632\u6b62\u90e8\u5206syn\u653b\u51fb"},"content":{"rendered":"<p>\u865a\u62df\u4e3b\u673a\u670d\u52a1\u5546\u5728\u8fd0\u8425\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u53d7\u5230\u9ed1\u5ba2\u653b\u51fb\uff0c\u5e38\u89c1\u7684\u653b\u51fb\u65b9\u5f0f\u6709SYN\uff0cDDOS\u7b49\u3002\u901a\u8fc7\u66f4\u6362IP\uff0c\u67e5\u627e\u88ab\u653b\u51fb\u7684\u7ad9\u70b9\u53ef\u80fd\u907f\u5f00\u653b\u51fb\uff0c\u4f46\u662f\u4e2d\u65ad\u670d\u52a1\u7684\u65f6\u95f4\u6bd4\u8f83\u957f\u3002\u6bd4\u8f83\u5f7b\u5e95\u7684\u89e3\u51b3\u65b9\u6cd5\u662f\u6dfb\u7f6e\u786c\u4ef6\u9632\u706b\u5899\u3002\u4e0d\u8fc7\uff0c\u786c\u4ef6\u9632\u706b\u5899\u4ef7\u683c\u6bd4\u8f83\u6602\u8d35\u3002\u53ef\u4ee5\u8003\u8651\u5229\u7528Linux \u7cfb\u7edf\u672c\u8eab\u63d0\u4f9b\u7684\u9632\u706b\u5899\u529f\u80fd\u6765\u9632\u5fa1\u3002<\/p>\n<p>\u62b5\u5fa1SYN SYN\u653b\u51fb\u662f\u5229\u7528TCP\/IP\u534f\u8bae3\u6b21\u63e1\u624b\u7684\u539f\u7406\uff0c\u53d1\u9001\u5927\u91cf\u7684\u5efa\u7acb\u8fde\u63a5\u7684\u7f51\u7edc\u5305\uff0c\u4f46\u4e0d\u5b9e\u9645\u5efa\u7acb\u8fde\u63a5\uff0c\u6700\u7ec8\u5bfc\u81f4\u88ab\u653b\u51fb\u670d\u52a1\u5668\u7684\u7f51\u7edc\u961f\u5217\u88ab\u5360\u6ee1\uff0c\u65e0\u6cd5\u88ab\u6b63\u5e38\u7528\u6237\u8bbf\u95ee\u3002<br \/>Linux\u5185\u6838\u63d0\u4f9b\u4e86\u82e5\u5e72SYN\u76f8\u5173\u7684\u914d\u7f6e\uff0c\u7528\u547d\u4ee4\uff1a sysctl -a &#124; grep syn \u770b\u5230\uff1a<br \/>net.ipv4.tcp_max_syn_backlog = 1024 net.ipv4.tcp_syncookies = 0<br \/>net.ipv4.tcp_synack_retries = 5 net.ipv4.tcp_syn_retries = 5<\/p>\n<p>tcp_max_syn_backlog\u662fSYN\u961f\u5217\u7684\u957f\u5ea6\uff0ctcp_syncookies\u662f\u4e00\u4e2a\u5f00\u5173\uff0c\u662f\u5426\u6253\u5f00SYN Cookie \u529f\u80fd\uff0c\u8be5\u529f\u80fd\u53ef\u4ee5\u9632\u6b62\u90e8\u5206SYN\u653b\u51fb\u3002tcp_synack_retries\u548ctcp_syn_retries\u5b9a\u4e49SYN \u7684\u91cd\u8bd5\u6b21\u6570\u3002\u52a0\u5927SYN\u961f\u5217\u957f\u5ea6\u53ef\u4ee5\u5bb9\u7eb3\u66f4\u591a\u7b49\u5f85\u8fde\u63a5\u7684\u7f51\u7edc\u8fde\u63a5\u6570\uff0c\u6253\u5f00SYN Cookie\u529f\u80fd\u53ef\u4ee5\u963b\u6b62\u90e8\u5206 SYN\u653b\u51fb\uff0c\u964d\u4f4e\u91cd\u8bd5\u6b21\u6570\u4e5f\u6709\u4e00\u5b9a\u6548\u679c\u3002<!--more--><\/p>\n<p>\u8c03\u6574\u4e0a\u8ff0\u8bbe\u7f6e\u7684\u65b9\u6cd5\u662f\uff1a<br \/>\u589e\u52a0SYN\u961f\u5217\u957f\u5ea6\u52302048\uff1a<br \/>sysctl -w net.ipv4.tcp_max_syn_backlog=2048<\/p>\n<p>\u6253\u5f00SYN COOKIE\u529f\u80fd\uff1a<br \/>sysctl -w net.ipv4.tcp_syncookies=1<\/p>\n<p>\u964d\u4f4e\u91cd\u8bd5\u6b21\u6570\uff1a<br \/>sysctl -w net.ipv4.tcp_synack_retries=3 sysctl -w net.ipv4.tcp_syn_retries=3<\/p>\n<p>\u4e3a\u4e86\u7cfb\u7edf\u91cd\u542f\u52a8\u65f6\u4fdd\u6301\u4e0a\u8ff0\u914d\u7f6e\uff0c\u53ef\u5c06\u4e0a\u8ff0\u547d\u4ee4\u52a0\u5165\u5230\/etc\/rc.d\/rc.local\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u9632\u6b62\u540c\u6b65\u5305\u6d2a\u6c34\uff08Sync Flood\uff09<br \/># iptables -A FORWARD -p tcp &#8211;syn -m limit &#8211;limit 1\/s -j ACCEPT<\/p>\n<p>\u4e5f\u6709\u4eba\u5199\u4f5c<br \/>#iptables -A INPUT -p tcp &#8211;syn -m limit &#8211;limit 1\/s -j ACCEPT<br \/>&#8211;limit 1\/s \u9650\u5236syn\u5e76\u53d1\u6570\u6bcf\u79d21\u6b21\uff0c\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u4fee\u6539<\/p>\n<p>\u9632\u6b62\u5404\u79cd\u7aef\u53e3\u626b\u63cf<br \/># iptables -A FORWARD -p tcp &#8211;tcp-flags SYN,ACK,FIN,RST RST -m limit &#8211;limit 1\/s -j ACCEPT<\/p>\n<p>Ping\u6d2a\u6c34\u653b\u51fb\uff08Ping of Death\uff09<br \/># iptables -A FORWARD -p icmp &#8211;icmp-type echo-request -m limit &#8211;limit 1\/s -j ACCEPT<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u865a\u62df\u4e3b\u673a\u670d\u52a1\u5546\u5728\u8fd0\u8425\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u53d7\u5230\u9ed1\u5ba2\u653b\u51fb\uff0c\u5e38\u89c1\u7684\u653b\u51fb\u65b9\u5f0f\u6709SYN\uff0cDDOS\u7b49\u3002\u901a\u8fc7\u66f4\u6362IP\uff0c\u67e5\u627e\u88ab\u653b\u51fb\u7684\u7ad9 <a href='https:\/\/www.icocean.com\/blog\/?p=1866' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[2993,2525,2574,2992,896,384],"class_list":["post-1866","post","type-post","status-publish","format-standard","hentry","category-lamp","tag-attack","tag-firewall","tag-iptables","tag-syn","tag-896","tag-384","category-24-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1866"}],"version-history":[{"count":0,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1866\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}