{"id":1519,"date":"2018-08-10T20:50:36","date_gmt":"2018-08-10T12:50:36","guid":{"rendered":"http:\/\/www.eumz.com\/?p=1519"},"modified":"2018-08-10T20:50:36","modified_gmt":"2018-08-10T12:50:36","slug":"sysctl%e5%af%b9linux%e5%86%85%e6%a0%b8-%e7%bd%91%e7%bb%9c%e7%9a%84%e8%ae%be%e7%bd%ae%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/www.wxcn.com\/?p=1519","title":{"rendered":"sysctl\u5bf9Linux\u5185\u6838\/\u7f51\u7edc\u7684\u8bbe\u7f6e\u8bf4\u660e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\/etc\/sysctl.conf\u63a7\u5236\u548c\u914d\u7f6eLinux\u5185\u6838\u53ca\u7f51\u7edc\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#\u5ffd\u7565icmp ping\u5e7f\u64ad\u5305\uff0c\u5e94\u5f00\u542f\uff0c\u907f\u514d\u653e\u5927\u653b\u51fb<br>net.ipv4.icmp_echo_ignore_broadcasts = 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u5f00\u542f\u6076\u610ficmp\u9519\u8bef\u6d88\u606f\u4fdd\u62a4<br>net.ipv4.icmp_ignore_bogus_error_responses = 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u5f00\u542fSYN\u6d2a\u6c34\u653b\u51fb\u4fdd\u62a4\uff0c\u8868\u793a\u5f00\u542fSYN Cookies\u3002\u5f53\u51fa\u73b0SYN\u7b49\u5f85\u961f\u5217\u6ea2\u51fa\u65f6\uff0c\u542f\u7528cookies\u6765\u5904\u7406\uff0c\u53ef\u9632\u8303\u5c11\u91cfSYN\u653b\u51fb\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u8868\u793a\u5173\u95ed<br>net.ipv4.tcp_syncookies = 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u5f00\u542f\u5e76\u8bb0\u5f55\u6b3a\u9a97\uff0c\u6e90\u8def\u7531\u548c\u91cd\u5b9a\u5411\u5305<br>net.ipv4.conf.all.log_martians = 1<br>net.ipv4.conf.default.log_martians = 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u5904\u7406\u65e0\u6e90\u8def\u7531\u7684\u5305<br>net.ipv4.conf.all.accept_source_route = 0<br>net.ipv4.conf.default.accept_source_route = 0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># reverse-pathfiltering \u53cd\u5411\u8def\u5f84\u8fc7\u6ee4\uff0c\u7cfb\u7edf\u6536\u5230\u4e00\u4e2aip\u5305\u540e\uff0c\u4f1a\u53cd\u67e5\u8be5ip\u5305\u7684ip\u662f\u5426\u4e0e\u5b83\u4eec\u5230\u8fbe\u7684\u7f51\u7edc\u63a5\u53e3\u5339\u914d\uff0c\u82e5\u4e0d\u5339\u914d\u5219\u4e22\u5f03\u3002\u662f\u9632ip\u5305\u6b3a\u9a97\u7b56\u7565\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># The rp_filter can reject incoming packets if their sourceaddress doesn\u2019t match the network interface that they\u2019re arrivingon, which helps to prevent IP spoofing. Turning this on, however,has its consequences: If your host has several IP addresses ondifferent interfaces, or if your single interface has multiple IPaddresses on it, you\u2019ll find that your kernel may end up rejectingvalid traffic. It\u2019s also important to note that even if you do notenable the rp_filter, protection against broadcast spoofing isalways on. Also, the protection it provides is only against spoofedinternal addresses; external addresses can still be spoofed.. Bydefault, it is disabled.<br>net.ipv4.conf.all.rp_filter = 1<br>net.ipv4.conf.default.rp_filter = 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#\u5173\u95ed\u91cd\u5b9a\u5411\u3002\u5982\u679c\u4e3b\u673a\u6240\u5728\u7684\u7f51\u7edc\u6709\u591a\u4e2a\u8def\u7531\u5668\uff0c\u4f60\u5c06\u5176\u4e2d\u4e00\u4e2a\u8bbe\u4e3a\u7f3a\u7701\u7f51\u5173\uff0c\u4f46\u8be5\u7f51\u5173\u5728\u6536\u5230\u4f60\u7684ip\u5305\u65f6\uff0c\u53d1\u73b0\u8be5ip\u5305\u5fc5\u987b\u7ecf\u8fc7\u53e6\u5916\u4e00\u4e2a\u8def\u7531\u5668\uff0c\u4e8e\u662f\u8be5\u7f51\u5173\u5c31\u7d66\u4f60\u7684\u4e3b\u673a\u53d1\u4e00\u4e2a\u201c\u91cd\u5b9a\u5411\u201d\u7684icmp\u5305\uff0c\u544a\u8bc9\u4e3b\u673a\u628a\u5305\u8f6c\u53d1\u5230\u53e6\u5916\u4e00\u4e2a\u8def\u7531\u5668\u30021\u8868\u793a\u4e3b\u673a\u63a5\u53d7\u8fd9\u6837\u7684\u91cd\u5b9a\u5411\u5305\uff0c0\u8868\u793a\u5ffd\u7565\uff1blinux\u9ed8\u8ba4\u662f1\uff0c\u53ef\u4ee5\u8bbe\u4f4d0\u4ee5\u6d88\u9664\u9690\u60a3\u3002<br>net.ipv4.conf.all.accept_redirects = 0<br>net.ipv4.conf.default.accept_redirects = 0<br>net.ipv4.conf.all.secure_redirects = 0<br>net.ipv4.conf.default.secure_redirects = 0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#\u7981\u6b62\u6570\u636e\u5305\u8f6c\u53d1\uff0c\u4e0d\u505a\u8def\u7531\u5668\u529f\u80fd\u3002\u6240\u8c13\u8f6c\u53d1\u5373\u5f53\u4e3b\u673a\u62e5\u6709\u591a\u7f51\u5361\u65f6\uff0c\u5176\u4e2d\u4e00\u5757\u6536\u5230\u6570\u636e\u5305\uff0c\u6839\u636e\u6570\u636e\u5305\u7684\u76ee\u7684ip\u5730\u5740\u5c06\u5305\u53d1\u5f80\u672c\u673a\u53e6\u4e00\u7f51\u5361\uff0c\u8be5\u7f51\u5361\u6839\u636e\u8def\u7531\u8868\u7ee7\u7eed\u53d1\u9001\u6570\u636e\u5305\u3002\u8fd9\u901a\u5e38\u5c31\u662f\u8def\u7531\u5668\u6240\u8981\u5b9e\u73b0\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#\u5bf9\u6bd4\u7f51\u5173\uff1a\u5185\u7f51\u4e3b\u673a\u5411\u516c\u7f51\u53d1\u9001\u6570\u636e\u5305\u65f6\uff0c\u7531\u4e8e\u76ee\u7684\u4e3b\u673a\u8ddf\u6e90\u4e3b\u673a\u4e0d\u5728\u540c\u4e00\u7f51\u6bb5\uff0c\u6240\u4ee5\u6570\u636e\u5305\u6682\u65f6\u53d1\u5f80\u5185\u7f51\u9ed8\u8ba4\u7f51\u5173\u5904\u7406\uff0c\u800c\u672c\u7f51\u6bb5\u7684\u4e3b\u673a\u5bf9\u6b64\u6570\u636e\u5305\u4e0d\u505a\u4efb\u4f55\u56de\u5e94\u3002\u7531\u4e8e\u6e90\u4e3b\u673aip\u662f\u79c1\u6709\u7684\uff0c\u7981\u6b62\u5728\u516c\u7f51\u4f7f\u7528\uff0c\u6240\u4ee5\u5fc5\u987b\u5c06\u6570\u636e\u5305\u7684\u6e90\u53d1\u9001\u5730\u5740\u4fee\u6539\u6210\u516c\u7f51\u4e0a\u7684\u53ef\u7528ip\uff0c\u8fd9\u5c31\u662f\u7f51\u5173\u6536\u5230\u6570\u636e\u5305\u4e4b\u540e\u9996\u5148\u8981\u505a\u7684\u5de5\u4f5c&#8211;ip\u8f6c\u6362\u3002\u7136\u540e\u7f51\u5173\u518d\u628a\u6570\u636e\u5305\u53d1\u5f80\u76ee\u7684\u4e3b\u673a\u3002\u76ee\u7684\u4e3b\u673a\u6536\u5230\u6570\u636e\u5305\u4e4b\u540e\uff0c\u53ea\u8ba4\u4e3a\u8fd9\u662f\u7f51\u5173\u53d1\u9001\u7684\u8bf7\u6c42\uff0c\u5e76\u4e0d\u77e5\u9053\u5185\u7f51\u4e3b\u673a\u7684\u5b58\u5728\uff0c\u4e5f\u6ca1\u5fc5\u8981\u77e5\u9053\uff0c\u76ee\u7684\u4e3b\u673a\u5904\u7406\u5b8c\u8bf7\u6c42\uff0c\u628a\u56de\u5e94\u4fe1\u606f\u53d1\u8fd8\u7ed9\u7f51\u5173\u3002\u7f51\u5173\u6536\u5230\u540e\uff0c\u5c06\u76ee\u7684\u4e3b\u673a\u53d1\u8fd8\u7684\u6570\u636e\u5305\u7684\u76ee\u7684ip\u5730\u5740\u4fee\u6539\u4e3a\u53d1\u51fa\u8bf7\u6c42\u7684\u5185\u7f51\u4e3b\u673a\u7684ip\u5730\u5740\uff0c\u5e76\u5c06\u5176\u53d1\u7ed9\u5185\u7f51\u4e3b\u673a\u3002\u8fd9\u5c31\u662f\u7f51\u5173\u7684\u7b2c\u4e8c\u4e2a\u5de5\u4f5c&#8211;\u6570\u636e\u5305\u7684\u8def\u7531\u8f6c\u53d1\u3002\u5185\u7f51\u7684\u4e3b\u673a\u53ea\u8981\u67e5\u770b\u6570\u636e\u5305\u7684\u76ee\u7684ip\u4e0e\u53d1\u9001\u8bf7\u6c42\u7684\u6e90\u4e3b\u673aip\u5730\u5740\u76f8\u540c\uff0c\u5c31\u4f1a\u56de\u5e94\uff0c\u8fd9\u5c31\u5b8c\u6210\u4e86\u4e00\u6b21\u8bf7\u6c42\u3002 net.ipv4.ip_forward = 0<br>net.ipv4.conf.all.send_redirects = 0<br>net.ipv4.conf.default.send_redirects = 0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u5f00\u542fexecshield\uff0cexecshield \u4e3b\u8981\u7528\u4e8e\u968f\u673a\u5316\u5806\u6808\u5730\u5740\uff0c\u907f\u514d\u88abexploit \u7a0b\u5e8f\u4fee\u6539\u6076\u610f\u5730\u5740\uff0c\u800c\u5bfc\u81f4\u6267\u884c\u653b\u51fb\u7a0b\u5e8f\u3002<br>kernel.exec-shield = 1<br>kernel.randomize_va_space = 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># IPv6\u8bbe\u7f6e<br>net.ipv6.conf.default.router_solicitations = 0<br>net.ipv6.conf.default.accept_ra_rtr_pref = 0<br>net.ipv6.conf.default.accept_ra_pinfo = 0<br>net.ipv6.conf.default.accept_ra_defrtr = 0<br>net.ipv6.conf.default.autoconf = 0<br>net.ipv6.conf.default.dad_transmits = 0<br>net.ipv6.conf.default.max_addresses = 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u589e\u52a0\u7cfb\u7edf\u6587\u4ef6\u63cf\u8ff0\u7b26\u9650\u5236<br>fs.file-max = 65535<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u5141\u8bb8\u66f4\u591a\u7684PIDs (\u51cf\u5c11\u6eda\u52a8\u7ffb\u8f6c\u95ee\u9898);<br>may break some programs 32768<br>kernel.pid_max = 65536<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u589e\u52a0\u7cfb\u7edfIP\u7aef\u53e3\u9650\u5236 n<br>et.ipv4.ip_local_port_range = 2000 65000<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u589e\u52a0TCP\u6700\u5927\u7f13\u51b2\u533a\u5927\u5c0f<br>net.ipv4.tcp_rmem = 4096 87380 8388608<br>net.ipv4.tcp_wmem = 4096 87380 8388608<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u589e\u52a0Linux\u81ea\u52a8\u8c03\u6574TCP\u7f13\u51b2\u533a\u9650\u5236<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u6700\u5c0f\uff0c\u9ed8\u8ba4\u548c\u6700\u5927\u53ef\u4f7f\u7528\u7684\u5b57\u8282\u6570<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># \u6700\u5927\u503c\u4e0d\u4f4e\u4e8e4MB\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u975e\u5e38\u9ad8\u7684BDP\u8def\u5f84\u53ef\u4ee5\u8bbe\u7f6e\u5f97\u66f4\u9ad8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># Tcp\u7a97\u53e3\u7b49<br>net.core.rmem_max = 8388608<br>net.core.wmem_max = 8388608<br>net.core.netdev_max_backlog = 5000<br>net.ipv4.tcp_window_scaling = 1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\/etc\/sysctl.conf\u63a7\u5236\u548c\u914d\u7f6eLinux\u5185\u6838\u53ca\u7f51\u7edc\u8bbe\u7f6e\u3002 #\u5ffd\u7565icmp ping\u5e7f\u64ad\u5305\uff0c\u5e94\u5f00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[279,375],"class_list":["post-1519","post","type-post","status-publish","format-standard","hentry","category-operating-system","tag-sysctl","tag-375"],"_links":{"self":[{"href":"https:\/\/www.wxcn.com\/index.php?rest_route=\/wp\/v2\/posts\/1519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wxcn.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wxcn.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wxcn.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wxcn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1519"}],"version-history":[{"count":0,"href":"https:\/\/www.wxcn.com\/index.php?rest_route=\/wp\/v2\/posts\/1519\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wxcn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wxcn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wxcn.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}