{"id":122445,"date":"2018-10-07T08:41:19","date_gmt":"2018-10-07T00:41:19","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=122445"},"modified":"2018-09-30T09:42:10","modified_gmt":"2018-09-30T01:42:10","slug":"iptables-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/iptables-linux.html","title":{"rendered":"\u5927\u795e\u6559\u4f60\u7528iptables\u9650\u5236sftp\u7aef\u53e3\u8fde\u63a5\u6570"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4e4b\u524d\u5728\u516c\u53f8\u670d\u52a1\u5668\u4e0a\u90e8\u7f72\u4e86sftp\uff0c\u7528\u4e8e\u4e0a\u4f20\u4e1a\u52a1\u7cfb\u7edf\u7684\u9644\u4ef6\u3002\u540e\u6765\u7531\u4e8e\u7a0b\u5e8f\u8fde\u63a5\u95ee\u9898\uff0c\u4f7f\u7684sftp\u8fde\u63a5\u6570\u8fc7\u591a\uff08\u6700\u591a\u65f6\u9ad8\u8fbe400\u591a\u4e2asftp\u8fde\u63a5\u6570\uff09\uff0c\u56e0\u4e3a\u6025\u9700\u8981\u5bf9sftp\u7684\u8fde\u63a5\u6570\u505a\u4e25\u683c\u9650\u5236\u3002\u64cd\u4f5c\u8bb0\u5f55\u5982\u4e0b\uff1a<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u542f\u52a8sftp\u672c\u673a\u7684iptables\u9632\u706b\u5899\u529f\u80fd\uff0c\u9650\u5236\u6bcf\u4e2aip\u8fde\u63a522\u7aef\u53e3\uff08sftp\u8fde\u63a5\u7aef\u53e3\u5373\u662fssh\u7aef\u53e3\uff09\u6700\u5927\u4e3a50\u4e2a\uff0c\u5f53\u8d85\u8fc750\u540e\u7684\u8fde\u63a5\u6570\u7684\u6d41\u91cf\u5c31\u4f1a\u88abDROP\u6389\uff01<\/p>\n

\u540c\u65f6iptables\u9700\u8981\u5f00\u653e50000-65535\u8303\u56f4\u7684\u7aef\u53e3\u7684\u8bbf\u95ee\uff08linux\u7cfb\u7edf\u6700\u5927\u7684\u7aef\u53e3\u4e3a65535\uff09<\/p>\n

[root@localhost ~]# cat \/etc\/sysconfig\/iptables\r\n# Firewall configuration written by system-config-firewall\r\n# Manual customization of this file is not recommended.\r\n*filter\r\n:INPUT ACCEPT [0:0]\r\n:FORWARD ACCEPT [0:0]\r\n:OUTPUT ACCEPT [0:0]\r\n-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT\r\n-A INPUT -p icmp -j ACCEPT\r\n-A INPUT -i lo -j ACCEPT\r\n#-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\r\n-A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 50 --connlimit-mask 0 -j DROP\r\n-A INPUT -m state --state NEW -m tcp -p tcp --dport 50000:65535 -j ACCEPT\r\n#-A INPUT -j REJECT --reject-with icmp-host-prohibited                                \/\/\u6ce8\u610f\u8fd9\u4e24\u884c\u9700\u8981\u6ce8\u91ca\u6389\uff01\u5426\u5219\u8bbe\u7f6e\u7684\u7b56\u7565\u65e0\u6548\uff01\r\n#-A FORWARD -j REJECT --reject-with icmp-host-prohibited\r\nCOMMIT<\/pre>\n
\u89e3\u91ca\u8bf4\u660e<\/strong><\/div>\n

\u4e0a\u9762\u9650\u5236\u7aef\u53e3\u8fde\u63a5\u6570\u4e3b\u8981\u7528\u5230\u7684\u6a21\u5757\u662fconnlimit\u3002
\n-A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 50 --connlimit-mask 0 -j DROP<\/p>\n

\u8bf4\u660e\u8f93\u5165\u7684\u76ee\u6807\u7aef\u53e3\u662f22\uff0c\u4e5f\u5c31\u662f\u8bbf\u95eesftp\u672c\u673a22\u7aef\u53e3\u7684\u6d41\u91cf\uff0c\u5982\u679c\u8fde\u63a5\u6570\u5927\u4e8e50\uff0c\u5219DROP\u6d41\u91cf\uff0cconnlimit-above\u8fd9\u4e2a\u662f\u8fde\u63a5\u6570\u7684\u7edf\u8ba1\uff0c
\n\u5982\u679c\u5927\u4e8e50\u5c31\u6ee1\u8db3\u6761\u4ef6\uff0cconnlimit-mask\u8fd9\u4e2a\u662f\u5b9a\u4e49\u90a3\u7ec4\u4e3b\u673a\uff0c\u6b64\u5904\u8ddf\u7684\u4e00\u4e2a\u6570\u503c\u662f\u7f51\u7edc\u4f4d\uff0c\u5373\u5b50\u7f51\u63a9\u7801\uff0c\u4e5f\u5c31\u662fconnlimit-mask 0 \u8fd9\u4e2aip\u7ec4\u7684\u8fde\u63a5\u6570\u5927\u4e8econnlimit-above 50\u5219DROP\u6389\uff01<\/p>\n

\u603b\u4f53\u63cf\u8ff0\u4e3a\u6d41\u91cf\u8fc7\u6ee4\u7aef\u53e3\u548c\u8fde\u63a5\u6570\u4ee5\u53ca\u7f51\u7edc\u4f4d\uff0c\u5982\u679c\u6ee1\u8db3\u7b2c\u4e00\u6761\uff0c\u5219\u62d2\u7edd\uff0c\u6d41\u91cf\u4e0d\u518d\u5339\u914d\u4e0b\u8fb9\u7684\u89c4\u5219\uff0c\u5982\u679c\u4e0d\u5339\u914d\uff0c\u5219\u7b2c\u4e8c\u6761\u89c4\u5219\u4f1a\u5141\u8bb8\u6d41\u91cf\u3002
\n--connlimit-mask 0 \u5373\u5b50\u7f51\u63a9\u7801\u4e3a0\uff0c\u8868\u793a\u6240\u6709\u7684ip\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e0d\u7ba1\u4ec0\u4e48ip\uff0c\u53ea\u8981\u8fde\u63a5\u6b64\u670d\u52a1\u5668\u768422\u7aef\u53e3\u8d85\u8fc73\u4e2a\uff0c\u5219DROP\u3002<\/p>\n

\u5982\u679c\u5c06--connlimit-mask 0\u53bb\u6389\uff0c\u5219\u5b50\u7f51\u63a9\u7801\u9ed8\u8ba4\u662f32\uff0c\u4e5f\u5c31\u662f\u8bf4\u67d0\u4e2aip\u8fde\u63a5\u6b64\u670d\u52a1\u5668\u768422\u7aef\u53e3\u8d85\u54e550\u4e2a\uff0c\u5219DROP\u6389\uff01
\n\u5982\u679c\u670951\u53f0\u673a\u5668\uff0c\u6bcf\u53f0\u673a\u5668\u8fde\u63a5\u4e00\u4e2a\uff0c\u5219\u4e0d\u4f1a\u88abDROP\u6389\uff01<\/p>\n

\u4e5f\u5c31\u662f\u8bf4connlimit-above 3\u8fd9\u4e2a\u7684\u6570\u91cf\u6240\u9650\u5236\u7684\u533a\u57df\u662f\u7531--connlimit-mask 0\u800c\u5b9a\uff01<\/p>\n

\u4f7f\u7528sftp\u6216ftp\u534f\u8bae\u4e0a\u4f20\u6587\u4ef6,\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u4e3a0<\/strong><\/div>\n
\u5ba2\u6237\u7aef\u4e0a\u4f20\u62a5\u9519:error while writing: received failure with description 'Failure'\r\n\u670d\u52a1\u5668\u7aef\/var\/log\/message\u62a5\u9519:sftp-server[15747]: error: process_write: write failed <\/pre>\n

\u9020\u6210\u8fd9\u4e2a\u9519\u8bef\u5927\u81f4\u5c31\u4e24\u4e2a\u539f\u56e0\uff1a<\/p>\n

1) ulimit\u9650\u5236. \r\n\u5728sftp\u8fde\u63a5\u4f7f\u7528\u7684\u8d26\u53f7\u4e0b\u589e\u5927ulimit\u7684\u503c\r\n# ulimit -n 65535 \r\n2) \u78c1\u76d8\u7a7a\u95f4\u4e0d\u591f\u4e86<\/pre>\n
iptables\u9650\u5236\u540c\u4e00IP\u8fde\u63a5\u6570\uff0c\u9884\u9632CC\/DDOS\u653b\u51fb<\/strong><\/div>\n

