{"id":75,"date":"2008-03-06T17:26:07","date_gmt":"2008-03-06T09:26:07","guid":{"rendered":"http:\/\/blog.pighead.cc\/whsyu\/2008\/03\/06\/75\/"},"modified":"2012-12-18T11:03:37","modified_gmt":"2012-12-18T03:03:37","slug":"pf-in-freebsd7","status":"publish","type":"post","link":"https:\/\/blog.pighead.cc\/whsyu\/2008\/03\/06\/pf-in-freebsd7\/","title":{"rendered":"pf in FreeBSD 7"},"content":{"rendered":"<p class=\"bb-post-separator\"><strong>[\u83ef\u8a9e, cmn-Hant-TW]  <\/strong><\/p><p>FreeBSD \u7684 pf \u76f8\u7576\u7684\u597d\u7528\uff0c\u5c24\u5176\u662f\u5728\u6709\u5169\u500b gateway \u7684\u6642\u5019\uff0c\u53ef\u4ee5\u7cbe\u78ba\u7684\u63a7\u5236\u9032\u51fa\u7684 gateway\uff0c\u5927\u81f4\u4e0a\u9700\u8981\u9019\u6a23\u5b50\u7684\u8a2d\u5b9a (\u5728 \/etc\/pf.conf) \u5373\u53ef\uff1a<\/p>\n<pre lang=\"none\">pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any\r\npass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any<\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u628a\u8dd1\u932f\u908a\u7684\u5c01\u5305\u4e1f\u56de\u6b63\u78ba\u7684\u8def\u53bb\uff0c\u4e4b\u524d\u5728 FreeBSD 6 \u4e0a\u4f7f\u7528\u76f8\u7576\u6109\u5feb\u3002\u6709\u9047\u5230\u4e00\u500b\u554f\u984c\u5c31\u662f icmp \u5c01\u5305\u8d70 $ext_gw1 \u56de\u4f86 (\u7cfb\u7d71\u7684 default gateway \u662f $ext_gw2) \u53ea\u6703\u6536\u5230\u7b2c\u4e00\u500b\u63a5\u8457\u5f8c\u9762\u5c31\u5931\u806f\u4e86\uff0c\u4f46\u662f\u5176\u4ed6\u7684 tcp udp \u770b\u8d77\u90fd\u6b63\u5e38\u904b\u4f5c\uff0c\u6240\u4ee5\u4e0d\u662f\u592a\u5927\u7684\u554f\u984c\uff0c\u5c31\u6c92\u7406\u4ed6\u4e86\u3002<\/p>\n<p>\u7136\u5f8c\u5728\u628a\u9019\u53f0 server \u6607\u7d1a\u5230 FreeBSD 7 \u4e4b\u5f8c\uff0c\u767c\u73fe\u72c0\u6cc1\u53cd\u904e\u4f86\u4e86\u3002\u5728\u8a2d\u5b9a\u6a94\u5b8c\u5168\u4e00\u6a23\u7684\u60c5\u6cc1\u4e0b\uff0cicmp \u901a\u4e86\uff0c\u4f46\u662f tcp \u65b7\u6389\u4e86\uff0c\u9019\u6a23\u5b50\u554f\u984c\u5c31\u5f88\u5927\u3002\u4ea4\u53c9\u6e2c\u8a66\u78ba\u5b9a\u4e0d\u662f\u7dda\u8def\u7684\u554f\u984c\u4e4b\u5f8c\uff0c\u90a3\u5c31\u662f\u8a2d\u5b9a\u7684\u554f\u984c\u4e86\u3002<\/p>\n<p>\u6e2c\u4e86\u4e00\u4e0b\u767c\u73fe\u60f3\u8981\u5f9e $ext_gw1 \u9032\u4f86\u5efa\u7acb\u7684\u9023\u7dda\uff0c\u56de\u61c9\u7684\u6642\u5019\u537b\u5f9e $ext_gw2 \u51fa\u53bb\uff0c\u8a66\u4e86\u597d\u591a\u65b9\u6cd5\u90fd\u6c92\u7121\u89e3\uff0c\u518d\u4ed4\u7d30\u770b\u4e86\u4e00\u4e0b pf.conf \u7684 manual pages \u88e1\u9762\u6709\u6c92\u6709\u4ec0\u9ebc tcp only \u7684\u8a2d\u5b9a\uff0c\u7136\u5f8c\u5c31\u767c\u73fe\u4e86 flag \u9019\u4e00\u500b\u53c3\u6578\uff0c\u7167\u6558\u8ff0\u4f86\u770b\u5c31\u662f\u8aaa\u9810\u8a2d\u662f S\/SA\uff0c\u7136\u5f8c\u5982\u679c\u4f60\u60f3\u8981\u6e1b\u5c11\u9650\u5236\u7684\u8a71\u53ef\u4ee5\u8a2d\u6210 any\uff0c\u4f46\u662f\u642d\u914d\u5176\u4ed6\u7684\u53ef\u80fd\u6703\u6bd4\u8f03\u4e0d\u7a69\u5b9a\uff0c\u554a\u6211\u4e5f\u61f6\u5f97\u53bb\u4ed4\u7d30\u770b\u9019\u4e9b\u53c3\u6578\u662f\u5728\u5e79\u561b\u7684\uff0c\u5c31\u62ff any \u76f4\u63a5\u8a66\u4e86\u3002\u6c92\u60f3\u5230\u5c45\u7136\u53ef\u4ee5\u7528 (\u7406\u8ad6\u4e0a\u61c9\u8a72\u6709\u66f4\u5408\u689d\u4ef6\u7684\u8a2d\u5b9a\uff0c\u4e0d\u904e\u6211\u4e0d\u60f3\u53bb\u770b\u6587\u4ef6\u4e86)\uff0c\u800c\u5206\u958b\u8a2d\u597d\u7684\u8a71 icmp \u4e5f\u53ef\u4ee5\u4f9d\u7136\u6b63\u5e38\u56de\u61c9\uff0c\u6c92\u6709 FreeBSD 6 \u6642\u4ee3\u7684\u554f\u984c\uff0c\u6539\u904e\u7684\u8a2d\u5b9a\u6a94\uff1a<\/p>\n<pre lang=\"none\">\r\npass out on $ext_if1 route-to ($ext_if2 $ext_gw2) proto { udp, icmp } from $ext_if2 to any\r\npass out on $ext_if2 route-to ($ext_if1 $ext_gw1) proto { udp, icmp } from $ext_if1 to any\r\npass out on $ext_if1 route-to ($ext_if2 $ext_gw2) proto tcp from $ext_if2 to any flags any\r\npass out on $ext_if2 route-to ($ext_if1 $ext_gw1) proto tcp from $ext_if1 to any flags any\r\n<\/pre>\n<p>\u628a tcp \u548c icmp, udp \u5206\u5225\u8655\u7406\uff0c\u904b\u4f5c\u7684\u6bd4\u4e4b\u524d\u9084\u8981\u9806\u66a2\u3002\u5f8c\u4f86\u60f3\u60f3\u5728\u4e4b\u524d\u7248\u672c\u4e0a\u9762\u7684\u8a2d\u5b9a\u6709\u5c0d\u7684\u8a71\uff0c\u6216\u8a31\u4e5f\u53ef\u4ee5\u6b63\u5e38\u8655\u7406 icmp \u5c01\u5305\u3002\u4e0d\u904e\u624b\u908a\u6c92\u6709\u9069\u5408\u7684 FreeBSD 6 \u7684\u6a5f\u5668\u53ef\u4ee5\u62ff\u4f86\u6e2c\u8a66\uff0c\u6240\u4ee5\u4e5f\u5c31\u4e0d\u53bb\u6e2c\u8a66\u9019\u500b\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[\u83ef\u8a9e, cmn-Hant-TW] FreeBSD \u7684 pf \u76f8\u7576\u7684\u597d\u7528\uff0c\u5c24\u5176\u662f\u5728\u6709\u5169\u500b gateway \u7684\u6642\u5019\uff0c\u53ef\u4ee5\u7cbe\u78ba\u7684\u63a7\u5236\u9032\u51fa\u7684 gateway\uff0c\u5927\u81f4\u4e0a\u9700\u8981\u9019\u6a23\u5b50\u7684\u8a2d\u5b9a (\u5728 \/etc\/pf.conf) \u5373\u53ef\uff1a pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any pass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any \u9019\u6a23\u53ef\u4ee5\u628a\u8dd1\u932f\u908a\u7684\u5c01\u5305\u4e1f\u56de\u6b63\u78ba\u7684\u8def\u53bb\uff0c\u4e4b\u524d\u5728 FreeBSD 6 \u4e0a\u4f7f\u7528\u76f8\u7576\u6109\u5feb\u3002\u6709\u9047\u5230\u4e00\u500b\u554f\u984c\u5c31\u662f icmp \u5c01\u5305\u8d70&hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[263,4591],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-freebsd","tag-firewall","tag-freebsd"],"_links":{"self":[{"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":5,"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":2219,"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/posts\/75\/revisions\/2219"}],"wp:attachment":[{"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.pighead.cc\/whsyu\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}