1. \u6309\u884c\u5220\u9664<\/strong><\/span><\/div>\n\u5982\u679c\u6309\u7167\u884c\u53f7\u5220\u9664\uff0c\u5c31\u4e0d\u4f1a\u6709\u8fd9\u7bc7\u6587\u7ae0\u4e86\uff0c\u5f53\u7136\u5982\u679c\u4f60\u5220\u9664\u524d\u5c31\u77e5\u9053\u4e86\u884c\u53f7\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e0b\u547d\u4ee4<\/p>\n
iptables -t $table -D POSTROUTING 2<\/pre>\n-t: \u540e\u9762\u63a5\u7684\u662f\u8981\u64cd\u7eb5\u7684\u8868\u3002\u8868\u5305\u62ec\u56db\u4e2a\uff0c\u6ce8\u610f\u9ed8\u8ba4\u7684\u53ef\u80fd\u4e0d\u662f\u4f60\u7684table\uff0c\u5177\u4f53\u770b\u5b98\u65b9\u6587\u6863\u5730\u5740<\/p>\n
-D: \u4ee3\u8868\u5220\u9664<\/p>\n
POSTROUTING: \u7528\u4e8e\u6e90\u5730\u5740\u8f6c\u6362\uff08SNAT\uff09,\u8fd9\u91cc\u9700\u8981\u586b\u4f60\u7684\u89c4\u5219\u8fde\u63a5\u3002<\/p>\n
\u7136\u540e\u540e\u9762\u63a5\u884c\u53f7<\/p>\n
iptables -t $table -L -n --line-numbers<\/pre>\n2. \u6839\u636e\u5339\u914d\u89c4\u5219\u5220\u9664<\/strong><\/span><\/div>\n\u5b98\u65b9\u6587\u6863\u4e2d\u91c7\u7528\u7684\u7684\u7cbe\u786e\u5339\u914d\u5220\u9664\u3002\u6240\u4ee5\u4f60\u4e0d\u80fd\u53ea\u5236\u5b9a\u4e00\u4e2a\u7b5b\u9009\u6761\u4ef6\u3002\u5fc5\u987b\u7ed9\u51fa\u89c4\u5219\u7684\u6bcf\u4e00\u4e2a\u7ec6\u8282\uff0c\u548c\u4f60\u5f53\u521d\u6dfb\u52a0\u8be5\u89c4\u5219\u65f6\u4e00\u6837\uff0c\u548c\u6dfb\u52a0\u52a8\u4f5c\u552f\u4e00\u4e0d\u540c\u7684\u662f\uff0c\u4f60\u8981\u628a-A\u6539\u6210-D\u3002\u8fd9\u79cd\u7cbe\u786e\u5339\u914d\u5220\u9664\u7684\u6210\u529f\u4f9d\u8d56\u7684\u5c31\u662f\u7528\u6237\u63d0\u4f9b\u7684\u6240\u6709match\u5b57\u6bb5\uff0ctarget\u5b57\u6bb5\u5fc5\u987b\u548c\u5185\u6838\u4e2d\u4fdd\u5b58\u7684\u4e00\u6a21\u4e00\u6837\uff0c\u7cbe\u786e\u5230\u5b57\u8282\u7ea7\u522b\u7684\u5339\u914d\u3002\u5982\u679c\u54ea\u6015\u6709\u4e00\u4e2a\u5b57\u8282\u4e0d\u5339\u914d\uff0c\u5c31\u4f1a\u6709\u4e8c\u4e49\u6027\uff0c\u5220\u9664\u5931\u8d25\u3002<\/p>\n
3. \u6574\u8868\u6574\u94fe\u5220\u9664<\/strong><\/span><\/div>\n\u8fd9\u4e2a\u592a\u6781\u7aef\u4e86,\u614e\u7528<\/p>\n
iptables -t $table -F<\/pre>\n4. \u4f7f\u7528Python-iptables\u8fdb\u884c\u64cd\u4f5c<\/strong><\/span><\/div>\n\u672c\u6765\u6211\u8fd9\u63a5\u53e3\u5c31\u662f\u7528python\u5199\u7684\uff0c\u6240\u4ee5\u81ea\u7136\u5c31\u60f3\u5230\u4f7f\u7528python-iptables\u6765\u8fdb\u884c\u89c4\u5219\u7684\u5220\u9664\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u4e0d\u7528\u7cbe\u786e\u5339\u914d\u4e86\u3002\u4f46\u95ee\u9898\u662f\u65e0\u6cd5\u5728\u963b\u585e\u6001\u7684\u65f6\u5019\u4f7f\u7528<\/p>\n
==\u4f46\u662f\u53ef\u4ee5\u91cd\u542f\u4e00\u4e2a\u5355\u72ec\u7684\u811a\u672c\u8fd0\u884c==<\/p>\n
python-iptables\u7684\u5b98\u65b9\u6587\u6863<\/p>\n
\r\nimport iptc\r\n\r\ntable = iptc.Table(iptc.Table.NAT)\r\ntable.autocommit = False # \u4e0d\u52a0\u4ea6\u53ef\uff0c\u4f1a\u81ea\u52a8\u63d0\u4ea4\uff0c\u6b64\u5904\u662f\u624b\u52a8\r\nchain = iptc.Chain(table, \"POSTROUTING\")\r\nfor rule in chain.rules:\r\n if rule.src == f\"{network_segment}\/255.255.255.0\":\r\n chain.delete_rule(rule)\r\ntable.commit()\r\ntable.autocommit = True\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"\u5982\u679c\u6309\u7167\u884c\u53f7\u5220\u9664\uff0c\u5c31\u4e0d\u4f1a\u6709\u8fd9\u7bc7\u6587\u7ae0\u4e86\uff0c\u5f53\u7136\u5982\u679c\u4f60\u5220\u9664\u524d\u5c31\u77e5\u9053\u4e86\u884c\u53f7\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e0b\u547d\u4ee4 iptables […]<\/p>\n","protected":false},"author":63,"featured_media":159554,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-159553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/159553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=159553"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/159553\/revisions"}],"predecessor-version":[{"id":160426,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/159553\/revisions\/160426"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/159554"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=159553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=159553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=159553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}