1\uff09\u9650\u5236\u4e0e80\u7aef\u53e3\u8fde\u63a5\u7684IP\u6700\u5927\u8fde\u63a5\u6570\u4e3a50\uff0c\u53ef\u81ea\u5b9a\u4e49\u4fee\u6539\u3002<\/p>\n

[root@localhost ~]# iptables -A INPUT -p tcp --dport 80 -m connlimit --connlimit-above 50 -j DROP<\/pre>\n

2\uff09\u4f7f\u7528recent\u6a21\u5757\u9650\u5236\u540cIP\u65f6\u95f4\u5185\u65b0\u8bf7\u6c42\u8fde\u63a5\u6570\u3002<\/p>\n

\u4e0b\u9762\u7b56\u7565\u8868\u793a\uff1a60\u79d2\u670910\u4e2a\u65b0\u8fde\u63a5\uff0c\u8d85\u8fc7\u8bb0\u5f55\u65e5\u5fd7\u3002<\/p>\n

[root@localhost ~]# iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --rcheck --seconds 60 --hitcount 10\r\n-j LOG --log-prefix 'DDOS:' --log-ip-options<\/pre>\n

\u4e0b\u9762\u7b56\u7565\u8868\u793a\uff1a60\u79d210\u4e2a\u65b0\u8fde\u63a5\uff0c\u8d85\u8fc7\u4e22\u5f03\u6570\u636e\u5305<\/p>\n

