{"id":15079,"date":"2025-04-18T21:42:52","date_gmt":"2025-04-18T13:42:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/15079.html"},"modified":"2025-04-18T21:42:52","modified_gmt":"2025-04-18T13:42:52","slug":"linux%e7%b3%bb%e7%bb%9fiptables","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/15079.html","title":{"rendered":"Linux\u7cfb\u7edfiptables"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u4e00\u3001iptables\u6982\u8ff0<\/li>\n<li>\n<ul>\n<li>1.iptables \u7684\u8868\u3001\u94fe\u7ed3\u6784<\/li>\n<\/ul>\n<\/li>\n<li>\u4e8c\u3001iptables\u547d\u4ee4<\/li>\n<li>\n<ul>\n<li>1.\u8bed\u6cd5\u7ed3\u6784<\/li>\n<li>2.iptables \u547d\u4ee4\u7684\u5e38\u7528\u7ba1\u7406\u9009\u9879<\/li>\n<li>3.\u8bbe\u7f6e\u4fee\u6539\u540e\u7684\u89c4\u5219\u4fdd\u5b58\u548c\u6062\u590d<\/li>\n<li>4.iptables\u4fe1\u606f\u67e5\u8be2<\/li>\n<li>5.\u89c4\u5219\u94fe\u5185\u7684\u5339\u914d\u987a\u5e8f:<\/li>\n<li>6.\u6dfb\u52a0\u65b0\u7684\u89c4\u5219<\/li>\n<li>7.\u5220\u9664\u3001\u6e05\u7a7a\u89c4\u5219<\/li>\n<li>8.\u8bbe\u7f6e\u9ed8\u8ba4\u7b56\u7565<\/li>\n<li>9.\u89c4\u5219\u7684\u5339\u914d\u6761\u4ef6<\/li>\n<li>\n<ul>\n<li>9.1\u901a\u7528\u5339\u914d<\/li>\n<li>9.2\u9690\u542b\u5339\u914d<\/li>\n<li>9.3\u663e\u5f0f\u5339\u914d<\/li>\n<li>9.4\u6269\u5c55\u63a7\u5236\u4f4d(\u4e86\u89e3)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e00\u3001iptables\u6982\u8ff0<\/h2>\n<p>Linux\u9632\u706b\u5899\u662f\u7531Netfilter\u7ec4\u4ef6\u63d0\u4f9b\u7684&#xff0c;Netfilter\u5de5\u4f5c\u5728\u5185\u6838\u7a7a\u95f4&#xff0c;\u96c6\u6210\u5728linux\u5185\u6838\u4e2d Netfilter \u662fLinux 2.4.x\u4e4b\u540e\u65b0\u4e00\u4ee3\u7684Linux\u9632\u706b\u5899\u673a\u5236&#xff0c;\u662flinux\u5185\u6838\u7684\u4e00\u4e2a\u5b50\u7cfb\u7edf\u3002Netfilter\u91c7\u7528\u6a21\u5757\u5316\u8bbe\u8ba1&#xff0c;\u5177\u6709\u826f\u597d\u7684\u53ef\u6269\u5145\u6027&#xff0c;\u63d0\u4f9b\u6269\u5c55\u5404\u79cd\u7f51\u7edc\u670d\u52a1\u7684\u7ed3\u6784\u5316\u5e95\u5c42\u6846\u67b6\u3002Netfilter\u4e0eIP\u534f\u8bae\u6808\u662f\u65e0\u7f1d\u5951\u5408&#xff0c;\u5e76\u5141\u8bb8\u5bf9\u6570\u636e\u62a5\u8fdb\u884c\u8fc7\u6ee4\u3001\u5730\u5740\u8f6c\u6362\u3001\u5904\u7406\u7b49\u64cd\u4f5c<\/p>\n<p>-netfilter\/iptables&#xff1a;IP \u4fe1\u606f\u5305\u8fc7\u6ee4\u7cfb\u7edf&#xff0c;\u5b83\u5b9e\u9645\u4e0a\u7531\u4e24\u4e2a\u7ec4\u4ef6 netfilter \u548c iptables\u7ec4\u6210\u3002 \u4e3b\u8981\u5de5\u4f5c\u5728\u7f51\u7edc\u5c42&#xff0c;\u9488\u5bf9IP\u6570\u636e\u5305&#xff0c;\u4f53\u73b0\u5728\u5bf9\u5305\u5185\u7684IP\u5730\u5740\u3001\u7aef\u53e3\u7b49\u4fe1\u606f\u7684\u5904\u7406\u3002<\/p>\n<p>-netfilter\/iptables\u5173\u7cfb&#xff1a; netfilter&#xff1a;\u5c5e\u4e8e\u201c\u5185\u6838\u6001\u201d\u53c8\u79f0\u5185\u6838\u7a7a\u95f4&#xff08;kernel space&#xff09;\u7684\u9632\u706b\u5899\u529f\u80fd\u4f53\u7cfb\u3002<\/p>\n<p>-iptables :\u5c5e\u4e8e\u201c\u7528\u6237\u6001\u201d(User Space&#xff0c; \u53c8\u79f0\u4e3a\u7528\u6237\u7a7a\u95f4)\u7684\u9632\u706b\u5899\u7ba1\u7406\u4f53\u7cfb\u3002 \u662f\u4e00\u79cd\u7528\u6765\u7ba1\u7406Linux\u9632\u706b\u5899\u7684\u547d\u4ee4\u7a0b\u5e8f&#xff0c;\u5b83\u4f7f\u63d2\u5165\u3001\u4fee\u6539\u548c\u5220\u9664\u6570\u636e\u5305\u8fc7\u6ee4\u8868\u4e2d\u7684\u89c4\u5219\u53d8\u5f97\u5bb9\u6613&#xff0c;\u901a\u5e38\u4f4d\u4e8e\/sbin\/iptables\u76ee\u5f55\u4e0b\u3002iptables\u662f\u57fa\u4e8e\u5185\u6838\u7684\u9632\u706b\u5899&#xff0c;\u5176\u4e2d\u5185\u7f6e\u4e86raw\u3001mangle\u3001 nat\u548cfilter\u56db\u4e2a\u89c4\u5219\u8868\u3002\u8868\u4e2d\u6240\u6709\u89c4\u5219\u914d\u7f6e\u540e&#xff0c;\u7acb\u5373\u751f\u6548&#xff0c;\u4e0d\u9700\u8981\u91cd\u542f\u670d\u52a1\u3002<\/p>\n<h3>1.iptables \u7684\u8868\u3001\u94fe\u7ed3\u6784<\/h3>\n<p>iptables\u7684\u56db\u8868\u4e94\u94fe\u7ed3\u6784\u4ecb\u7ecd iptables\u7684\u4f5c\u7528\u662f\u4e3a\u5305\u8fc7\u6ee4\u673a\u5236\u7684\u5b9e\u73b0\u63d0\u4f9b\u89c4\u5219&#xff0c;\u901a\u8fc7\u5404\u79cd\u4e0d\u540c\u7684\u89c4\u5219&#xff0c;\u544a\u8bc9netfilter\u5bf9\u6765\u81ea\u67d0\u4e9b\u6e90&#xff0c;\u524d\u5f80\u67d0\u4e9b\u76ee\u7684\u6216\u5177\u6709\u67d0\u4e9b\u534f\u8bae\u7279\u5f81\u7684\u6570\u636e\u5305\u5e94\u8be5\u5982\u4f55\u5904\u7406&#xff0c;\u4e3a\u4e86\u66f4\u52a0\u65b9\u4fbf\u7684\u7ec4\u7ec7\u548c\u7ba1\u7406\u9632\u706b\u5899\u89c4\u5219&#xff0c;iptables\u91c7\u7528\u4e86\u8868\u548c\u94fe\u7684\u5206\u5c42\u7ed3\u6784&#xff0c;\u6240\u4ee5\u5b83\u4f1a\u5bf9\u8bf7\u6c42\u7684\u6570\u636e\u5305\u7684\u5305\u5934\u6570\u636e\u8fdb\u884c\u5206\u6790&#xff0c;\u6839\u636e\u6211\u4eec\u9884\u5148\u8bbe\u5b9a\u7684\u89c4\u5219\u8fdb\u884c\u5339\u914d\u6765\u51b3\u5b9a\u662f\u5426\u53ef\u4ee5\u8fdb\u5165\u4e3b\u673a \u5176\u4e2d&#xff0c;\u6bcf\u4e2a\u89c4\u5219\u8868\u76f8\u5f53\u4e8e\u5185\u6838\u7a7a\u95f4\u7684\u4e00\u4e2a\u5bb9\u5668&#xff0c;\u6839\u636e\u89c4\u5219\u96c6\u7684\u4e0d\u540c\u7528\u9014\u5212\u5206\u4e3a\u9ed8\u8ba4\u7684\u56db\u4e2a\u8868&#xff0c;\u5728\u6bcf\u4e2a\u8868\u5bb9\u5668\u5185\u53c8\u5305\u62ec\u4e0d\u540c\u7684\u89c4\u5219\u94fe&#xff0c;\u6839\u636e\u5904\u7406\u6570\u636e\u5305\u7684\u4e0d\u540c\u65f6\u673a\u5212\u5206\u4e3a\u4e94\u79cd\u94fe<\/p>\n<p>\u56db\u8868 filter&#xff1a;\u7528\u4e8e\u63a7\u5236\u6570\u636e\u5305\u662f\u5426\u88ab\u63a5\u53d7\u6216\u8005\u8f6c\u53d1\u4e22\u5f03(\u5373\u4e3a\u8fc7\u6ee4\u64cd\u4f5c),\u8868\u5185\u542b\u6709\u4e09\u4e2a\u94fe,input,output,forward<\/p>\n<p>nat\u7528\u4e8e\u4e3b\u8981\u7528\u4e8e\u7f51\u7edc\u5730\u5740\u8f6c\u6362,\u53ef\u4ee5\u4fee\u6539\u6570\u636e\u5305\u7684\u6e90\u3001\u76ee\u6807ip\u5730\u5740\u548c\u7aef\u53e3\u53f7&#xff0c;\u5305\u542b\u4e09\u4e2a\u89c4\u5219\u94fe&#xff0c;OUTPUT\u3001PREROUTING\u3001POSTROUTING<\/p>\n<p>mangle\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5305\u7684\u5185\u5bb9,\u6bd4\u5982\u670d\u52a1\u7c7b\u578b(\u5934\u90e8\u4fe1\u606f,\u4f18\u5148\u7ea7,\u5ef6\u8fdf,\u541e\u5410\u91cf),\u751f\u547d\u5468\u671f&#xff0c;\u5305\u542b\u4e94\u4e2a\u89c4\u5219\u94fe&#xff0c;INPUT\u3001 OUTPUT\u3001 FORWARD\u3001 PREROUTING\u3001 POSTROUTING<\/p>\n<p>raw\u7528\u4e8e\u51b3\u5b9a\u6570\u636e\u5305\u662f\u5426\u8fdb\u884c\u72b6\u6001\u8ddf\u8e2a(\u8bc6\u522b\u6570\u636e\u5305\u662f\u4e00\u4e2a\u5df2\u7ecf\u5efa\u7acb\u8fde\u63a5\u7684\u4e00\u90e8\u5206\u8fd8\u662f\u4e00\u4e2a\u65b0\u7684\u8fde\u63a5)&#xff0c;\u5305\u542b\u4e24\u4e2a\u89c4\u5219\u94fe&#xff0c;OUTPUT\u3001PREROUTING<\/p>\n<p>\u4e94\u94fe INPUT: \u5904\u7406\u5165\u7ad9\u6570\u636e\u5305&#xff0c;\u5339\u914d\u76ee\u6807IP\u4e3a\u672c\u673a\u7684\u6570\u636e\u5305\u3002 OUTPUT: \u5904\u7406\u51fa\u7ad9\u6570\u636e\u5305&#xff0c;\u4e00\u822c\u4e0d\u5728\u6b64\u94fe\u4e0a\u505a\u914d\u7f6e\u3002 FORWARD: \u5904\u7406\u7ecf\u8fc7\u672c\u673a,\u4f46\u76ee\u7684\u5730\u4e0d\u662f\u672c\u673a\u7684\u6570\u636e\u5305&#xff08;\u8f6c\u53d1&#xff09;\u3002<\/p>\n<p>PREROUTING: \u5728\u8fdb\u884c\u8def\u7531\u9009\u62e9\u524d\u5904\u7406\u6570\u636e\u5305&#xff0c;\u7528\u6765\u4fee\u6539\u76ee\u7684\u5730\u5740&#xff0c;\u7528\u6765\u505aDNAT\u3002\u76f8\u5f53\u4e8e\u628a\u5185\u7f51\u670d\u52a1\u5668\u7684IP\u548c\u7aef\u53e3\u6620\u5c04\u5230\u8def\u7531\u5668\u7684\u5916\u7f51IP\u548c\u7aef\u53e3\u4e0a\u3002<\/p>\n<p>POSTROUTING: \u5728\u8fdb\u884c\u8def\u7531\u9009\u62e9\u540e\u5904\u7406\u6570\u636e\u5305&#xff0c;\u7528\u6765\u4fee\u6539\u6e90\u5730\u5740&#xff0c;\u7528\u6765\u505aSNAT\u3002\u76f8\u5f53\u4e8e\u5185\u7f51\u901a\u8fc7\u8def\u7531\u5668NAT\u8f6c\u6362\u529f\u80fd\u5b9e\u73b0\u5185\u7f51\u4e3b\u673a\u901a\u8fc7\u4e00\u4e2a\u516c\u7f51IP\u5730\u5740\u4e0a\u7f51\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134249-680256d995f9e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6570\u636e\u5305\u8fc7\u6ee4\u7684\u5339\u914d\u6d41\u7a0b \u4f18\u5148\u987a\u5e8f \u89c4\u5219\u8868\u5e94\u7528\u987a\u5e8f&#xff1a;raw\u2192mangle\u2192nat\u2192filter \u5165\u7ad9\u6570\u636e(\u6765\u81ea\u5916\u754c\u7684\u6570\u636e\u5305&#xff0c;\u4e14\u76ee\u6807\u5730\u5740\u662f\u9632\u706b\u5899\u672c\u673a) : PREROUTING &#8211;&gt; INPUT &#8211;&gt; \u672c\u673a\u7684\u5e94\u7528\u7a0b\u5e8f \u4ecepreouting\u8fdb\u5165,\u7136\u540e\u8def\u7531\u9009\u62e9\u5165\u7ad9\u8fdb\u5165input\u94fe<\/p>\n<p>\u51fa\u7ad9\u6570\u636e(\u4ece\u9632\u706b\u5899\u672c\u673a\u5411\u5916\u90e8\u5730\u5740\u53d1\u9001\u7684\u6570\u636e\u5305):\u672c\u673a\u7684\u5e94\u7528\u7a0b\u5e8f\u2013&gt;OUTPUT\u2013&gt;POSTROUTING \u4e3b\u673a\u901a\u8fc7output\u94fe\u51fa\u53d1,\u7ecf\u8fc7\u8def\u7531\u9009\u62e9\u6700\u4f73\u8def\u5f84,\u6700\u540e\u7ecf\u8fc7postrouting\u53d1\u51fa<\/p>\n<p>\u7f51\u7edc\u578b\u9632\u706b\u5899: \u8f6c\u53d1\u6570\u636e(\u9700\u8981\u7ecf\u8fc7\u9632\u706b\u5899\u8f6c\u53d1\u7684\u6570\u636e\u5305) : PREROUTING &#8211;&gt; FORWARD &#8211;&gt; POSTROUTING \u4ecepreouting\u8fdb\u5165,\u7136\u540e\u8def\u7531\u9009\u62e9\u8f6c\u53d1\u8fdb\u5165forward\u94fe,\u6700\u540e\u7531postrouting\u53d1\u51fa <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134250-680256da44f8a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u4e8c\u3001iptables\u547d\u4ee4<\/h2>\n<p>CentOS7\u9ed8\u8ba4\u4f7f\u7528firewalld\u9632\u706b\u5899&#xff0c;\u6ca1\u6709\u5b89\u88c5iptables,\u82e5\u60f3\u4f7f\u7528iptables\u9632\u706b\u5899\u3002\u5fc5\u987b\u5148\u5173\u95edfirewalld\u9632\u706b\u5899&#xff0c;\u518d\u5b89\u88c5iptables<\/p>\n<p>\u5173\u95edfirewalld\u9632\u706b\u5899<\/p>\n<p>systemctl stop firewalld.service systemctl disable firewalld.service<\/p>\n<p>\u5b89\u88c5iptables \u9632\u706b\u5899<\/p>\n<p>yum -y install iptables iptables-services<\/p>\n<p>\u8bbe\u7f6eiptables\u5f00\u673a\u542f\u52a8<\/p>\n<p>systemctl start iptables.service systemctl enable iptables.service<\/p>\n<p>iptables\u9632\u706b\u5899\u7684\u914d\u7f6e\u65b9\u6cd5: 1\u3001\u4f7f\u7528iptables\u547d\u4ee4\u884c\u3002 2\u3001\u4f7f\u7528system-config-firewall centso7\u4e0d\u80fd\u4f7f\u7528 centos 6\u53ef\u4ee5\u4f7f\u7528<\/p>\n<h3>1.\u8bed\u6cd5\u7ed3\u6784<\/h3>\n<p>iptables [-t \u8868\u540d] \u7ba1\u7406\u9009\u9879 [\u94fe\u540d][\u5339\u914d\u6761\u4ef6][-j \u63a7\u5236\u7c7b\u578b]<\/p>\n<p>\u6ce8\u610f\u4e8b\u9879&#xff1a; \u4e0d\u6307\u5b9a\u8868\u540d\u65f6&#xff0c;\u9ed8\u8ba4\u6307filter\u8868 \u4e0d\u6307\u5b9a\u94fe\u540d\u65f6&#xff0c;\u9ed8\u8ba4\u6307\u8868\u5185\u7684\u6240\u6709\u94fe \u9664\u975e\u8bbe\u7f6e\u94fe\u7684\u9ed8\u8ba4\u7b56\u7565&#xff0c;\u5426\u5219\u5fc5\u987b\u6307\u5b9a\u5339\u914d\u6761\u4ef6 \u9009\u9879\u3001\u94fe\u540d\u3001\u63a7\u5236\u7c7b\u578b\u4f7f\u7528\u5927\u5199\u5b57\u6bcd&#xff0c;\u5176\u4f59\u5747\u4e3a\u5c0f\u5199<\/p>\n<p>\u6570\u636e\u5305\u7684\u5e38\u89c1\u63a7\u5236\u7c7b\u578b(\u5fc5\u987b\u5927\u5199)<\/p>\n<ul>\n<li>ACCEPT&#xff1a;\u5141\u8bb8\u6570\u636e\u5305\u901a\u8fc7\u3002<\/li>\n<li>DROP&#xff1a;\u76f4\u63a5\u4e22\u5f03\u6570\u636e\u5305&#xff0c;\u4e0d\u7ed9\u51fa\u4efb\u4f55\u56de\u5e94\u4fe1\u606f\u3002<\/li>\n<li>REJECT&#xff1a;\u62d2\u7edd\u6570\u636e\u5305\u901a\u8fc7&#xff0c;\u5fc5\u8981\u65f6\u4f1a\u7ed9\u6570\u636e\u53d1\u9001\u7aef\u4e00\u4e2a\u54cd\u5e94\u4fe1\u606f\u3002<\/li>\n<li>LOG&#xff1a;\u5728\/var\/log\/messages \u6587\u4ef6\u4e2d\u8bb0\u5f55\u65e5\u5fd7\u4fe1\u606f&#xff0c;\u7136\u540e\u5c06\u6570\u636e\u5305\u4f20\u9012\u7ed9\u4e0b\u4e00\u6761\u89c4\u5219\u3002<\/li>\n<li>SNAT:\u4fee\u6539\u6570\u636e\u5305\u7684\u6e90\u5730\u5740\u3002<\/li>\n<li>DNAT:\u4fee\u6539\u6570\u636e\u5305\u7684\u76ee\u7684\u5730\u5740\u3002<\/li>\n<li>MASQUERADE:\u4f2a\u88c5\u6210\u4e00\u4e2a\u975e\u56fa\u5b9a\u516c\u7f51IP\u5730\u5740\u3002<\/li>\n<\/ul>\n<p>\u9632\u706b\u5899\u89c4\u5219\u7684\u201c\u5339\u914d\u5373\u505c\u6b62\u201d\u5bf9\u4e8e LOG \u64cd\u4f5c\u6765\u8bf4\u662f\u4e00\u4e2a\u7279\u4f8b&#xff0c;\u56e0\u4e3a LOG \u53ea\u662f\u4e00\u79cd\u8f85\u52a9\u52a8\u4f5c&#xff0c;\u5e76\u6ca1\u6709\u771f\u6b63\u5904\u7406\u6570\u636e\u5305\u3002<\/p>\n<h3>2.iptables \u547d\u4ee4\u7684\u5e38\u7528\u7ba1\u7406\u9009\u9879<\/h3>\n<table>\n<tr>\u7ba1\u7406\u9009\u9879\u7528\u6cd5\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>-A<\/td>\n<td>\u5728\u6307\u5b9a\u94fe\u672b\u5c3e\u8ffd\u52a0\u4e00\u6761 iptables -A INPUT &#xff08;\u64cd\u4f5c&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>-I<\/td>\n<td>\u5728\u6307\u5b9a\u94fe\u4e2d\u63d2\u5165\u4e00\u6761\u65b0\u7684&#xff0c;\u672a\u6307\u5b9a\u5e8f\u53f7\u9ed8\u8ba4\u4f5c\u4e3a\u7b2c\u4e00\u6761 iptables -I INPUT 3(\u5728\u7b2c\u4e09\u6761\u89c4\u5219\u524d\u9762\u6dfb\u52a0)<\/td>\n<\/tr>\n<tr>\n<td>-P<\/td>\n<td>\u6307\u5b9a\u9ed8\u8ba4\u89c4\u5219 iptables -P OUTPUT ACCEPT &#xff08;\u64cd\u4f5c&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>-D<\/td>\n<td>\u5220\u9664 iptables -t nat -D INPUT &#xff08;\u64cd\u4f5c&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>-R<\/td>\n<td>\u4fee\u6539\u3001\u66ff\u6362\u67d0\u4e00\u6761\u89c4\u5219 iptables -t nat -R INPUT &#xff08;\u64cd\u4f5c&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>-L<\/td>\n<td>\u67e5\u770b iptables -t nat -L &#xff08;\u67e5\u770b&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>-n<\/td>\n<td>\u6240\u6709\u5b57\u6bb5\u4ee5\u6570\u5b57\u5f62\u5f0f\u663e\u793a&#xff08;\u6bd4\u5982\u4efb\u610fip\u5730\u5740\u662f0.0.0.0\u800c\u4e0d\u662fanywhere&#xff0c;\u6bd4\u5982\u663e\u793a\u534f\u8bae\u7aef\u53e3\u53f7\u800c\u4e0d\u662f\u670d\u52a1\u540d&#xff09; iptables -L -n,iptables -nL,iptables -vnL &#xff08;\u67e5\u770b&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>-v<\/td>\n<td>\u67e5\u770b\u65f6\u663e\u793a\u66f4\u8be6\u7ec6\u4fe1\u606f&#xff0c;\u5e38\u8ddf-L\u4e00\u8d77\u4f7f\u7528 &#xff08;\u67e5\u770b&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u2013line-number<\/td>\n<td>\u89c4\u5219\u5e26\u7f16\u53f7 iptables -t nat -L -n &#8211;line-number \/iptables -t nat -L &#8211;line-number<\/td>\n<\/tr>\n<tr>\n<td>-F<\/td>\n<td>\u6e05\u9664\u94fe\u4e2d\u6240\u6709\u89c4\u5219 iptables -F &#xff08;\u64cd\u4f5c&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>-X<\/td>\n<td>\u6e05\u7a7a\u81ea\u5b9a\u4e49\u94fe\u7684\u89c4\u5219&#xff0c;\u4e0d\u5f71\u54cd\u5176\u4ed6\u94fe(\u5185\u7f6e\u94fe\u90fd\u4e0d\u53d7\u5f71\u54cd) iptables -X<\/td>\n<\/tr>\n<tr>\n<td>-Z<\/td>\n<td>\u6e05\u7a7a\u94fe\u7684\u8ba1\u6570\u5668&#xff08;\u5339\u914d\u5230\u7684\u6570\u636e\u5305\u7684\u5927\u5c0f\u548c\u603b\u548c&#xff09;iptables -Z<\/td>\n<\/tr>\n<tr>\n<td>-S<\/td>\n<td>\u67e5\u770b\u94fe\u7684\u6240\u6709\u89c4\u5219\u6216\u8005\u67d0\u4e2a\u94fe\u7684\u89c4\u5219\/\u67d0\u4e2a\u5177\u4f53\u89c4\u5219\u540e\u9762\u8ddf\u7f16\u53f7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>3.\u8bbe\u7f6e\u4fee\u6539\u540e\u7684\u89c4\u5219\u4fdd\u5b58\u548c\u6062\u590d<\/h3>\n<p>\u5728\u9ed8\u8ba4\u7684\u60c5\u51b5\u4e0b&#xff0c;\u6211\u4eec\u5bf9&#034;\u9632\u706b\u5899&#034;\u6240\u505a\u51fa\u7684\u4fee\u6539\u90fd\u662f&#034;\u4e34\u65f6\u7684&#034;&#xff0c;\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f&#xff0c;\u5f53\u91cd\u542fiptables\u670d\u52a1\u6216\u8005\u91cd\u542f\u670d\u52a1\u5668\u4ee5\u540e&#xff0c;\u6211\u4eec\u5e73\u5e38\u6dfb\u52a0\u7684\u89c4\u5219\u6216\u8005\u5bf9\u89c4\u5219\u6240\u505a\u51fa\u7684\u4fee\u6539\u90fd\u5c06\u6d88\u5931&#xff0c;\u4e3a\u4e86\u9632\u6b62\u8fd9\u79cd\u60c5\u51b5\u7684\u53d1\u751f&#xff0c;\u6211\u4eec\u9700\u8981\u5c06\u89c4\u5219&#034;\u4fdd\u5b58&#034;<\/p>\n<p>cp \/etc\/sysconfig\/iptables \/etc\/sysconfig\/iptables.bak    #\u521b\u5efa\u89c4\u5219\u96c6\u7684\u5907\u4efd<br \/>\niptables-save &gt; \/etc\/sysconfig\/iptables                   #\u4fdd\u5b58\u65b0\u89c4\u5219(\u5c31\u662f\u4fee\u6539\/etc\/sysconfig\/iptables\u6587\u4ef6)<\/p>\n<p>iptables-restore &lt; \/etc\/sysconfig\/iptables.bak            #\u4f7f\u7528\u5907\u4efd\u6587\u4ef6\u8fdb\u884c\u6062\u590d<\/p>\n<h3>4.iptables\u4fe1\u606f\u67e5\u8be2<\/h3>\n<p># filter\u8d1f\u8d23\u8fc7\u6ee4\u529f\u80fd&#xff0c;\u6bd4\u5982\u5141\u8bb8\u54ea\u4e9bIP\u5730\u5740\u8bbf\u95ee&#xff0c;\u62d2\u7edd\u54ea\u4e9bIP\u5730\u5740\u8bbf\u95ee&#xff0c;\u5141\u8bb8\u8bbf\u95ee\u54ea\u4e9b\u7aef\u53e3&#xff0c;\u7981\u6b62\u8bbf\u95ee\u54ea\u4e9b\u7aef\u53e3<br \/>\n# \u9ed8\u8ba4\u4e0d\u52a0-t\u5c31\u662f\u6307\u7684filter\u8868<br \/>\niptables -t filter -L<br \/>\niptables -t raw -L<br \/>\niptables -t mangle -L<br \/>\niptables -t nat -L<\/p>\n<p># -v\u662f\u663e\u793a\u8be6\u7ec6\u7684\u4fe1\u606f&#xff0c;\u5217\u51faINPUT\u94fe\u7684\u8be6\u7ec6\u4fe1\u606f<br \/>\niptables -vL INPUT<br \/>\n# \u4ee5\u6570\u5b57\u5f62\u5f0f\u663e\u793a\u5730\u5740\u548c\u7aef\u53e3\u4fe1\u606f<br \/>\niptables -nvL INPUT<br \/>\n# \u663e\u793a\u89c4\u5219\u7684\u5e8f\u53f7&#xff0c;&#8211;line-numbers\u9009\u9879\u8868\u793a\u663e\u793a\u89c4\u5219\u7684\u5e8f\u53f7&#xff0c;\u6ce8\u610f&#xff0c;\u6b64\u9009\u9879\u4e3a\u957f\u9009\u9879&#xff0c;\u4e0d\u80fd\u4e0e\u5176\u4ed6\u77ed\u9009\u9879\u5408\u5e76&#xff0c;\u4e0d\u8fc7\u6b64\u9009\u9879\u53ef\u4ee5\u7b80\u5199\u4e3a&#8211;line<br \/>\niptables &#8211;line-numbers -t \u8868\u540d -L<\/p>\n<p># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;\u663e\u793a\u754c\u9762\u89e3\u91ca&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Chain INPUT (policy ACCEPT 170M packets, 33G bytes)<br \/>\n# policy\u8868\u793a\u5f53\u524d\u94fe\u7684\u9ed8\u8ba4\u7b56\u7565&#xff0c;policy ACCEPT\u8868\u793aINPUT\u7684\u94fe\u7684\u9ed8\u8ba4\u52a8\u4f5c\u4e3aACCEPT&#xff0c;\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f&#xff0c;\u9ed8\u8ba4\u63a5\u53d7\u901a\u8fc7INPUT\u5173\u5361\u7684\u6240\u6709\u8bf7\u6c42&#xff0c;<br \/>\n\u6240\u4ee5\u6211\u4eec\u5728\u914d\u7f6eINPUT\u94fe\u7684\u5177\u4f53\u89c4\u5219\u65f6&#xff0c;\u5e94\u8be5\u5c06\u9700\u8981\u62d2\u7edd\u7684\u8bf7\u6c42\u914d\u7f6e\u5230\u89c4\u5219\u4e2d<br \/>\n# \u8bf4\u767d\u4e86\u5c31\u662f\u201d\u9ed1\u540d\u5355\u201d\u673a\u5236&#xff0c;\u9ed8\u8ba4\u6240\u6709\u4eba\u90fd\u80fd\u901a\u8fc7&#xff0c;\u53ea\u6709\u6307\u5b9a\u7684\u4eba\u4e0d\u80fd\u901a\u8fc7&#xff0c;\u5f53\u6211\u4eec\u628aINPUT\u94fe\u9ed8\u8ba4\u52a8\u4f5c\u8bbe\u7f6e\u4e3a\u63a5\u53d7(ACCEPT)&#xff0c;<br \/>\n\u5c31\u8868\u793a\u6240\u6709\u4eba\u90fd\u80fd\u901a\u8fc7\u8fd9\u4e2a\u5173\u5361&#xff0c;\u6b64\u65f6\u5c31\u5e94\u8be5\u5728\u5177\u4f53\u7684\u89c4\u5219\u4e2d\u6307\u5b9a\u9700\u8981\u62d2\u7edd\u7684\u8bf7\u6c42&#xff0c;\u5c31\u8868\u793a\u53ea\u6709\u6307\u5b9a\u7684\u4eba\u4e0d\u80fd\u901a\u8fc7\u8fd9\u4e2a\u5173\u5361&#xff0c;\u8fd9\u5c31\u662f\u9ed1\u540d\u5355\u673a\u5236<br \/>\n# packets\u8868\u793a\u5f53\u524d\u94fe&#xff08;\u4e0a\u4f8b\u4e3aINPUT\u94fe&#xff09;\u9ed8\u8ba4\u7b56\u7565\u5339\u914d\u5230\u7684\u5305\u7684\u6570\u91cf&#xff0c;0 packets\u8868\u793a\u9ed8\u8ba4\u7b56\u7565\u5339\u914d\u52300\u4e2a\u5305\u3002<br \/>\n# bytes\u8868\u793a\u5f53\u524d\u94fe\u9ed8\u8ba4\u7b56\u7565\u5339\u914d\u5230\u7684\u6240\u6709\u5305\u7684\u5927\u5c0f\u603b\u548c\u3002<br \/>\n# \u5176\u5b9e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u628apackets\u4e0ebytes\u79f0\u4f5c\u201d\u8ba1\u6570\u5668\u201d&#xff0c;\u4e0a\u56fe\u4e2d\u7684\u8ba1\u6570\u5668\u8bb0\u5f55\u4e86\u9ed8\u8ba4\u7b56\u7565\u5339\u914d\u5230\u7684\u62a5\u6587\u6570\u91cf\u4e0e\u603b\u5927\u5c0f&#xff0c;<br \/>\n\u201d\u8ba1\u6570\u5668\u201d\u53ea\u4f1a\u5728\u4f7f\u7528-v\u9009\u9879\u65f6&#xff0c;\u624d\u4f1a\u663e\u793a\u51fa\u6765<\/p>\n<p># pkts:\u5bf9\u5e94\u89c4\u5219\u5339\u914d\u5230\u7684\u62a5\u6587\u7684\u4e2a\u6570\u3002<br \/>\n# bytes:\u5bf9\u5e94\u5339\u914d\u5230\u7684\u62a5\u6587\u5305\u7684\u5927\u5c0f\u603b\u548c\u3002<br \/>\n# target:\u89c4\u5219\u5bf9\u5e94\u7684target&#xff0c;\u5f80\u5f80\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u201d\u52a8\u4f5c\u201d&#xff0c;\u5373\u89c4\u5219\u5339\u914d\u6210\u529f\u540e\u9700\u8981\u91c7\u53d6\u7684\u63aa\u65bd\u3002<br \/>\n# prot:\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u534f\u8bae&#xff0c;\u662f\u5426\u53ea\u9488\u5bf9\u67d0\u4e9b\u534f\u8bae\u5e94\u7528\u6b64\u89c4\u5219\u3002<br \/>\n# opt:\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u9009\u9879\u3002<br \/>\n# in:\u8868\u793a\u6570\u636e\u5305\u7531\u54ea\u4e2a\u63a5\u53e3(\u7f51\u5361)\u6d41\u5165&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6e\u901a\u8fc7\u54ea\u5757\u7f51\u5361\u6d41\u5165\u7684\u62a5\u6587\u9700\u8981\u5339\u914d\u5f53\u524d\u89c4\u5219\u3002<br \/>\n# out:\u8868\u793a\u6570\u636e\u5305\u5c06\u7531\u54ea\u4e2a\u63a5\u53e3(\u7f51\u5361)\u6d41\u51fa&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6e\u901a\u8fc7\u54ea\u5757\u7f51\u5361\u6d41\u51fa\u7684\u62a5\u6587\u9700\u8981\u5339\u914d\u5f53\u524d\u89c4\u5219\u3002<br \/>\n# source:\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u6e90\u5934\u5730\u5740&#xff0c;\u53ef\u4ee5\u662f\u4e00\u4e2aIP&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u7f51\u6bb5\u3002<br \/>\n# destination:\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u76ee\u6807\u5730\u5740\u3002\u53ef\u4ee5\u662f\u4e00\u4e2aIP&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u7f51\u6bb5<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134251-680256db030e8.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>5.\u89c4\u5219\u94fe\u5185\u7684\u5339\u914d\u987a\u5e8f:<\/h3>\n<p>\u81ea\u4e0a\u5411\u4e0b\u6309\u987a\u5e8f\u4f9d\u6b21\u8fdb\u884c\u68c0\u67e5&#xff0c;\u627e\u5230\u76f8\u5339\u914d\u7684\u89c4\u5219\u5373\u505c\u6b62(LOG\u7b56\u7565\u4f8b\u5916&#xff0c;\u8868\u793a\u8bb0\u5f55\u76f8\u5173\u65e5\u5fd7)\u8981\u4e48\u653e\u884c \u8981\u4e48\u4e22\u5f03 \u82e5\u5728\u8be5\u94fe\u5185\u627e\u4e0d\u5230\u76f8\u5339\u914d\u7684\u89c4\u5219&#xff0c;\u5219\u6309\u8be5\u94fe\u7684\u9ed8\u8ba4\u7b56\u7565\u5904\u7406(\u672a\u4fee\u6539\u7684\u72b6\u51b5\u4e0b&#xff0c;\u9ed8\u8ba4\u7b56\u7565\u4e3a\u5141\u8bb8)<\/p>\n<p>\u6ce8&#xff1a;\u6309\u7b2c\u4e00\u6761\u89c4\u5219\u2026\u2026\u7b2c\u4e8c\u6761\u89c4\u5219\u7684\u987a\u5e8f\u8fdb\u884c\u5339\u914d\u5904\u7406&#xff0c;\u9075\u5faa\u201c\u5339\u914d\u5373\u505c\u6b62\u201d\u7684\u539f\u5219&#xff0c; \u4e00\u65e6\u627e\u5230\u4e00\u6761\u5339\u914d\u89c4\u5219\u5c06\u4e0d\u518d\u68c0\u67e5\u540e\u7eed\u7684\u5176\u4ed6\u89c4\u5219&#xff0c;\u5982\u679c\u4e00\u76f4\u627e\u4e0d\u5230\u5339\u914d\u7684\u89c4\u5219&#xff0c;\u5c31\u6309\u9ed8\u8ba4\u89c4\u5219\u5904\u7406\u3002 \u9ed8\u8ba4\u89c4\u5219\u7528iptables -L\u67e5\u770b&#xff0c;\u89c4\u5219\u94fe\u540e\u9762\u51fa\u73b0(policy ACCEPT)\u5373\u662f\u9ed8\u8ba4\u653e\u884c \u9ed8\u8ba4\u7b56\u7565\u4e0d\u53c2\u4e0e\u94fe\u5185\u89c4\u5219\u7684\u987a\u5e8f\u7f16\u6392 -F\u6e05\u7a7a\u94fe\u65f6&#xff0c;\u9ed8\u8ba4\u7b56\u7565\u4e0d\u53d7\u5f71\u54cd<\/p>\n<h3>6.\u6dfb\u52a0\u65b0\u7684\u89c4\u5219<\/h3>\n<p>iptables -t filter -A INPUT -p icmp -j REJECT      #\u4e0d\u5141\u8bb8\u4efb\u4f55\u4e3b\u673aping\u672c\u4e3b\u673a,\u56e0\u4e3a\u6dfb\u52a0\u5728\u672b\u5c3e\u88ab\u524d\u9762\u7684\u89c4\u5219\u5339\u914d\u4e86\u6240\u4ee5\u4e0d\u751f\u6548<br \/>\niptables -t filter -I INPUT -p icmp -j REJECT      #\u6dfb\u52a0\u81f3\u5f00\u5934\u5c31\u53ef\u4ee5\u751f\u6548<\/p>\n<p>iptables -I  INPUT 2 -p tcp &#8211;dport 22 -j ACCEPT   #\u6240\u6709TCP\u6570\u636e\u5305&#xff0c;\u5982\u679c\u76ee\u6807\u7aef\u53e3\u4e3a22&#xff0c;\u90fd\u5c06\u88ab\u5141\u8bb8\u8fdb\u5165\u672c\u673a<br \/>\niptables -t filter -A INPUT -p tcp -j ACCEPT    \/\/\u5141\u8bb8\u4efb\u4f55\u4e3b\u673atcp<br \/>\niptables -I INPUT -p udp -j ACCEPT        \/\/\u5141\u8bb8\u4efb\u4f55\u4e3b\u673audp<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134251-680256db202a0.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>7.\u5220\u9664\u3001\u6e05\u7a7a\u89c4\u5219<\/h3>\n<p>1.\u5220\u9664\u4e00\u6761\u9632\u706b\u5899\u89c4\u5219\u65f6&#xff0c;\u4f7f\u7528\u7ba1\u7406\u9009\u9879\u201c-D\u201d\u3002\u4f8b\u5982&#xff0c;\u82e5\u8981\u5220\u9664 filter \u8868 INPUT \u94fe\u4e2d\u7684\u7b2c8\u6761\u89c4\u5219&#xff0c;\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u3002 iptables -D INPUT 8 \u6ce8\u610f: 1.\u82e5\u89c4\u5219\u5217\u8868\u4e2d\u6709\u591a\u6761\u76f8\u540c\u7684\u89c4\u5219\u65f6&#xff0c;\u6309\u5185\u5bb9\u5339\u914d\u53ea\u5220\u9664\u7684\u5e8f\u53f7\u6700\u5c0f\u7684\u4e00\u6761 2.\u6309\u53f7\u7801\u5339\u914d\u5220\u9664\u65f6&#xff0c;\u786e\u4fdd\u89c4\u5219\u53f7\u7801\u5c0f\u4e8e\u7b49\u4e8e\u5df2\u6709\u89c4\u5219\u6570&#xff0c;\u5426\u5219\u62a5\u9519 3.\u6309\u5185\u5bb9\u5339\u914d\u5220\u6570\u65f6&#xff0c;\u786e\u4fdd\u89c4\u5219\u5b58\u5728&#xff0c;\u5426\u5219\u62a5\u9519 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134251-680256db38e24.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>2.\u6e05\u7a7a\u6307\u5b9a\u94fe\u6216\u8868\u4e2d\u7684\u6240\u6709\u9632\u706b\u5899\u89c4\u5219 iptables -F INPUT \u6ce8\u610f: l.-F\u4ec5\u4ec5\u662f\u6e05\u7a7a\u94fe\u4e2d\u7684\u89c4\u5219&#xff0c;\u5e76\u4e0d\u5f71\u54cd-P\u8bbe\u7f6e\u7684\u9ed8\u8ba4\u89c4\u5219&#xff0c;\u9ed8\u8ba4\u89c4\u5219\u9700\u8981\u624b\u52a8\u8fdb\u884c\u4fee\u6539 2.-P\u8bbe\u7f6e\u4e86DROP\u540e(\u9ed8\u8ba4\u89c4\u5219\u4e3a\u4e22\u5f03)&#xff0c;\u4f7f\u7528-F \u4e00\u5b9a\u8981\u5c0f\u5fc3! \u9632\u6b62\u628a\u5141\u8bb8\u8fdc\u7a0b\u8fde\u63a5\u7684\u76f8\u5173\u89c4\u5219\u6e05\u9664\u540e\u5bfc\u81f4\u65e0\u6cd5\u8fdc\u7a0b\u8fde\u63a5\u4e3b\u673a&#xff0c;\u6b64\u60c5\u51b5\u5982\u679c\u6ca1\u6709\u4fdd\u5b58\u89c4\u5219\u53ef\u91cd\u542f\u4e3b\u673a\u89e3\u51b3 3.\u5982\u679c\u4e0d\u5199\u8868\u540d\u548c\u94fe\u540d&#xff0c;\u9ed8\u8ba4\u6e05\u7a7afilter\u8868\u4e2d\u6240\u6709\u94fe\u91cc\u7684\u6240\u6709\u89c4\u5219 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134251-680256db6b47c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>8.\u8bbe\u7f6e\u9ed8\u8ba4\u7b56\u7565<\/h3>\n<p>iptables \u7684\u5404\u6761\u94fe\u4e2d&#xff0c;\u9ed8\u8ba4\u7b56\u7565\u662f\u89c4\u5219\u5339\u914d\u7684\u6700\u540e\u4e00\u4e2a\u73af\u8282\u2014\u2014\u5f53\u627e\u4e0d\u5230\u4efb\u4f55\u4e00\u6761\u80fd\u591f\u5339\u914d\u6570\u636e\u5305\u7684\u89c4\u5219\u65f6&#xff0c;\u5219\u6267\u884c\u9ed8\u8ba4\u7b56\u7565\u3002\u9ed8\u8ba4\u7b56\u7565\u7684\u63a7\u5236\u7c7b\u578b\u4e3a ACCEPT&#xff08;\u5141\u8bb8&#xff09;\u3001DROP&#xff08;\u4e22\u5f03&#xff09;\u4e24\u79cd\u3002\u4f8b\u5982&#xff0c;\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u53ef\u4ee5\u5c06 filter \u8868\u4e2d FORWARD \u94fe\u7684\u9ed8\u8ba4\u7b56\u7565\u8bbe\u4e3a\u4e22\u5f03&#xff0c; OUTPUT \u94fe\u7684\u9ed8\u8ba4\u7b56\u7565\u8bbe\u4e3a\u5141\u8bb8\u3002<\/p>\n<p>iptables [-t\u8868\u540d] -P &lt;\u94fe\u540d&gt; &lt;\u63a7\u5236\u7c7b\u578b&gt;<br \/>\niptables -P INPUT DROP                            #\u8f93\u5165\u540e\u6ca1\u663e\u793a,\u6e05\u9664\u6240\u6709\u89c4\u5219\u4e4b\u540e\u751f\u6548&#xff0c;input\u9ed8\u8ba4\u89c4\u5219\u4e3a\u4e22\u5f03\u6570\u636e\u5305,\u9700\u8981\u767d\u540d\u5355<br \/>\niptables -I  INPUT 2 -p tcp &#8211;dport 22 -j ACCEPT  #\u9632\u6b62\u89c4\u5219\u88ab\u6e05\u7a7a,\u5bfc\u81f4\u8fdc\u7a0b\u8fde\u63a5\u88ab\u7981\u6b62<br \/>\niptables -F<br \/>\niptables -P FORWARD DROP <\/p>\n<p>#\u2013\u822c\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u8bbe\u7f6e\u7f51\u7edc\u578b\u9632\u706b\u5899\u3001\u4e3b\u673a\u578b\u9632\u706b\u5899\u65f6\u90fd\u8981\u8bbe\u7f6e\u9ed8\u8ba4\u89c4\u5219\u4e3aDROP&#xff0c;\u5e76\u8bbe\u7f6e\u767d\u540d\u5355<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u5f53\u4f7f\u7528\u7ba1\u7406\u9009\u9879\u201c-F\u201d\u6e05\u7a7a\u94fe\u65f6&#xff0c;\u9ed8\u8ba4\u7b56\u7565\u4e0d\u53d7\u5f71\u54cd\u3002\u56e0\u6b64\u82e5\u8981\u4fee\u6539\u9ed8\u8ba4 \u7b56\u7565&#xff0c;\u5fc5\u987b\u901a\u8fc7\u7ba1\u7406\u9009\u9879\u201c-P\u201d\u91cd\u65b0\u8fdb\u884c\u8bbe\u7f6e\u3002\u53e6\u5916&#xff0c;\u9ed8\u8ba4\u7b56\u7565\u5e76\u4e0d\u53c2\u4e0e\u94fe\u5185\u89c4\u5219\u7684\u987a\u5e8f\u7f16\u6392&#xff0c; \u56e0\u6b64\u5728\u5176\u4ed6\u89c4\u5219\u4e4b\u524d\u6216\u4e4b\u540e\u8bbe\u7f6e\u5e76\u65e0\u533a\u522b\u3002<\/p>\n<h3>9.\u89c4\u5219\u7684\u5339\u914d\u6761\u4ef6<\/h3>\n<p>\u5728\u7f16\u5199\u9632\u706b\u5899\u89c4\u5219\u65f6&#xff0c;\u5339\u914d\u6761\u4ef6\u7684\u8bbe\u7f6e\u8d77\u7740\u51b3\u5b9a\u6027\u7684\u4f5c\u7528\u3002\u53ea\u6709\u6e05\u6670\u3001\u51c6\u786e\u5730\u8bbe\u7f6e\u597d\u5339\u914d\u6761\u4ef6&#xff0c;\u9632\u706b\u5899\u624d\u77e5\u9053\u8981\u5bf9\u7b26\u5408\u4ec0\u4e48\u6761\u4ef6\u7684\u6570\u636e\u5305\u8fdb\u884c\u5904\u7406&#xff0c;\u907f\u514d\u201c\u8bef\u6740\u201d\u3002\u5bf9\u4e8e\u540c\u4e00\u6761\u9632\u706b\u5899\u89c4\u5219&#xff0c;\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\u5339\u914d\u6761\u4ef6&#xff0c;\u8868\u793a\u8fd9\u4e9b\u6761\u4ef6\u5fc5\u987b\u90fd\u6ee1\u8db3\u89c4\u5219\u624d\u4f1a\u751f\u6548\u3002\u6839\u636e\u6570\u636e\u5305\u7684\u5404\u79cd\u7279\u5f81&#xff0c;\u7ed3\u5408iptables\u7684\u6a21\u5757\u7ed3\u6784&#xff0c;\u5339\u914d\u6761\u4ef6\u7684\u8bbe\u7f6e\u5305\u62ec\u4e09\u5927\u7c7b&#xff1a;\u901a\u7528\u5339\u914d\u3001\u9690\u542b\u5339\u914d\u3001\u663e\u5f0f\u5339\u914d<\/p>\n<h4>9.1\u901a\u7528\u5339\u914d<\/h4>\n<p>\u901a\u7528\u5339\u914d\u4e5f\u79f0\u4e3a\u5e38\u89c4\u5339\u914d&#xff0c;\u8fd9\u79cd\u5339\u914d\u65b9\u5f0f\u53ef\u4ee5\u72ec\u7acb\u4f7f\u7528&#xff0c;\u4e0d\u4f9d\u8d56\u4e8e\u5176\u4ed6\u6761\u4ef6\u6216\u6269\u5c55\u6a21\u5757\u3002 \u5e38\u89c1\u7684\u901a\u7528\u5339\u914d\u5305\u62ec\u534f\u8bae\u5339\u914d\u3001\u5730\u5740\u5339\u914d\u3001\u7f51\u7edc\u63a5\u53e3\u5339\u914d\u3002<\/p>\n<p>\u53ef\u76f4\u63a5\u4f7f\u7528&#xff0c;\u4e0d\u4f9d\u8d56\u4e8e\u5176\u4ed6\u6761\u4ef6\u6216\u6269\u5c55&#xff0c;\u5305\u62ec\u7f51\u7edc\u534f\u8bae\u3001IP\u5730\u5740\u3001\u7f51\u7edc\u63a5\u53e3\u7b49\u6761\u4ef6\u3002 \u534f\u8bae\u5339\u914d: -p \u534f\u8bae\u540d \u5730\u5740\u5339\u914d:-s \u6e90\u5730\u5740\u3001-d\u76ee\u7684\u5730\u5740 #\u53ef\u4ee5\u662fIP\u3001\u7f51\u6bb5\u3001\u57df\u540d\u3001\u7a7a(\u4efb\u4f55\u5730\u5740) \u63a5\u53e3\u5339\u914d: -i\u5165\u7ad9\u7f51\u5361\u3001-o\u51fa\u7ad9\u7f51\u5361<\/p>\n<p>iptables -A FORWARD ! -p icmp -j ACCEPT<br \/>\n#\u5411 FORWARD \u94fe\u6dfb\u52a0\u4e00\u6761\u89c4\u5219,\u611f\u53f9\u53f7\u201d!\u201d\u8868\u793a\u53d6\u53cd,\u5373\u5339\u914d\u4e0d\u662f ICMP \u534f\u8bae\u7684\u6570\u636e\u5305,-j ACCEPT\u8868\u793a\u5141\u8bb8\u5b83\u4eec\u901a\u8fc7<\/p>\n<p>iptables -A INPUT -s 192.168.80.11 -j DROP<br \/>\n#\u5bf9INPUT\u94fe\u6240\u6709\u5339\u914d\u6e90\u5730\u5740\u4e3a192.168.80.11\u7684\u6570\u636e\u5305\u8fdb\u884c\u4e22\u5f03<\/p>\n<p>iptables -I INPUT -i ens33 -s 192.168.44.10\/24 -j DROP<br \/>\n#\u5bf9192.168.44.10\u7684ens33\u7f51\u5361\u7684\u6570\u636e\u5305\u8fdb\u884c\u4e22\u5f03<\/p>\n<p>iptables -I INPUT -p icmp -j DROP<br \/>\n#\u4e22\u5f03\u6240\u6709icmp\u7684\u6570\u636e\u5305<\/p>\n<p>iptables -I INPUT -p tcp &#8211;dport 22 -i ACCEPT<br \/>\n#\u5bf9\u76ee\u6807\u7aef\u53e3\u53f7\u4e3a22\u7684tcp\u534f\u8bae\u653e\u884c<\/p>\n<h4>9.2\u9690\u542b\u5339\u914d<\/h4>\n<p>\u8981\u6c42\u4ee5\u7279\u5b9a\u7684\u534f\u8bae\u5339\u914d\u4f5c\u4e3a\u524d\u63d0&#xff0c;\u5305\u62ec\u7aef\u53e3\u3001TCP\u6807\u8bb0\u3001ICMP\u7c7b\u578b\u7b49\u6761\u4ef6\u3002 \u7aef\u53e3\u5339\u914d: &#8211;sport \u6e90\u7aef\u53e3\u3001\u2013dport \u76ee\u7684\u7aef\u53e3 #\u53ef\u4ee5\u662f\u4e2a\u522b\u7aef\u53e3\u3001\u7aef\u53e3\u8303\u56f4 \u2013sport 1000 \u5339\u914d\u6e90\u7aef\u53e3\u662f1000\u7684\u6570\u636e\u5305 \u2013sport 1000:3000 \u5339\u914d\u6e90\u7aef\u53e3\u662f1000-3000\u7684\u6570\u636e\u5305 \u2013sport :3000 \u5339\u914d\u6e90\u7aef\u53e3\u662f3000\u53ca\u4ee5\u4e0b\u7684\u6570\u636e\u5305 \u2013sport 1000: \u5339\u914d\u6e90\u7aef\u53e3\u662f1000\u53ca\u4ee5\u4e0a\u7684\u6570\u636e\u5305 \u6ce8\u610f: &#8211;sport\u548c\u2013dport \u5fc5\u987b\u914d\u5408-p &lt;\u534f\u8bae\u7c7b\u578b&gt;\u4f7f\u7528<\/p>\n<p>iptables -A INPUT -p tcp &#8211;sport 1000:3000 -j REJECT<br \/>\n#\u62d2\u7edd\u6240\u6709\u6e90\u7aef\u53e3\u4e3a1000\u52303000\u7684tcp\u8bbf\u95ee<\/p>\n<p>iptables -A INPUT -p tcp &#8211;dport 20:21 -j ACCEPT<br \/>\n#\u63a5\u6536\u76ee\u6807\u7aef\u53e3\u662f20\u548c21\u7684tcp\u6570\u636e\u5305<\/p>\n<p>iptables -I FORWARD -d 192.168.80.0\/24 -p tcp &#8211;dport 24500:24600 -j DROP<br \/>\n#FORWARD\u4e22\u5f03\u6240\u6709\u76ee\u7684\u7aef\u53e3\u4e3a24500\u523024600\u7684\u524d\u5f80192.168.80.0\u7684tcp\u6570\u636e\u5305<\/p>\n<p>iptables -A FORWARD -s 192.168.4.0\/24 -p udp &#8211;dport 53 -j ACCEPT<br \/>\n#FORWARD\u63a5\u6536\u6e90\u5730\u5740192.168.4.0\u7684\u5b50\u7f51\u4e14\u76ee\u7684\u7aef\u53e3\u4e3a53\u7684\u7684udp\u6570\u636e\u5305(\u63a5\u6536192.168.4.0\u53d1\u51fa\u7684\u6570\u636e\u5305)<\/p>\n<p>iptables -A FORWARD -d 192.168.4.0\/24 -p udp &#8211;sport 53 -j ACCEPT<br \/>\n#FORWARD\u63a5\u6536\u76ee\u7684\u5730\u5740192.168.4.0\u7684\u5b50\u7f51\u4e14\u76ee\u7684\u7aef\u53e3\u4e3a53\u7684\u7684udp\u6570\u636e\u5305(\u63a5\u6536\u53d1\u5f80192.168.4.0\u7684\u6570\u636e\u5305)<\/p>\n<p>iptables -A INPUT -s 192.168.4.0\/24 -p tcp &#8211;dport 53 -j ACCEPT<br \/>\n#\u63a5\u6536\u6e90\u5730\u5740\u4e3a192.168.4.0\u7684\u5b50\u7f51\u7684\u76ee\u7684\u7aef\u53e353\u7684tcp\u6570\u636e\u5305<\/p>\n<h4>9.3\u663e\u5f0f\u5339\u914d<\/h4>\n<p>\u8981\u6c42\u4ee5\u201c-m\u6269\u5c55\u6a21\u5757\u201d\u7684\u5f62\u5f0f\u660e\u786e\u6307\u51fa\u7c7b\u578b&#xff0c;\u5305\u62ec\u591a\u7aef\u53e3\u3001MAC\u5730\u5740\u3001IP\u8303\u56f4\u3001\u6570\u636e\u5305\u72b6\u6001\u7b49\u6761\u4ef6\u3002<\/p>\n<p>\u591a\u7aef\u53e3\u5339\u914d: -m multiport &#8211;sport \u6e90\u7aef\u53e3\u5217\u8868 -m multiport &#8211;dport \u76ee\u7684\u7aef\u53e3\u5217\u8868<\/p>\n<p>iptables -A INPUT -p tcp -m multiport &#8211;dport 80,22,21,20,53 -j ACCEPT<br \/>\niptables -A INPUT -P udp -m multiport &#8211;dport 53 -j ACCEPT<\/p>\n<p>IP\u8303\u56f4\u5339\u914d: -m iprange &#8211;src-range IP\u8303\u56f4<\/p>\n<p>iptables -A FORWARD -p udp -m iprange &#8211;src-range 192.168.80.100-192.168.80.200 -j DROP<br \/>\n#\u7981\u6b62\u8f6c\u53d1\u6e90\u5730\u5740\u4f4d\u4e8e192.168.80.100-192.168.80.200\u7684udp\u6570\u636e\u5305<\/p>\n<p>MAC\u5730\u5740\u5339\u914d: -m mac &#8211;mac-source MAC\u5730\u5740<\/p>\n<p>iptables -A FORWARD -m mac &#8211;mac-source xx:xx:xx:xx:xx:xx -j DROP<br \/>\n#\u7981\u6b62\u6765\u81ea\u67d0MAC\u5730\u5740\u7684\u6570\u636e\u5305\u901a\u8fc7\u672c\u673a\u8f6c\u53d1<\/p>\n<p>\u72b6\u6001\u5339\u914d: -m state &#8211;state \u8fde\u63a5\u72b6\u6001 \u5e38\u89c1\u7684\u8fde\u63a5\u72b6\u6001: NEW :\u4e0e\u4efb\u4f55\u8fde\u63a5\u65e0\u5173\u7684&#xff0c;\u8fd8\u6ca1\u5f00\u59cb\u8fde\u63a5(\u5f53\u4e00\u4e2a\u5ba2\u6237\u7aef\u9996\u6b21\u5c1d\u8bd5\u5efa\u7acb\u5230\u670d\u52a1\u5668\u7684\u8fde\u63a5\u65f6&#xff0c;\u5b83\u662f\u4e00\u4e2a NEW \u72b6\u6001\u7684\u6570\u636e\u5305) ESTABLISHED :\u8868\u793a\u6570\u636e\u5305\u5c5e\u4e8e\u4e00\u4e2a\u5df2\u5efa\u7acb\u7684\u8fde\u63a5&#xff0c;\u5373\u8fde\u63a5\u5df2\u88ab\u6210\u529f\u5efa\u7acb&#xff0c;\u5e76\u4e14\u901a\u4fe1\u6b63\u5728\u8fdb\u884c\u4e2d RELATED :\u8868\u793a\u6570\u636e\u5305\u4e0e\u4e00\u4e2a\u5df2\u5efa\u7acb\u7684\u8fde\u63a5&#xff08;ESTABLISHED&#xff09;\u6709\u5173\u8054&#xff0c;\u4f46\u5b83\u4eec\u53ef\u80fd\u662f\u7531\u4e0d\u540c\u7684\u7aef\u53e3\u4e0a\u7684\u901a\u4fe1\u4ea7\u751f\u7684(\u5982FTP\u4e3b\u88ab\u52a8\u6a21\u5f0f\u7684\u6570\u636e\u8fde\u63a5) INVALID:\u4e0d\u80fd\u88ab\u8bc6\u522b\u5c5e\u4e8e\u54ea\u4e2a\u8fde\u63a5\u6216\u6ca1\u6709\u4efb\u4f55\u72b6\u6001,INVALID \u72b6\u6001\u53ef\u80fd\u8868\u660e\u5b58\u5728\u95ee\u9898&#xff0c;\u5982\u7f51\u7edc\u9519\u8bef\u3001\u6076\u610f\u6570\u636e\u5305\u6216\u72b6\u6001\u8ddf\u8e2a\u673a\u5236\u7684\u6545\u969c\u3002<\/p>\n<p>iptables -A FORWARD -m state &#8211;state NEW -p tcp ! &#8211;syn -j DROP<br \/>\n#\u7981\u6b62\u5904\u4e8enew\u72b6\u6001\u5374\u4e0d\u5e26\u6709syn\u7684\u6570\u636e\u5305\u8f6c\u53d1(\u5982\u4f2a\u9020\u7684\u7f51\u7edc\u653b\u51fb\u6570\u636e\u5305)<br \/>\n#\u4e5f\u53ef\u4ee5\u7406\u89e3\u4e3a\u7981\u6b62\u8f6c\u53d1\u4e0e\u6b63\u5e38TCP\u8fde\u63a5\u65e0\u5173\u7684\u975e&#8211;syn\u8bf7\u6c42\u6570\u636e\u5305<br \/>\n#\u4e00\u4e2a\u6b63\u5e38\u7684\u65b0 TCP \u8fde\u63a5\u5c1d\u8bd5\u7684\u7b2c\u4e00\u4e2a\u6570\u636e\u5305\u4f1a\u5e26\u6709 SYN \u6807\u5fd7\u4f4d\u8bbe\u7f6e<\/p>\n<p>iptables -A INPUT -p tcp -m state &#8211;state ESTABLISHED, RELATED -j ACCEPT<br \/>\n#\u63a5\u6536ESTABLISHED, RELATED\u72b6\u6001\u7684tcp\u6570\u636e\u5305<br \/>\n#\u5bf9\u8fdb\u6765\u7684\u5305\u7684\u72b6\u6001\u8fdb\u884c\u68c0\u6d4b\u3002\u5df2\u7ecf\u5efa\u7acbtcp\u8fde\u63a5\u7684\u5305\u4ee5\u53ca\u8be5\u8fde\u63a5\u76f8\u5173\u7684\u5305\u5141\u8bb8\u901a\u8fc7\u3002<br \/>\n#\u6bd4\u5982\u6211\u548c\u4f60\u505a\u751f\u610f&#xff0c;\u6211\u4eec\u8c08\u6210\u4e86\u751f\u610f&#xff0c;\u5230\u4e86\u652f\u4ed8\u7684\u65f6\u5019&#xff0c;\u5c31\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u4e0e\u8fd9\u7b14\u751f\u610f\u76f8\u5173\u7684\u652f\u4ed8\u529f\u80fd<br \/>\niptables -P INPUT DROP<\/p>\n<h4>9.4\u6269\u5c55\u63a7\u5236\u4f4d(\u4e86\u89e3)<\/h4>\n<p>TCP\u6807\u8bb0\u5339\u914d: &#8211;tcp-flags TCP\u6807\u8bb0 iptables -I INPUT -i ens33 -p tcp &#8211;tcp-flags SYN,RST,ACK SYN -j ACCEPT #\u4e22\u5f03SYN\u8bf7\u6c42\u5305&#xff0c;\u653e\u884c\u5176\u4ed6\u5305<\/p>\n<p>ICMP\u7c7b\u578b\u5339\u914d: &#8211;icmp-type ICMP\u7c7b\u578b #\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u4ee3\u7801 \u201cEcho- Request\u201d (\u4ee3\u7801\u4e3a8)\u8868\u793a\u8bf7\u6c42 \u201cEcho- Reply\u201d (\u4ee3\u7801\u4e3a0)\u8868\u793a\u56de\u663e \u201cDest ination-Unreachable\u201d (\u4ee3\u7801\u4e3a3)\u8868\u793a\u76ee\u6807\u4e0d\u53ef\u8fbe \u5173\u4e8e\u5176\u5b83\u53ef\u7528\u7684ICMP\u534f\u8bae\u7c7b\u578b&#xff0c;\u53ef\u4ee5\u6267\u884c\u201ciptables -p icmp -h\u201d\u547d\u4ee4&#xff0c;\u67e5\u770b\u5e2e\u52a9\u4fe1\u606f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.5k\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf28\u6b21\u3002Linux\u9632\u706b\u5899\u662f\u7531Netfilter\u7ec4\u4ef6\u63d0\u4f9b\u7684\uff0cNetfilter\u5de5\u4f5c\u5728\u5185\u6838\u7a7a\u95f4\uff0c\u96c6\u6210\u5728linux\u5185\u6838\u4e2dNetfilter \u662fLinux 2.4.x\u4e4b\u540e\u65b0\u4e00\u4ee3\u7684Linux\u9632\u706b\u5899\u673a\u5236\uff0c\u662flinux\u5185\u6838\u7684\u4e00\u4e2a\u5b50\u7cfb\u7edf\u3002Netfilter\u91c7\u7528\u6a21\u5757\u5316\u8bbe\u8ba1\uff0c\u5177\u6709\u826f\u597d\u7684\u53ef\u6269\u5145\u6027\uff0c\u63d0\u4f9b\u6269\u5c55\u5404\u79cd\u7f51\u7edc\u670d\u52a1\u7684\u7ed3\u6784\u5316\u5e95\u5c42\u6846\u67b6\u3002Netfilter\u4e0eIP\u534f\u8bae\u6808\u662f\u65e0\u7f1d\u5951\u5408\uff0c\u5e76\u5141\u8bb8\u5bf9\u6570\u636e\u62a5\u8fdb\u884c\u8fc7\u6ee4\u3001\u5730\u5740\u8f6c\u6362\u3001\u5904\u7406\u7b49\u64cd\u4f5c\u3002_linux iptables<\/p>\n","protected":false},"author":2,"featured_media":15073,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,43,78],"topic":[],"class_list":["post-15079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-linux","tag-43","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux\u7cfb\u7edfiptables - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/15079.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux\u7cfb\u7edfiptables - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.5k\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf28\u6b21\u3002Linux\u9632\u706b\u5899\u662f\u7531Netfilter\u7ec4\u4ef6\u63d0\u4f9b\u7684\uff0cNetfilter\u5de5\u4f5c\u5728\u5185\u6838\u7a7a\u95f4\uff0c\u96c6\u6210\u5728linux\u5185\u6838\u4e2dNetfilter \u662fLinux 2.4.x\u4e4b\u540e\u65b0\u4e00\u4ee3\u7684Linux\u9632\u706b\u5899\u673a\u5236\uff0c\u662flinux\u5185\u6838\u7684\u4e00\u4e2a\u5b50\u7cfb\u7edf\u3002Netfilter\u91c7\u7528\u6a21\u5757\u5316\u8bbe\u8ba1\uff0c\u5177\u6709\u826f\u597d\u7684\u53ef\u6269\u5145\u6027\uff0c\u63d0\u4f9b\u6269\u5c55\u5404\u79cd\u7f51\u7edc\u670d\u52a1\u7684\u7ed3\u6784\u5316\u5e95\u5c42\u6846\u67b6\u3002Netfilter\u4e0eIP\u534f\u8bae\u6808\u662f\u65e0\u7f1d\u5951\u5408\uff0c\u5e76\u5141\u8bb8\u5bf9\u6570\u636e\u62a5\u8fdb\u884c\u8fc7\u6ee4\u3001\u5730\u5740\u8f6c\u6362\u3001\u5904\u7406\u7b49\u64cd\u4f5c\u3002_linux iptables\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/15079.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T13:42:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134249-680256d995f9e.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/15079.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/15079.html\",\"name\":\"Linux\u7cfb\u7edfiptables - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T13:42:52+00:00\",\"dateModified\":\"2025-04-18T13:42:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/15079.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/15079.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/15079.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\u7cfb\u7edfiptables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux\u7cfb\u7edfiptables - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/15079.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux\u7cfb\u7edfiptables - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.5k\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf28\u6b21\u3002Linux\u9632\u706b\u5899\u662f\u7531Netfilter\u7ec4\u4ef6\u63d0\u4f9b\u7684\uff0cNetfilter\u5de5\u4f5c\u5728\u5185\u6838\u7a7a\u95f4\uff0c\u96c6\u6210\u5728linux\u5185\u6838\u4e2dNetfilter \u662fLinux 2.4.x\u4e4b\u540e\u65b0\u4e00\u4ee3\u7684Linux\u9632\u706b\u5899\u673a\u5236\uff0c\u662flinux\u5185\u6838\u7684\u4e00\u4e2a\u5b50\u7cfb\u7edf\u3002Netfilter\u91c7\u7528\u6a21\u5757\u5316\u8bbe\u8ba1\uff0c\u5177\u6709\u826f\u597d\u7684\u53ef\u6269\u5145\u6027\uff0c\u63d0\u4f9b\u6269\u5c55\u5404\u79cd\u7f51\u7edc\u670d\u52a1\u7684\u7ed3\u6784\u5316\u5e95\u5c42\u6846\u67b6\u3002Netfilter\u4e0eIP\u534f\u8bae\u6808\u662f\u65e0\u7f1d\u5951\u5408\uff0c\u5e76\u5141\u8bb8\u5bf9\u6570\u636e\u62a5\u8fdb\u884c\u8fc7\u6ee4\u3001\u5730\u5740\u8f6c\u6362\u3001\u5904\u7406\u7b49\u64cd\u4f5c\u3002_linux iptables","og_url":"https:\/\/www.wsisp.com\/helps\/15079.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T13:42:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418134249-680256d995f9e.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/15079.html","url":"https:\/\/www.wsisp.com\/helps\/15079.html","name":"Linux\u7cfb\u7edfiptables - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T13:42:52+00:00","dateModified":"2025-04-18T13:42:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/15079.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/15079.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/15079.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux\u7cfb\u7edfiptables"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/15079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=15079"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/15079\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/15073"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=15079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=15079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=15079"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=15079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}