{"id":711,"date":"2025-07-27T09:59:05","date_gmt":"2025-07-27T01:59:05","guid":{"rendered":"https:\/\/www.vcidc.net\/blog\/?p=711"},"modified":"2025-07-27T09:59:05","modified_gmt":"2025-07-27T01:59:05","slug":"%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%98%b2%e7%81%ab%e5%a2%99%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97%ef%bc%9alinux%e6%9c%8d%e5%8a%a1%e5%99%a8iptables%e9%98%b2%e7%81%ab%e5%a2%99%e8%ae%be%e7%bd%ae%e8%af%a6","status":"publish","type":"post","link":"https:\/\/www.vcidc.net\/blog\/711.html","title":{"rendered":"\u670d\u52a1\u5668\u9632\u706b\u5899\u914d\u7f6e\u6307\u5357\uff1aLinux\u670d\u52a1\u5668iptables\u9632\u706b\u5899\u8bbe\u7f6e\u8be6\u89e3"},"content":{"rendered":"<p><h2>\u670d\u52a1\u5668\u9632\u706b\u5899\u6280\u672f\u7b80\u4ecb<\/h2>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.vcidc.net\/blog\/wp-content\/uploads\/2025\/07\/KCm9DG.jpg\" alt=\"\u670d\u52a1\u5668\u9632\u706b\u5899\u914d\u7f6e\u6307\u5357\uff1aLinux\u670d\u52a1\u5668iptables\u9632\u706b\u5899\u8bbe\u7f6e\u8be6\u89e3\" title=\"\u670d\u52a1\u5668\u9632\u706b\u5899\u914d\u7f6e\u6307\u5357\uff1aLinux\u670d\u52a1\u5668iptables\u9632\u706b\u5899\u8bbe\u7f6e\u8be6\u89e3\"><\/p>\n<p>\u670d\u52a1\u5668\u9632\u706b\u5899\u662f\u4e00\u79cd\u7f51\u7edc\u5b89\u5168\u8bbe\u5907\uff0c\u7528\u4e8e\u76d1\u63a7\u548c\u63a7\u5236\u8fdb\u5165\u548c\u79bb\u5f00\u7f51\u7edc\u7684\u6570\u636e\u6d41\u3002\u5b83\u901a\u8fc7\u5bf9\u7f51\u7edc\u6d41\u91cf\u8fdb\u884c\u8fc7\u6ee4\uff0c\u9632\u6b62\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee\u548c\u6f5c\u5728\u7684\u6076\u610f\u653b\u51fb\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u914d\u7f6e\u548c\u4f7f\u7528iptables\u9632\u706b\u5899\uff0c\u5305\u62ec\u64cd\u4f5c\u6b65\u9aa4\u3001\u547d\u4ee4\u793a\u4f8b\u53ca\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<p><h2>\u4efb\u52a1\u6982\u8ff0<\/h2>\n<\/p>\n<p>\u672c\u6587\u7684\u4efb\u52a1\u662f\u6307\u5bfc\u8bfb\u8005\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u914d\u7f6eiptables\u9632\u706b\u5899\uff0c\u5b9e\u73b0\u57fa\u672c\u7684\u7f51\u7edc\u5b89\u5168\u9632\u62a4\u3002<\/p>\n<p><h2>\u51c6\u5907\u5de5\u4f5c<\/h2>\n<\/p>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u5df2\u7ecf\u767b\u5f55\u5230\u60a8\u7684Linux\u670d\u52a1\u5668\uff0c\u5e76\u4e14\u5177\u6709root\u6743\u9650\u3002<\/p>\n<p><h2>\u5b89\u88c5iptables<\/h2>\n<\/p>\n<p>\u786e\u4fdd\u60a8\u7684\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86iptables\u3002\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u9ed8\u8ba4\u5df2\u7ecf\u5b89\u88c5\u4e86iptables\u3002<\/p>\n<p><h3>\u68c0\u67e5iptables\u7248\u672c<\/h3>\n<\/p>\n<p><pre><code>iptables --version<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p>\u5982\u679ciptables\u672a\u5b89\u88c5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<p><pre><code>sudo apt-get update<\/p>\r\n<p>sudo apt-get install iptables<\/p>\r\n<p><\/code><\/pre>\n<p>\uff08\u5bf9\u4e8e\u57fa\u4e8eDebian\u7684\u7cfb\u7edf\uff09<\/p>\n<p><h2>\u57fa\u672c\u914d\u7f6e\u6b65\u9aa4<\/h2>\n<\/p>\n<p>\u4ee5\u4e0b\u662f\u5728Linux\u670d\u52a1\u5668\u4e0a\u914d\u7f6eiptables\u9632\u706b\u5899\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n<p><h3>1. \u6e05\u9664\u73b0\u6709\u89c4\u5219<\/h3>\n<\/p>\n<p>\u9996\u5148\uff0c\u6e05\u9664\u6240\u6709\u73b0\u6709\u7684iptables\u89c4\u5219\u3002<\/p>\n<p><pre><code>sudo iptables -F<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u8bbe\u7f6e\u9ed8\u8ba4\u7b56\u7565<\/h3>\n<\/p>\n<p>\u8bbe\u7f6e\u9ed8\u8ba4\u7684INPUT\u3001OUTPUT\u548cFORWARD\u94fe\u7b56\u7565\u3002<\/p>\n<p><pre><code>sudo iptables -P INPUT DROP<\/p>\r\n<p>sudo iptables -P FORWARD DROP<\/p>\r\n<p>sudo iptables -P OUTPUT ACCEPT<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3. \u5141\u8bb8SSH\u8bbf\u95ee<\/h3>\n<\/p>\n<p>\u5141\u8bb8SSH\u670d\u52a1\uff08\u9ed8\u8ba4\u7aef\u53e322\uff09\u7684\u8bbf\u95ee\u3002<\/p>\n<p><pre><code>sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4. \u5141\u8bb8\u672c\u5730\u56de\u73af<\/h3>\n<\/p>\n<p>\u5141\u8bb8\u672c\u5730\u56de\u73af\u63a5\u53e3\uff08localhost\uff09\u7684\u8bbf\u95ee\u3002<\/p>\n<p><pre><code>sudo iptables -A INPUT -i lo -j ACCEPT<\/p>\r\n<p>sudo iptables -A OUTPUT -o lo -j ACCEPT<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>5. \u5141\u8bb8\u7279\u5b9aIP\u8bbf\u95ee<\/h3>\n<\/p>\n<p>\u5141\u8bb8\u6765\u81ea\u7279\u5b9aIP\u5730\u5740\u7684\u8bbf\u95ee\u3002<\/p>\n<p><pre><code>sudo iptables -A INPUT -s 192.168.1.100 -j ACCEPT<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>6. \u4fdd\u5b58\u89c4\u5219<\/h3>\n<\/p>\n<p>\u5c06iptables\u89c4\u5219\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u5728\u7cfb\u7edf\u91cd\u542f\u540e\u4fdd\u6301\u89c4\u5219\u3002<\/p>\n<p><pre><code>sudo iptables-save > \/etc\/iptables\/rules.v4<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<ul>\n<li>\u5728\u4fee\u6539iptables\u89c4\u5219\u65f6\uff0c\u8bf7\u786e\u4fdd\u60a8\u4e86\u89e3\u6bcf\u4e2a\u89c4\u5219\u7684\u542b\u4e49\u3002<\/li>\n<li>\u5728\u4fee\u6539\u89c4\u5219\u540e\uff0c\u8bf7\u4f7f\u7528`iptables-save`\u547d\u4ee4\u4fdd\u5b58\u89c4\u5219\u3002<\/li>\n<li>\u5728\u914d\u7f6e\u9632\u706b\u5899\u65f6\uff0c\u8bf7\u8003\u8651\u5b89\u5168\u6027\u548c\u4fbf\u5229\u6027\u7684\u5e73\u8861\u3002<\/li>\n<\/ul>\n<p><h2>\u5b9e\u7528\u6280\u5de7<\/h2>\n<\/p>\n<ul>\n<li>\u4f7f\u7528`iptables -L`\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u89c4\u5219\u3002<\/li>\n<li>\u4f7f\u7528`iptables -D`\u547d\u4ee4\u5220\u9664\u89c4\u5219\u3002<\/li>\n<li>\u4f7f\u7528`iptables -I`\u547d\u4ee4\u5728\u7279\u5b9a\u4f4d\u7f6e\u63d2\u5165\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><h2>\u7ed3\u8bba<\/h2>\n<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u5df2\u7ecf\u6210\u529f\u5728Linux\u670d\u52a1\u5668\u4e0a\u914d\u7f6e\u4e86iptables\u9632\u706b\u5899\u3002\u8bf7\u6839\u636e\u60a8\u7684\u5b9e\u9645\u9700\u6c42\u8c03\u6574\u89c4\u5219\uff0c\u4ee5\u786e\u4fdd\u7f51\u7edc\u5b89\u5168\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u670d\u52a1\u5668\u9632\u706b\u5899\u6280\u672f\u7b80\u4ecb \u670d\u52a1\u5668\u9632\u706b\u5899\u662f\u4e00\u79cd\u7f51\u7edc\u5b89\u5168\u8bbe\u5907\uff0c\u7528\u4e8e\u76d1\u63a7\u548c\u63a7\u5236\u8fdb\u5165\u548c\u79bb\u5f00\u7f51\u7edc\u7684\u6570\u636e\u6d41\u3002\u5b83\u901a\u8fc7\u5bf9\u7f51\u7edc\u6d41\u91cf\u8fdb\u884c\u8fc7\u6ee4\uff0c\u9632\u6b62\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee\u548c\u6f5c\u5728\u7684\u6076\u610f\u653b\u51fb\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u914d\u7f6e\u548c\u4f7f\u7528iptables\u9632\u706b\u5899\uff0c\u5305\u62ec\u64cd\u4f5c\u6b65\u9aa4\u3001&#8230;<\/p>\n","protected":false},"author":1,"featured_media":712,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[110,19,79],"topic":[],"class_list":["post-711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tw-server","tag-iptables","tag-19","tag-79"],"_links":{"self":[{"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/posts\/711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/comments?post=711"}],"version-history":[{"count":1,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/posts\/711\/revisions"}],"predecessor-version":[{"id":714,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/posts\/711\/revisions\/714"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/media\/712"}],"wp:attachment":[{"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/media?parent=711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/categories?post=711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/tags?post=711"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.vcidc.net\/blog\/wp-json\/wp\/v2\/topic?post=711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}