[root@localhost ~]# iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --rcheck --seconds 60 --hitcount 10 -j DROP<\/pre>\n

\u53ef\u4ee5\u5728iptables\u914d\u7f6e\u6587\u4ef6\u4e2d<\/p>\n

[root@localhost ~]# vim \/etc\/sysconfig\/iptables    \/\/\u5220\u9664\u539f\u6765\u7684\u5185\u5bb9\u8f93\u5165\u5982\u4e0b\u5185\u5bb9 \u4fdd\u5b58\r\n# Generated by iptables-save v1.3.5 on Sun Dec 12 23:55:59 2010\r\n*filter\r\n:INPUT DROP [385263:27864079]\r\n:FORWARD ACCEPT [0:0]\r\n:OUTPUT ACCEPT [4367656:3514692346]\r\n-A INPUT -i lo -j ACCEPT\r\n-A INPUT -m state \u2013state RELATED,ESTABLISHED -j ACCEPT\r\n-A INPUT -p icmp -j ACCEPT\r\n-A INPUT -s 127.0.0.1 -j ACCEPT\r\n-A INPUT -p tcp -m tcp \u2013dport 80 -m state \u2013state NEW -m recent \u2013set \u2013name WEB \u2013rsource\r\n-A INPUT -p tcp -m tcp \u2013dport 80 -m state \u2013state NEW -m recent \u2013update \u2013seconds 5 \u2013hitcount 20 \u2013rttl \u2013name WEB \u2013rsource -j DROP\r\n-A INPUT -p tcp -m multiport \u2013ports 21,22,80 -j ACCEPT\r\n-A INPUT -p tcp -m tcp \u2013tcp-flags SYN,RST,ACK SYN -m ttl \u2013ttl-eq 117 -j DROP\r\n-A INPUT -p tcp -m tcp \u2013tcp-flags SYN,RST,ACK SYN -m length \u2013length 0:40 -j DROP\r\n-A INPUT -p tcp -m tcp ! \u2013tcp-flags SYN,RST,ACK SYN -m state \u2013state NEW -j DROP\r\nCOMMIT\r\n# Completed on Sun Dec 12 23:55:59 2017<\/pre>\n

\u4ee5\u4e0a\u914d\u7f6e\uff0c\u8bf4\u660e\u6b64\u8bbe\u5b9a\u4ec5\u5bf9\u5916\u5f00\u653e21(FTP),22(SSH),80(http\u7f51\u7ad9\uff09\u4e09\u4e2aTCP\u7aef\u53e3\u3002\u8bbe\u7f6e80\u7aef\u53e35\u79d2\u518520\u4e2a\u8fde\u63a5\u3002<\/p>\n

[root@localhost ~]# \/etc\/init.d\/iptables restart<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/www.cnblogs.com\/kevingrace\/p\/8082700.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/iptables-linux.html<\/a>\u7f16\u8f91\uff1a\u5411\u91d1\u5e73\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u4e4b\u524d\u5728\u516c\u53f8\u670d\u52a1\u5668\u4e0a\u90e8\u7f72\u4e86sftp\uff0c\u7528\u4e8e\u4e0a\u4f20\u4e1a\u52a1\u7cfb\u7edf\u7684\u9644\u4ef6\u3002\u540e\u6765\u7531\u4e8e\u7a0b\u5e8f\u8fde\u63a5\u95ee\u9898\uff0c\u4f7f\u7684sftp\u8fde\u63a5\u6570\u8fc7\u591a\uff08 […]<\/p>\n","protected":false},"author":1482,"featured_media":122457,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-122445","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/122445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=122445"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/122445\/revisions"}],"predecessor-version":[{"id":122517,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/122445\/revisions\/122517"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/122457"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=122445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=122445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=122445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}