{"id":4591,"date":"2023-05-10T19:39:16","date_gmt":"2023-05-10T11:39:16","guid":{"rendered":"https:\/\/blog.coderfan.org\/?p=4591"},"modified":"2023-06-12T11:36:03","modified_gmt":"2023-06-12T03:36:03","slug":"iptables-usage","status":"publish","type":"post","link":"https:\/\/blog.coderfan.org\/en\/iptables-usage.html","title":{"rendered":"Iptables\u4f7f\u7528\u8bb0\u5f55"},"content":{"rendered":"<div class='booster-block booster-read-block'>\n                <div class=\"twp-read-time\">\n                \t<i class=\"booster-icon twp-clock\"><\/i> <span>Read Time:<\/span>8 Minute, 6 Second                <\/div>\n\n            <\/div>\n<h4 class=\"wp-block-heading\">\u7b80\u4ecb<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">Iptables\u662fLinux\u5e73\u53f0\u4e0b\u901a\u7528\u7684\u5305\u8fc7\u6ee4\u9632\u706b\u5899\uff0c\u53ef\u4ee5\u5b8c\u6210\u5c01\u5305\u8fc7\u6ee4\u3001\u5c01\u5305\u91cd\u5b9a\u5411\u548c\u7f51\u7edc\u5730\u5740\u8f6c\u6362\uff08NAT\uff09\u7b49\u529f\u80fd\u3002Iptables\u672c\u8eab\u662f\u5bf9\u5185\u6838netfilter\u6a21\u5757\u7684\u5c01\u88c5\uff0c\u4fbf\u4e8e\u7528\u6237\u6001\u7a0b\u5e8f\u64cd\u4f5c\u9632\u706b\u5899\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u56db\u8868\u4e94\u94fe<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u56db\u8868\u6307\u7684\u662f\uff1a<strong>filter\u3001nat\u3001mangle\u3001raw<\/strong>\uff0c\u5176\u4e2dfilter\u8868\u8d1f\u8d23\u8fc7\u6ee4\u529f\u80fd\uff0c\u4e5f\u5c31\u662f\u9632\u706b\u5899\u914d\u7f6e\uff1bnat\u8868\uff0c\u4e5f\u5c31\u662fnetwork address translation\uff0c\u7f51\u7edc\u5730\u5740\u8f6c\u6362\uff1bmangle\u8868\u8d1f\u8d23\u62c6\u89e3\u62a5\u6587\uff0c\u505a\u51fa\u4fee\u6539\uff08\u5982TTL,Qos\u914d\u7f6e\u7b49\u4fe1\u606f\uff09\u5e76\u91cd\u65b0\u5c01\u88c5\uff1braw\u8868\uff0c\u8d1f\u8d23\u5173\u95ednat\u8868\u4e0a\u542f\u7528\u7684\u8fde\u63a5\u8ffd\u8e2a\u673a\u5236\u3002<\/p>\n\n\n\n<p>\u4e94\u94fe\u6307\u7684\u662f\uff1aPREROUTING\u3001INPUT\u3001FORWARD\u3001OUTPUT\u3001POSTROUTING<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u8868\u4e0e\u94fe\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\u8868\u662f\u4e00\u4e2a\u4e00\u4e2a\u9762\uff0c\u800c\u94fe\u5219\u662f\u7a7f\u8d8a\u8fd9\u4e9b\u9762\u5c06\u9762\u8fde\u63a5\u3002\u5728\u8868\u4e0e\u94fe\u4e2d\uff0c\u771f\u6b63\u8d77\u5230\u4f5c\u7528\u7684\u5219\u662f\u89c4\u5219\u3002\u6211\u4eec\u5728\u8868\u4e2d\u53ef\u4ee5\u4fee\u6539TCP\/IP\u5305\u5934\u7684\u4e0d\u540c\u4f4d\u7f6e\uff0c\u5728\u94fe\u4e2d\u6267\u884c\u4e3a\u5305\u88ab\u8def\u7531\u8f6c\u6362\u7684\u4e0d\u540c\u9636\u6bb5\u3002\u89c4\u5219\u662f\u5177\u4f53\u7684\u884c\u4e3a\u903b\u8f91\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u5e76\u4e0d\u662f\u6240\u6709\u7684\u94fe\u90fd\u8d2f\u7a7f\u4e86\u4e0a\u8ff0\u56db\u8868\uff0c\u67d0\u4e9b\u8868\u4e2d\u53ea\u80fd\u5305\u542b\u7279\u5b9a\u7684\u67d0\u4e9b\u94fe\uff0c\u4e0b\u9762\u7b80\u5355\u4f5c\u4e2a\u5217\u8868\u5f52\u7eb3\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\u94fe<\/td><td>\u8868<\/td><\/tr><tr><td>PREROUTING &nbsp; <\/td><td>raw,mangle,nat<\/td><\/tr><tr><td>INPUT<\/td><td>mangle,filter,nat<\/td><\/tr><tr><td>FORWARD<\/td><td>mangle,filter<\/td><\/tr><tr><td>OUTPUT<\/td><td>raw,mangle,filter,nat<\/td><\/tr><tr><td>POSTROUTING<\/td><td>mangle,nat<\/td><\/tr><\/tbody><\/table><figcaption>\u6ce8\uff1a\u4e0d\u540c\u7684\u7cfb\u7edf\u4e4b\u95f4\u53ef\u80fd\u4f1a\u5b58\u5728\u5dee\u5f02<\/figcaption><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">\u5173\u4e8e\u89c4\u5219\uff0c\u5177\u4f53\u7684\u52a8\u4f5c\u5305\u62ec\uff1aACCEPT(\u63a5\u53d7)\u3001REJECT\uff08\u62d2\u7edd\u4f46\u4f1a\u56de\u590d\u88ab\u62d2\u7edd\u7684\u539f\u56e0\uff09\u3001DROP\uff08\u76f4\u63a5\u4e22\u5f03\u65e0\u54cd\u5e94\uff09\u3001REDIRECT(\u7aef\u53e3\u91cd\u5b9a\u5411)\u3001MASQUERADE(\u6e90\u5730\u5740\u52a8\u6001\u4f2a\u88c5)\u3001LOG\uff08\u8bb0\u5f55\u65e5\u5fd7\u800c\u540e\u5411\u4e0b\u5339\u914d\u89c4\u5219\uff09\u3001DNAT(\u76ee\u7684IP\u8f6c\u6362)\u3001SNAT\uff08\u6e90IP\u8f6c\u6362\uff09\u7b49\u3002\u4ee5\u4e0b\u662f\u89c4\u5219\u5339\u914d\u4e2d\u7684\u4e00\u4e9b\u5e38\u7528\u53c2\u6570\u8868\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\u53c2\u6570<\/td><td>\u7528\u9014<\/td><\/tr><tr><td>-i<\/td><td>\u6307\u5b9a\u5165\u7ad9\u7684network interface<\/td><\/tr><tr><td>-o<\/td><td> \u6307\u5b9a\u51fa\u7ad9\u7684network interface <\/td><\/tr><tr><td>-p<\/td><td>\u6307\u5b9a\u5339\u914d\u7684\u534f\u8bae,\u5982tcp\/udp\/icmp<\/td><\/tr><tr><td>-s<\/td><td>\u6307\u5b9a\u6e90IP<\/td><\/tr><tr><td>-d<\/td><td>\u6307\u5b9a\u76ee\u6807IP<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6570\u636e\u5305\u7ecf\u8fc7\u9632\u706b\u5899\u65f6\u7684\u6570\u636e\u6d41\u5411\u53ef\u4ee5\u53c2\u8003\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"456\" src=\"https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/image.png\" alt=\"\" class=\"wp-image-4601\" srcset=\"https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/image.png 865w, https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/image-300x158.png 300w, https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/image-768x405.png 768w, https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/image-18x9.png 18w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">\u5982\u679c\u6570\u636e\u5305\u9700\u8981\u7ecf\u8fc7\u4e0a\u5c42\u5904\u7406\uff1a\u6d41\u91cf-&gt;PREROUTING-&gt;INPUT-&gt;Application-&gt;OUTPUT-&gt;POSTROUTING\uff1b\u5982\u679c\u6570\u636e\u4e0d\u9700\u8981\u7ecf\u8fc7\u4e0a\u5c42\u5904\u7406\uff0c\u5355\u7eaf\u8f6c\u53d1\uff1a\u6d41\u91cf-&gt;PREROUTING-&gt;FORWARD-&gt;POSTROUTING.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5217\u51fa\u89c4\u5219<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">Iptables\u547d\u4ee4\u914d\u7f6e\u53c2\u6570\u4e2d\u9075\u5b88\u201c\u8868-&gt;\u94fe-&gt;\u89c4\u5219\u201c\u3002\u5982\u679c\u6211\u4eec\u9700\u8981\u67e5\u770b\u6240\u6709\u7684iptables\u914d\u7f6e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">root@bstcd-OptiPlex-7090:~# iptables --list -n\nChain INPUT (policy ACCEPT)\ntarget     prot opt source               destination         \n\nChain FORWARD (policy ACCEPT)\ntarget     prot opt source               destination         \n\nChain OUTPUT (policy ACCEPT)\ntarget     prot opt source               destination         \nroot@bstcd-OptiPlex-7090:~# <\/code><\/pre>\n\n\n\n<p><strong>\u5217\u51fa\u67d0\u4e2a\u8868\u4e0a\u7684\u89c4\u5219<\/strong>\uff1aiptables -t +\u8868\u540d &nbsp;-L,\u8868\u540d\u5728\u7f3a\u7701\u60c5\u51b5\u4e0b\u9ed8\u8ba4\u4e3afilter\u8868<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">trout_x86:\/ # iptables -t filter -L                                                                                                                                                                      \nChain INPUT (policy ACCEPT)\ntarget     prot opt source               destination         \nbw_INPUT   all  --  anywhere             anywhere            \nfw_INPUT   all  --  anywhere             anywhere            \n\nChain FORWARD (policy ACCEPT)\ntarget     prot opt source               destination         \noem_fwd    all  --  anywhere             anywhere            \nfw_FORWARD  all  --  anywhere             anywhere            \nbw_FORWARD  all  --  anywhere             anywhere            \ntetherctrl_FORWARD  all  --  anywhere             anywhere            \n\nChain OUTPUT (policy ACCEPT)\ntarget     prot opt source               destination         \noem_out    all  --  anywhere             anywhere            \nfw_OUTPUT  all  --  anywhere             anywhere            \nst_OUTPUT  all  --  anywhere             anywhere            \nbw_OUTPUT  all  --  anywhere             anywhere  <\/code><\/pre>\n\n\n\n<p><strong>\u5217\u51fa\u67d0\u4e2a\u8868\u4e0a\u67d0\u4e2a\u94fe\u7684\u6240\u6709\u89c4\u5219<\/strong>\uff1aiptables -t +\u8868\u540d -L +\u94fe\u540d<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">trout_x86:\/ # iptables -t filter -L INPUT                                                                                                                                                                  \nChain INPUT (policy ACCEPT)\ntarget     prot opt source               destination         \nbw_INPUT   all  --  anywhere             anywhere            \nfw_INPUT   all  --  anywhere             anywhere            \ntrout_x86:\/ # iptables -t filter -L OUTPUT                                                                                                                                                                 \nChain OUTPUT (policy ACCEPT)\ntarget     prot opt source               destination         \noem_out    all  --  anywhere             anywhere            \nfw_OUTPUT  all  --  anywhere             anywhere            \nst_OUTPUT  all  --  anywhere             anywhere            \nbw_OUTPUT  all  --  anywhere             anywhere            \ntrout_x86:\/ # <\/code><\/pre>\n\n\n\n<p>\u540c\u65f6\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528-v\u53c2\u6570\u67e5\u770b\u5b8c\u6574\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">trout_x86:\/ # iptables -t filter -L OUTPUT                                                                                                                                                                 \nChain OUTPUT (policy ACCEPT)\ntarget     prot opt source               destination         \noem_out    all  --  anywhere             anywhere            \nfw_OUTPUT  all  --  anywhere             anywhere            \nst_OUTPUT  all  --  anywhere             anywhere            \nbw_OUTPUT  all  --  anywhere             anywhere            \ntrout_x86:\/ # iptables -t filter -vL OUTPUT                                                                                                                                                                \nChain OUTPUT (policy ACCEPT 33733 packets, 6488K bytes)\n pkts bytes target     prot opt in     out     source               destination         \n33749 6490K oem_out    all  --  any    any     anywhere             anywhere            \n33749 6490K fw_OUTPUT  all  --  any    any     anywhere             anywhere            \n33749 6490K st_OUTPUT  all  --  any    any     anywhere             anywhere            \n33749 6490K bw_OUTPUT  all  --  any    any     anywhere             anywhere            \ntrout_x86:\/ # <\/code><\/pre>\n\n\n\n<p>\u6bcf\u4e00\u5217\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n<p>pkts:\u5bf9\u5e94\u89c4\u5219\u5339\u914d\u5230\u7684\u62a5\u6587\u7684\u4e2a\u6570<\/p>\n\n\n\n<p>bytes:\u5bf9\u5e94\u5339\u914d\u5230\u7684\u62a5\u6587\u5305\u7684\u5927\u5c0f\u603b\u548c<\/p>\n\n\n\n<p>target:\u89c4\u5219\u5bf9\u5e94\u7684target\uff0c\u5f80\u5f80\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u52a8\u4f5c<\/p>\n\n\n\n<p>prot\uff1a\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u534f\u8bae\uff0c\u662f\u5426\u4ec5\u9488\u5bf9\u67d0\u4e9b\u534f\u8bae\u5e94\u7528\u6b64\u89c4\u5219<\/p>\n\n\n\n<p>opt\uff1a\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u9009\u9879<\/p>\n\n\n\n<p>in\uff1a\u8868\u793a\u6570\u636e\u5305\u7531\u54ea\u4e2a\u7f51\u5361\u6d41\u5165<\/p>\n\n\n\n<p>out\uff1a\u8868\u793a\u6570\u636e\u5305\u4ece\u54ea\u4e2a\u7f51\u5361\u6d41\u51fa<\/p>\n\n\n\n<p>source\uff1a\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u6e90\u5730\u5740\uff0c\u53ef\u4ee5\u662fIP\u4e5f\u53ef\u4ee5\u4e00\u4e2a\u7f51\u6bb5<\/p>\n\n\n\n<p class=\"has-text-align-justify\">destination\uff1a\u8868\u793a\u89c4\u5219\u5bf9\u5e94\u7684\u76ee\u6807\u5730\u5740\uff0c\u53ef\u4ee5\u662fIP\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u7f51\u6bb5<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u8fd9\u4e9b\u5217\u7684\u6700\u4e0a\u65b9\uff0cChain OUTPUT\u610f\u5473\u7740\u8fd9\u662f\u5c5e\u4e8eOUTPUT\u94fe\u7684\u89c4\u5219,policy drop\u610f\u5473\u7740\u9ed8\u8ba4\u7684\u89c4\u5219\u4e3aACCEPT.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6dfb\u52a0\u89c4\u5219<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u4e0a\u9762\u7684\u5185\u5bb9\u4e3a\u67e5\u770biptables\u7684\u89c4\u5219\uff0c\u5b9e\u9645\u4e0a\u662f\u901a\u8fc7-L\u6765\u5217\u51fa\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u8bb2\u8bb2\u5982\u4f55\u6dfb\u52a0\u89c4\u5219\u3002\u8fd9\u91cc\u6dfb\u52a0\u89c4\u5219\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1ainsert\u4e0eappend\u3002\u5176\u4e2dinsert\u53ef\u4ee5\u6307\u5b9a\u89c4\u5219\u987a\u5e8f\uff0c\u672a\u6307\u5b9a\u7684\u60c5\u51b5\u4e0b\u5c06\u4f1a\u5c06\u89c4\u5219\u81f3\u4e8e\u94fe\u5f00\u5934\uff1b\u800cappend\u5219\u662f\u5728\u94fe\u672b\u5c3e\u8fdb\u884c\u8ffd\u52a0\u3002\u7531\u4e8e\u89c4\u5219\u5224\u65ad\u662f\u81ea\u4e0a\u800c\u4e0b\u8fdb\u884c\u7684\uff0c\u6240\u4ee5\u94fe\u5934\u7684\u89c4\u5219\u5177\u6709\u66f4\u9ad8\u7684\u4f18\u5148\u7ea7\uff0c\u8fd9\u4e00\u70b9\u9700\u8981\u6ce8\u610f\u3002<\/p>\n\n\n\n<p>\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -I INPUT -s  192.168.1.146 -j DROP<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d,-t\u7528\u4e8e\u6307\u5b9a\u54ea\u4e2a\u8868,-t filter\u8868\u660e\u7528\u4e8e\u6307\u5b9afilter\u8868\uff0c-I\u7528\u4e8einsert\u63d2\u5165,-I INPUT\u8868\u660e\u5728INPUT\u94fe\u4e2d\u8fdb\u884c\u63d2\u5165\uff0c-s\u8868\u660e\u9002\u7528\u4e8e\u8be5\u89c4\u5219\u7684\u6e90\u5730\u5740\uff0c-j\u8868\u793a\u8be5\u89c4\u5219\u5177\u4f53\u7684\u52a8\u4f5c\uff0c\u4e00\u822c\u5e38\u7528\u7684\u52a8\u4f5c\u6709ACCEPT,REJECT,DROP\u7b49\u3002<\/p>\n\n\n\n<p>\u5728\u6b64\u5904\u672a\u6307\u5b9a\u4f4d\u7f6e\u987a\u5e8f\uff0c\u6240\u4ee5\u662f\u5728INPUT\u94fe\u5934\u6dfb\u52a0\u89c4\u5219\u3002\u4e0b\u9762\u6211\u4eec\u770b\u4e00\u4e2a\u8ffd\u52a0\u89c4\u5219\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -A INPUT -s 192.168.1.146 -j ACCEPT<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c-A INPUT\u8868\u793a\u5728INPUT\u94fe\u4e2dappend\u6dfb\u52a0\uff0c\u9700\u8981\u8bf4\u660e\u7684\u662f,-A\u6dfb\u52a0\u7684\u89c4\u5219\u662f\u5728\u94fe\u7684\u5c3e\u90e8\uff0c\u800c-I\u6dfb\u52a0\u7684\u89c4\u5219\u662f\u5728\u94fe\u7684\u9996\u90e8\uff0c\u800c\u89c4\u5219\u7684\u987a\u5e8f\u662f\u5f88\u91cd\u8981\u7684\uff0c\u5bf9\u540c\u4e00\u4e2a\u76ee\u6807\u5236\u5b9a\u597d\u7684\u89c4\u5219\uff0c\u89c4\u5219\u9760\u524d\u6ee1\u8db3\u5c31\u4f1a\u4f18\u5148\u5904\u7406\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u540e\u7eed\u7684\u89c4\u5219\u65e0\u6cd5\u751f\u6548\u3002<\/p>\n\n\n\n<p>\u5982\u4f55\u786e\u5b9a\u89c4\u5219\u7684\u987a\u5e8f\u5462\uff0c\u5728\u5217\u51fa\u89c4\u5219\u65f6\u4f7f\u7528&#8211;line\u53c2\u6570\u5373\u53ef,\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">trout_x86:\/ # iptables -t filter -vL OUTPUT                                                                                                                                                                \nChain OUTPUT (policy ACCEPT 33733 packets, 6488K bytes)\n pkts bytes target     prot opt in     out     source               destination         \n33749 6490K oem_out    all  --  any    any     anywhere             anywhere            \n33749 6490K fw_OUTPUT  all  --  any    any     anywhere             anywhere            \n33749 6490K st_OUTPUT  all  --  any    any     anywhere             anywhere            \n33749 6490K bw_OUTPUT  all  --  any    any     anywhere             anywhere            \ntrout_x86:\/ # iptables -t filter --line -vL OUTPUT                                                                                                                                                         \nChain OUTPUT (policy ACCEPT 34237 packets, 6623K bytes)\nnum   pkts bytes target     prot opt in     out     source               destination         \n1    34253 6625K oem_out    all  --  any    any     anywhere             anywhere            \n2    34253 6625K fw_OUTPUT  all  --  any    any     anywhere             anywhere            \n3    34253 6625K st_OUTPUT  all  --  any    any     anywhere             anywhere            \n4    34253 6625K bw_OUTPUT  all  --  any    any     anywhere             anywhere            \ntrout_x86:\/ # <\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u60f3\u8981\u6307\u5b9a\u63d2\u5165\u7684\u89c4\u5219\u5e8f\u53f7,\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u793a\u4f8b\u6765\u8fdb\u884c\u6dfb\u52a0\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -I INPUT 2 -s 192.168.1.146 -j ACCEPT<\/code><\/pre>\n\n\n\n<p>\u8be5\u793a\u4f8b\u8868\u793a\u63d2\u5165\u89c4\u5219\u4e14\u5e8f\u53f7\u4e3a2\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5220\u9664\u89c4\u5219<\/h4>\n\n\n\n<p>\u6709\u4e9b\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u4f1a\u9700\u8981\u5220\u9664\u67d0\u4e9b\u89c4\u5219\uff0c\u5220\u9664\u89c4\u5219\u4e00\u822c\u53ef\u4ee5\u6709\u4e24\u79cd\u65b9\u5f0f\uff0c\u4e00\u662f\u901a\u8fc7\u5e8f\u53f7\u6765\u8fdb\u884c\u5220\u9664\uff0c\u4e8c\u662f\u76f4\u63a5\u5220\u9664\u5bf9\u5e94\u7684\u52a8\u4f5c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -D INPUT 2<\/code><\/pre>\n\n\n\n<p>\u8868\u660e\u5220\u9664filter\u8868INPUT\u94fe\u7684\u7b2c\u4e8c\u6761\u89c4\u5219\u3002<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -D INPUT -s 192.168.1.146 -j ACCEPT<\/code><\/pre>\n\n\n\n<p>\u8868\u660e\u5220\u9664filter\u8868\u4e2dINPUT\u94fe\u5bf9\u5e94\u7684\u89c4\u5219\u3002<\/p>\n\n\n\n<p>\u9664\u4e86\u4e0a\u8ff0\u4e24\u79cd\u65b9\u5f0f\uff0ciptables\u8fd8\u63d0\u4f9b\u4e86\u76f4\u63a5\u6e05\u9664\u94fe\u4e2d\u6240\u6709\u89c4\u5219\u7684\u65b9\u5f0f\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -F INPUT<\/code><\/pre>\n\n\n\n<p>\u8868\u660e\u5220\u9664filter\u8868\u4e2dINPUT\u94fe\u4e0a\u6240\u6709\u7684\u89c4\u5219\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4fee\u6539\u89c4\u5219<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u4e00\u822c\u60c5\u51b5\u4e0b\u4e0d\u5efa\u8bae\u4fee\u6539\u89c4\u5219\uff0c\u6bd4\u8f83\u63a8\u8350\u7684\u662f\u5220\u9664\u89c4\u5219\u540e\u91cd\u65b0\u6dfb\u52a0\u5bf9\u5e94\u7684\u89c4\u5219\uff0c\u4f46\u5982\u679c\u6211\u4eec\u4e0d\u5f97\u4e0d\u4fee\u6539\u89c4\u5219\u65f6\uff0ciptables\u4e5f\u63d0\u4f9b\u4e86\u76f8\u5e94\u7684\u80fd\u529b\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528-R\u9009\u9879\u6765\u4fee\u6539\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -R INPUT 1 -s 192.168.1.110 -j REJECT<\/code><\/pre>\n\n\n\n<p>\u5728\u8be5\u793a\u4f8b\u4e2d\uff0c-R\u9009\u9879\u8868\u793a\u6307\u5b9a\u8981\u4fee\u6539\u7684\u94fe\uff08Replace\uff09\uff0c1\u4ee3\u8868INPUT\u94fe\u7684\u7b2c\u4e00\u6761\u89c4\u5219\uff0c-s\u6307\u5b9a\u6e90\u5730\u5740\uff0c-j REJECT\u8868\u660e\u4fee\u6539\u4e3aREJECT\u3002<\/p>\n\n\n\n<p>\u9664\u4e86\u4fee\u6539\u67d0\u4e2a\u5177\u4f53\u7684\u89c4\u5219\uff0c\u6211\u4eec\u53ef\u80fd\u8fd8\u4f1a\u4fee\u6539\u67d0\u4e9b\u94fe\u7684\u9ed8\u8ba4\u89c4\u5219\uff0c\u5173\u4e8e\u94fe\u7684\u9ed8\u8ba4\u89c4\u5219\u6211\u4eec\u5df2\u7ecf\u5728\u4e0a\u9762\u63d0\u5230\u8fc7\uff0c\u8fd9\u91cc\u8bb2\u5982\u4f55\u4fee\u6539\u9ed8\u8ba4\u89c4\u5219\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -P FORWARD DROP<\/code><\/pre>\n\n\n\n<p>\u5728\u8be5\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06filter\u8868\u4e2d\u7684FORWARD\u94fe\u9ed8\u8ba4\u89c4\u5219\u6539\u4e3aDROP\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u62d3\u5c55\u4f7f\u7528<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">iptables\u63d0\u4f9b\u4e86\u4e00\u4e9b\u989d\u5916\u7684\u62d3\u5c55\u6765\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u7684\u5236\u5b9a\u89c4\u5219\uff0c\u901a\u8fc7\u8fd9\u4e9b\u62d3\u5c55\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u6765\u5236\u5b9a\u89c4\u5219\u3002<\/p>\n\n\n\n<p>\u786e\u8ba4\u5f53\u524d\u652f\u6301\u7684\u62d3\u5c55\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\u786e\u8ba4\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">root@bwg29cn2:~# ls \/lib\/modules\/`uname -r`\/kernel\/net\/netfilter\/\nipset                       nf_dup_netdev.ko        nfnetlink_osf.ko     nft_hash.ko         nft_tunnel.ko      xt_conntrack.ko  xt_iprange.ko     xt_osf.ko       xt_statistic.ko\nipvs                        nf_flow_table_inet.ko   nfnetlink_queue.ko   nft_limit.ko        nft_xfrm.ko        xt_cpu.ko        xt_ipvs.ko        xt_owner.ko     xt_string.ko\nnf_conncount.ko             nf_flow_table.ko        nf_synproxy_core.ko  nft_log.ko          x_tables.ko        xt_CT.ko         xt_l2tp.ko        xt_physdev.ko   xt_tcpmss.ko\nnf_conntrack_amanda.ko      nf_log_common.ko        nf_tables.ko         nft_masq.ko         xt_addrtype.ko     xt_dccp.ko       xt_LED.ko         xt_pkttype.ko   xt_TCPMSS.ko\nnf_conntrack_broadcast.ko   nf_log_netdev.ko        nf_tables_set.ko     nft_nat.ko          xt_AUDIT.ko        xt_devgroup.ko   xt_length.ko      xt_policy.ko    xt_TCPOPTSTRIP.ko\nnf_conntrack_ftp.ko         nf_nat_amanda.ko        nft_chain_nat.ko     nft_numgen.ko       xt_bpf.ko          xt_dscp.ko       xt_limit.ko       xt_quota.ko     xt_tcpudp.ko\nnf_conntrack_h323.ko        nf_nat_ftp.ko           nft_compat.ko        nft_objref.ko       xt_cgroup.ko       xt_DSCP.ko       xt_LOG.ko         xt_rateest.ko   xt_TEE.ko\nnf_conntrack_irc.ko         nf_nat_irc.ko           nft_connlimit.ko     nft_osf.ko          xt_CHECKSUM.ko     xt_ecn.ko        xt_mac.ko         xt_RATEEST.ko   xt_time.ko\nnf_conntrack.ko             nf_nat.ko               nft_counter.ko       nft_queue.ko        xt_CLASSIFY.ko     xt_esp.ko        xt_mark.ko        xt_realm.ko     xt_TPROXY.ko\nnf_conntrack_netbios_ns.ko  nf_nat_sip.ko           nft_ct.ko            nft_quota.ko        xt_cluster.ko      xt_hashlimit.ko  xt_MASQUERADE.ko  xt_recent.ko    xt_TRACE.ko\nnf_conntrack_netlink.ko     nf_nat_tftp.ko          nft_dup_netdev.ko    nft_redir.ko        xt_comment.ko      xt_helper.ko     xt_multiport.ko   xt_REDIRECT.ko  xt_u32.ko\nnf_conntrack_pptp.ko        nfnetlink_acct.ko       nft_fib_inet.ko      nft_reject_inet.ko  xt_connbytes.ko    xt_hl.ko         xt_nat.ko         xt_sctp.ko\nnf_conntrack_sane.ko        nfnetlink_cthelper.ko   nft_fib.ko           nft_reject.ko       xt_connlabel.ko    xt_HL.ko         xt_NETMAP.ko      xt_SECMARK.ko\nnf_conntrack_sip.ko         nfnetlink_cttimeout.ko  nft_fib_netdev.ko    nft_socket.ko       xt_connlimit.ko    xt_HMARK.ko      xt_nfacct.ko      xt_set.ko\nnf_conntrack_snmp.ko        nfnetlink.ko            nft_flow_offload.ko  nft_synproxy.ko     xt_connmark.ko     xt_IDLETIMER.ko  xt_NFLOG.ko       xt_socket.ko\nnf_conntrack_tftp.ko        nfnetlink_log.ko        nft_fwd_netdev.ko    nft_tproxy.ko       xt_CONNSECMARK.ko  xt_ipcomp.ko     xt_NFQUEUE.ko     xt_state.ko\nroot@bwg29cn2:~# <\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u8fd9\u4e9b*.ko\u90fd\u662f\u5185\u6838\u9a71\u52a8\u6a21\u5757\uff0c\u5f53iptables\u4f7f\u7528\u76f8\u5e94\u7684\u62d3\u5c55\u65f6\u5c31\u4f1aload\u5bf9\u5e94\u7684\u6a21\u5757\u3002<\/p>\n\n\n\n<p>\u786e\u8ba4\u5df2\u7ecfloaded\u7684\u62d3\u5c55\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">root@Franz:\/home\/FranzKafka# cat \/proc\/net\/ip_tables_matches\ntime\ncomment\nlimit\naddrtype\nconntrack\nconntrack\nconntrack\nrecent\nrecent\nttl\naddrtype\nudplite\nudp\ntcp\nicmp<\/code><\/pre>\n\n\n\n<p><strong>iprange\u6a21\u5757<\/strong>\uff1a\u53ef\u4ee5\u6307\u5b9a\u8fde\u7eed\u7684IP\u5730\u5740,\u542f\u7528\u8be5\u6a21\u5757\u540e\u4f7f\u7528&#8211;src-range\u548c\u2014dst-range\u6765\u6307\u5b9a\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -I INPUT -m iprange  --src-range 192.168.1.1-192.168.1.146 -j DROP\niptables -t filter -I INPUT -m iprange  --dst-range 192.168.1.1-192.168.1.146 -j DROP<\/code><\/pre>\n\n\n\n<p><strong>string\u6a21\u5757<\/strong>\uff1a\u4f7f\u7528string\u6269\u5c55\u6a21\u5757\uff0c\u53ef\u4ee5\u6307\u5b9a\u8981\u5339\u914d\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u62a5\u6587\u4e2d\u5305\u542b\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u7b26\u5408\u5339\u914d\u6761\u4ef6<\/p>\n\n\n\n<p><strong>time\u6a21\u5757<\/strong>\uff1a\u53ef\u4ee5\u6839\u636e\u65f6\u95f4\u6bb5\u6765\u5339\u914d\u62a5\u6587\uff0c\u5982\u679c\u62a5\u6587\u5230\u8fbe\u7684\u65f6\u95f4\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u8303\u56f4\u5185\uff0c\u5219\u7b26\u5408\u5339\u914d\u6761\u4ef6\uff0c\u53ef\u7528\u53c2\u6570\u5305\u62ec&#8211;timestart\u548c\u2014timestop,&#8211;weekdays,&#8211;monthdays<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -I INPUT -p tcp --sport 443 -m time --timestart 09:00:00 -j DROP\n\niptables -t filter -I OUTPUT -p tcp -d taobao.com --dport 80 -m time --timestart 00:00 --timestop 10:00 --weekdays 1,2,3,4,5 -j DROP\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u9700\u8981\u8bf4\u660e\u7684\u662f\uff0ctime\u6a21\u5757\u4f7f\u7528\u7684\u65f6\u95f4\u4e3aUTC\u65f6\u95f4\uff0c\u4e0e\u670d\u52a1\u5668\u7684\u7cfb\u7edf\u65f6\u95f4\u53ef\u80fd\u662f\u5b58\u5728\u5dee\u5f02\u7684\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u89c4\u5219\u65e0\u6cd5\u5339\u914d\uff1b\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7&#8211;kerneltz\u53c2\u6570\u6765\u8bbe\u7f6e\u5176\u91c7\u7528\u4e0e\u5185\u6838\u4e00\u81f4\u7684\u65f6\u533a\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -I INPUT -s 112.165.10.4 -p tcp --dport 43162 -m time --kerneltz --timestop 12:57:28 -j DROP<\/code><\/pre>\n\n\n\n<p><strong>connlimit\u6a21\u5757<\/strong>\uff1a\u53ef\u4ee5\u9650\u5236IP\u7684\u8fde\u63a5\u6570\u91cf<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -t filter -I INPUT -m connlimit \u2013connlimit-above 3 -j REJECT<\/code><\/pre>\n\n\n\n<p>\u8be5\u793a\u4f8b\u9650\u5236\u5355IP\u8fde\u63a5\u6570\u8d85\u8fc73\u5219REJECT\u62d2\u7edd\u8fde\u63a5\u3002<\/p>\n\n\n\n<p><strong>limit\u6a21\u5757\uff1a<\/strong>limit\u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u9650\u5236\u901f\u7387<\/p>\n\n\n\n<p>\u67e5\u770b\u67d0\u4e2a\u62d3\u5c55\u6a21\u5757\u7684\u5e2e\u52a9\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1aiptables -m \u6a21\u5757\u540d &nbsp;&#8211;help  <\/p>\n\n\n\n<p>\u5982\u6211\u4eec\u9700\u8981\u67e5\u770btime\u6a21\u5757\u7684\u4f7f\u7528\u5e2e\u52a9\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">root@FranzKafka:\/home\/FranzKafka# iptables -m time --help\niptables v1.8.4\ntime match options:\n    --datestart time     Start and stop time, to be given in ISO 8601\n    --datestop time      (YYYY[-MM[-DD[Thh[:mm[:ss]]]]])\n    --timestart time     Start and stop daytime (hh:mm[:ss])\n    --timestop time      (between 00:00:00 and 23:59:59)\n[!] --monthdays value    List of days on which to match, separated by comma\n                         (Possible days: 1 to 31; defaults to all)\n[!] --weekdays value     List of weekdays on which to match, sep. by comma\n                         (Possible days: Mon,Tue,Wed,Thu,Fri,Sat,Sun or 1 to 7\n                         Defaults to all weekdays.)\n    --kerneltz           Work with the kernel timezone instead of UTC<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u81ea\u5b9a\u4e49\u94fe<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u9664\u4e86\u9ed8\u8ba4\u7684\u56db\u8868\u4e94\u94fe\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u589e\u52a0\u81ea\u5df1\u7684\u94fe\uff0c\u4e5f\u5c31\u662f\u81ea\u5b9a\u4e49\u7684\u94fe\u3002\u4e00\u822c\u6765\u8bb2\u6211\u4eec\u53ef\u4ee5\u4e0d\u7528\u589e\u52a0\u81ea\u5df1\u7684\u94fe\uff0c\u5728\u9ed8\u8ba4\u7684\u4e94\u94fe\u4e2d\u8fdb\u884c\u89c4\u5219\u7684\u6dfb\u52a0\u5373\u53ef\u3002\u4f46\u6709\u4e9b\u65f6\u5019\u4e3a\u4e86\u89c4\u5219\u7684\u96c6\u4e2d\u7ba1\u7406\uff0c\u6211\u4eec\u4e0d\u65b9\u4fbf\u5728\u9ed8\u8ba4\u7684\u94fe\u4e2d\u8fdb\u884c\u64cd\u4f5c\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u94fe\uff0c\u5bf9\u81ea\u5b9a\u4e49\u94fe\u8fdb\u884c\u7ba1\u7406\u3002<\/p>\n\n\n\n<p><strong>\u521b\u5efa\u81ea\u5b9a\u4e49\u94fe<\/strong>\uff1a<\/p>\n\n\n\n<p>iptables -t filter -N OWN_CHAIN&nbsp; \/\/\u8868\u660e\u5728filter\u8868\u521b\u5efa\u540d\u4e3aOWN_CHAIN\u7684\u94fe,-N\u4ee3\u8868new<\/p>\n\n\n\n<p>\u8fd9\u91cc\u9700\u8981\u8bf4\u660e\u7684\u662f\uff0c\u521b\u5efa\u81ea\u5b9a\u4e49\u521b\u5efa\u540e\u9700\u8981\u5728\u9ed8\u8ba4\u7684\u94fe\u4e2d\u8fdb\u884c\u5f15\u7528\u624d\u80fd\u4f7f\u89c4\u5219\u751f\u6548\u3002<\/p>\n\n\n\n<p><strong>\u5f15\u7528\u81ea\u5b9a\u4e49\u94fe<\/strong>\uff1a<\/p>\n\n\n\n<p>iptables -t filter -I INPUT -p tcp -j OWN_CHAIN \/\/\u5728INPUT\u94fe\u4e2d\u5f15\u7528OWN_CHAIN\u94fe<\/p>\n\n\n\n<p><strong>\u91cd\u547d\u540d\u81ea\u5b9a\u4e49\u94fe<\/strong>\uff1a<\/p>\n\n\n\n<p>iptables -E OWN_CHAIN OWN_CHAIN1 \/\/\u5c06OWN_CHAIN\u91cd\u547d\u540d\u4e3aOWN_CHAIN1<\/p>\n\n\n\n<p><strong>\u5220\u9664\u81ea\u5b9a\u4e49\u94fe<\/strong>\uff1a<\/p>\n\n\n\n<p>iptables -X OWN_CHAIN<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u9700\u8981\u8bf4\u660e\u7684\u662f\uff0c\u5728\u5220\u9664\u81ea\u5b9a\u4e49\u94fe\u4e4b\u524d\uff0c\u9700\u8981\u5148\u6e05\u9664\u8be5\u81ea\u5b9a\u4e49\u94fe\u5728\u9ed8\u8ba4\u4e94\u94fe\u4e2d\u7684\u5f15\u7528\uff0c\u5e76\u4e14\u786e\u4fdd\u65e0\u4efb\u4f55\u89c4\u5219\uff0c\u5426\u5219\u65e0\u6cd5\u8fdb\u884c\u5220\u9664\u3002<\/p>\n\n\n\n<p><strong>\u6e05\u9664\u81ea\u5b9a\u4e49\u94fe<\/strong>\uff1a<\/p>\n\n\n\n<p>iptables -t filter -F OWN_CHAIN<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u65e5\u5fd7\u67e5\u770b<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">Iptables\u4e2d\u7684\u52a8\u4f5c\u9664\u4e86ACCEPT\u3001DROP\u3001REJECT\u3001RETURN\uff0c\u8fd8\u6709LOG\uff0c\u5176\u4e2dLOG\u52a8\u4f5c\u5373\u662f\u8bb0\u5f55\u6ee1\u8db3\u89c4\u5219\u7684\u6570\u636e\u5305\uff0c\u5982\u4e0b\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">iptables -A INPUT -p tcp --dport 80 -j LOG --log-prefix \"INPUT\" --log-level 4  --log-ip-options --log-tcp-sequence\n\n--log-level #\u9519\u8bef\u7ea7\u522b\uff0c\u53ef\u4ee5\u4f7f\u75280\u52307\u4e4b\u95f4\u7684\u6570\u5b57\u30020\u662femerg,1\u662falert\uff0c2\u662fcrit\uff0c3\u662ferr\uff0c4\u662fwarning\uff0c5\u662fnotice\uff0c6\u662finfo\uff0c7\u662fdebug\n--log-prefix \"INPUT\" #\u63cf\u8ff0\u524d\u7f00\uff0c\u65e5\u5fd7\u4e2d\u7684tag\n--log-ip-options #\u8bb0\u5f55IP\u4fe1\u606f\n--log-tcp-sequence #\u8bb0\u5f55TCP\u5e8f\u5217\u53f7<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u8be5\u89c4\u5219\u8868\u660e\u4ee5Append\u7684\u5f62\u5f0f\u5c06tcp\u8bbf\u95ee\u7aef\u53e380\u7684\u6570\u636e\u5305\u8fdb\u884c\u8bb0\u5f55\uff0c\u9ed8\u8ba4\u4f1a\u5c06\u65e5\u5fd7\u8bb0\u5f55\u5230kernel\u65e5\u5fd7\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528dmesg\u547d\u4ee4\u8fdb\u884c\u67e5\u770b\u3002<\/p>\n        <div class=\"booster-block booster-reactions-block\">\n            <div class=\"twp-reactions-icons\">\n                \n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-1\" post-id=\"4591\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/happy.svg\" alt=\"Happy\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Happy                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">2<\/span>\n                        \n                                                <span class=\"twp-react-percent\"><span>100<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-2\" post-id=\"4591\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/sad.svg\" alt=\"Sad\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Sad                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-3\" post-id=\"4591\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/excited.svg\" alt=\"Excited\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Excited                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-6\" post-id=\"4591\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/sleepy.svg\" alt=\"Sleepy\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Sleepy                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                        \n                                                <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-4\" post-id=\"4591\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/angry.svg\" alt=\"Angry\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">Angry<\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                        \n                    <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-5\" post-id=\"4591\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/surprise.svg\" alt=\"Surprise\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">Surprise<\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n            <\/div>\n        <\/div>","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8eIptables\u7684\u4e00\u4e9b\u5e38\u89c1\u4f7f\u7528\u65b9\u6cd5\u8bb0\u5f55<\/p>","protected":false},"author":1,"featured_media":4623,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":4,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18],"tags":[68,33,26],"class_list":["post-4591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-operating-system","tag-filter","tag-linux","tag-vps"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[]}},"aioseo_notices":[],"featured_image_urls":{"full":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"thumbnail":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo-150x150.png",150,150,true],"medium":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo-300x150.png",300,150,true],"medium_large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"1536x1536":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"2048x2048":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"trp-custom-language-flag":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo-18x9.png",18,9,true]},"post_excerpt_stackable":"<p>\u5173\u4e8eIptables\u7684\u4e00\u4e9b\u5e38\u89c1\u4f7f\u7528\u65b9\u6cd5\u8bb0\u5f55<\/p>\n","category_list":"<a href=\"https:\/\/blog.coderfan.org\/en\/category\/operating-system\" rel=\"category tag\">\u64cd\u4f5c\u7cfb\u7edf<\/a>","author_info":{"name":"FranzKafka95","url":"https:\/\/blog.coderfan.org\/en\/author\/yushenglonely95"},"comments_num":"0 comments","featured_image_urls_v2":{"full":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"thumbnail":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo-150x150.png",150,150,true],"medium":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo-300x150.png",300,150,true],"medium_large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"1536x1536":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"2048x2048":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo.png",318,159,false],"trp-custom-language-flag":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/05\/Linux-Logo-18x9.png",18,9,true]},"post_excerpt_stackable_v2":"<p>\u5173\u4e8eIptables\u7684\u4e00\u4e9b\u5e38\u89c1\u4f7f\u7528\u65b9\u6cd5\u8bb0\u5f55<\/p>\n","category_list_v2":"<a href=\"https:\/\/blog.coderfan.org\/en\/category\/operating-system\" rel=\"category tag\">\u64cd\u4f5c\u7cfb\u7edf<\/a>","author_info_v2":{"name":"FranzKafka95","url":"https:\/\/blog.coderfan.org\/en\/author\/yushenglonely95"},"comments_num_v2":"0 comments","_links":{"self":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts\/4591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/comments?post=4591"}],"version-history":[{"count":36,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts\/4591\/revisions"}],"predecessor-version":[{"id":4792,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts\/4591\/revisions\/4792"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/media\/4623"}],"wp:attachment":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/media?parent=4591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/categories?post=4591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/tags?post=4591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}