{"id":15495,"date":"2025-12-29T16:17:48","date_gmt":"2025-12-29T08:17:48","guid":{"rendered":"https:\/\/blog.pfchina.org\/?p=15495"},"modified":"2026-01-05T11:24:07","modified_gmt":"2026-01-05T03:24:07","slug":"opnsense-%e9%85%8d%e5%90%88%e4%b8%89%e5%b1%82%e4%ba%a4%e6%8d%a2%e6%9c%ba%e9%85%8d%e7%bd%ae-vlan-%e9%97%b4%e8%b7%af%e7%94%b1","status":"publish","type":"post","link":"https:\/\/blog.pfchina.org\/?p=15495","title":{"rendered":"OPNsense \u914d\u5408\u4e09\u5c42\u4ea4\u6362\u673a\u914d\u7f6e VLAN \u95f4\u8def\u7531"},"content":{"rendered":"<p style=\"text-align: justify;\">\u901a\u8fc7\u4e09\u5c42\u4ea4\u6362\u673a\u6765\u5904\u7406 VLAN \u95f4\u8def\u7531\uff0c\u53ef\u4ee5\u8282\u7701\u9632\u706b\u5899\u4e0a\u7684\u8d44\u6e90\uff0c\u540c\u65f6\u63d0\u5347\u7f51\u7edc\u8bbf\u95ee\u6027\u80fd\u3002\u4e09\u5c42\u4ea4\u6362\u673a\u8d1f\u8d23 VLAN \u95f4\u8def\u7531 + DHCP\uff0cOPNsense \u53ea\u505a\u51fa\u53e3\u3001\u9632\u706b\u5899\u3001NAT\u3002<\/p>\n<p style=\"text-align: justify;\">\u00a0vlan\u5730\u5740\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<table style=\"height: 270px;\" width=\"713\">\n<thead>\n<tr>\n<th>\n<p class=\"p1\"><b>VLAN<\/b><\/p>\n<\/th>\n<th>\n<p class=\"p1\"><b>\u7528\u9014<\/b><\/p>\n<\/th>\n<th>\n<p class=\"p1\"><b>\u7f51\u6bb5<\/b><\/p>\n<\/th>\n<th>\n<p class=\"p1\"><b>\u7f51\u5173<\/b><\/p>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">10<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">\u7ba1\u7406<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.10.0\/24<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.10.1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">20<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">\u529e\u516c<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.20.0\/24<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.20.1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">30<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">IoT<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.30.0\/24<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.30.1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">99<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">\u4e0a\u8054 OPNsense<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.99.0\/30<\/p>\n<\/td>\n<td>\n<p class=\"p1\" style=\"text-align: center;\">192.168.99.1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e0b\u9762\u4e3a\u914d\u7f6e\u8fc7\u7a0b\u3002<\/p>\n<h1 style=\"text-align: justify;\">\u4ea4\u6362\u673a\u914d\u7f6e<\/h1>\n<p style=\"text-align: justify;\">\u4ea4\u6362\u673a\u4e3a\u534e\u4e3aS5735S-L32ST4X-A\uff0c\u5176\u4ed6\u7c7b\u578b\u4ea4\u6362\u673a\u53ef\u4ee5\u53c2\u8003\u3002<\/p>\n<h3 style=\"text-align: justify;\">1\u3001\u521b\u5efa vlan\u548cSVI<\/h3>\n<pre class=\"code\">system-view\r\nvlan batch 10 20 30 99\r\ninterface Vlanif10\r\ndescription VLAN10-MGMT\r\nip address 192.168.10.1 255.255.255.0\r\ndhcp select global\r\ninterface Vlanif20\r\ndescription VLAN20-OFFICE\r\nip address 192.168.20.1 255.255.255.0\r\ndhcp select global\r\ninterface Vlanif30\r\ndescription VLAN30-IOT\r\nip address 192.168.30.1 255.255.255.0\r\ndhcp select global\r\ninterface Vlanif99\r\ndescription UPLINK-OPNSENSE\r\nip address 192.168.99.1 255.255.255.252<\/pre>\n<h3 style=\"text-align: justify;\">2\u3001\u542f\u7528 dhcp<\/h3>\n<p style=\"text-align: justify;\">\u542f\u7528 DHCP Server\uff08\u5168\u5c40\uff09<\/p>\n<pre class=\"code\">dhcp enable<\/pre>\n<p style=\"text-align: justify;\">vlan\u914d\u7f6edhcp\u5730\u5740\u6c60<\/p>\n<pre class=\"code\">ip pool VLAN10_POOL\r\nnetwork 192.168.10.0 mask 255.255.255.0\r\ngateway-list 192.168.10.1\r\ndns-list 223.5.5.5 8.8.8.8\r\nexcluded-ip-address 192.168.10.1 192.168.10.50\r\nlease day 7<\/pre>\n<pre class=\"code\">ip pool VLAN20_POOL\r\nnetwork 192.168.20.0 mask 255.255.255.0\r\ngateway-list 192.168.20.1\r\ndns-list 223.5.5.5 8.8.8.8\r\nexcluded-ip-address 192.168.20.1 192.168.20.50\r\nlease day 7<\/pre>\n<pre class=\"code\">ip pool VLAN30_POOL\r\nnetwork 192.168.30.0 mask 255.255.255.0\r\ngateway-list 192.168.30.1\r\ndns-list 223.5.5.5 8.8.8.8\r\nexcluded-ip-address 192.168.30.1 192.168.30.50\r\nlease day 7<\/pre>\n<h3 style=\"text-align: justify;\">3\u3001\u6dfb\u52a0\u63a5\u5165\u7aef\u53e3<\/h3>\n<pre class=\"code\">interface GigabitEthernet0\/0\/1\r\ndescription MGMT-PC\r\nport link-type access\r\nport default vlan 10\r\ninterface GigabitEthernet0\/0\/2\r\ndescription OFFICE-PC\r\nport link-type access\r\nport default vlan 20\r\ninterface GigabitEthernet0\/0\/3\r\ndescription IOT\r\nport link-type access\r\nport default vlan 30<\/pre>\n<h3 style=\"text-align: justify;\">4\u3001\u6dfb\u52a0\u4e0a\u8054\u7aef\u53e3<\/h3>\n<pre class=\"code\">interface GigabitEthernet0\/0\/24\r\ndescription UPLINK-OPNSENSE\r\nport link-type access\r\nport default vlan 99<\/pre>\n<h3 style=\"text-align: justify;\">5\u3001\u6dfb\u52a0\u9ed8\u8ba4\u8def\u7531<\/h3>\n<pre class=\"code\">ip route-static 0.0.0.0 0.0.0.0 192.168.99.2<\/pre>\n<h3 style=\"text-align: justify;\">6\u3001\u4fdd\u5b58\u914d\u7f6e<\/h3>\n<pre class=\"code\">save<\/pre>\n<h1 style=\"text-align: justify;\">OPNsense \u914d\u7f6e<\/h1>\n<h3 style=\"text-align: justify;\">1\u3001lan\u63a5\u53e3\u914d\u7f6e<\/h3>\n<p style=\"text-align: justify;\">\u8f6c\u5230\u63a5\u53e3&gt;lan\uff0c\u5c06 lan\u63a5\u53e3\u5730\u5740\u914d\u7f6e\u4e3a\u4ea4\u6362\u673a\u9ed8\u8ba4\u8def\u7531\u7684\u4e0b\u4e00\u8df3\u5730\u5740192.168.99.2\u3002<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-42-30.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15498\" src=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-42-30.png\" alt=\"\" width=\"2016\" height=\"288\" \/><\/a><\/p>\n<h3 style=\"text-align: justify;\">2\u3001\u6dfb\u52a0\u7f51\u5173<\/h3>\n<p style=\"text-align: justify;\">\u8f6c\u5230\u7cfb\u7edf&gt;\u7f51\u5173&gt;\u914d\u7f6e\uff0c\u5728lan\u63a5\u53e3\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u7f51\u5173\uff0c\u5730\u5740\u4e3a\u4ea4\u6362\u673a\u4e0b\u8054\u53e3\u5730\u5740192.168.99.1\u3002<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-50-34.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-15501 size-full\" src=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-50-34.png\" alt=\"\" width=\"1784\" height=\"648\" \/><\/a><\/p>\n<h3 style=\"text-align: justify;\">3\u3001\u6dfb\u52a0\u56de\u7a0b\u8def\u7531<\/h3>\n<p style=\"text-align: justify;\">\u8f6c\u5230\u7cfb\u7edf&gt;\u8def\u7531&gt;\u914d\u7f6e\uff0c\u6dfb\u52a0\u4e09\u6761\u56de\u7a0b\u8def\u7531\u3002<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-49-25.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15500\" src=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-49-25.png\" alt=\"\" width=\"1790\" height=\"594\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">\u5176\u4ed6\u4e24\u6761\u56de\u7a0b\u8def\u7531\u7c7b\u4f3c\u3002<\/p>\n<h3 style=\"text-align: justify;\">4\u3001\u6dfb\u52a0\u9632\u706b\u5899\u89c4\u5219<\/h3>\n<p style=\"text-align: justify;\">\u8f6c\u5230\u9632\u706b\u5899&gt;\u89c4\u5219&gt;LAN\uff0c\u6dfb\u52a0\u4e00\u6761 any to any \u89c4\u5219\u3002\u6ce8\u610f\u8fd9\u91cc\u7684\u6e90\u4e0d\u80fd\u4e3aLAN NET\uff0c\u5fc5\u987b\u4e3a any\uff0c\u6216\u8005 vlan\u7684\u5b50\u7f51\u3002<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-52-17.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15502\" src=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_15-52-17.png\" alt=\"\" width=\"2036\" height=\"412\" \/><\/a><\/p>\n<h3 style=\"text-align: justify;\">5\u3001\u6dfb\u52a0\u51fa\u7ad9\u89c4\u5219<\/h3>\n<p style=\"text-align: justify;\">\u4e0e pfSense \u5728\u6dfb\u52a0\u9759\u6001\u8def\u7531\u540e\u4f1a\u81ea\u52a8\u6dfb\u52a0\u51fa\u7ad9\u89c4\u5219\u4e0d\u540c\uff0cOPNsense \u9700\u8981\u624b\u52a8\u6dfb\u52a0\u51fa\u7ad9\u89c4\u5219\u3002<\/p>\n<p style=\"text-align: justify;\">\u8f6c\u5230\u9632\u706b\u5899 &gt;NAT\u00a0 &gt;\u51fa\u7ad9\uff0c\u5c06\u51fa\u7ad9\u6539\u4e3a\u6df7\u5408\u51fa\u7ad9\uff0c\u7136\u540e\u6dfb\u52a0\u4ee5\u4e0b\u51fa\u7ad9\u89c4\u5219\uff1a<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_16-02-08.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15503\" src=\"https:\/\/blog.pfchina.org\/wp-content\/uploads\/2025\/12\/Snipaste_2025-12-29_16-02-08.png\" alt=\"\" width=\"2030\" height=\"356\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">\u73b0\u5728\uff0cVLAN\u95f4\u8def\u7531\u5728\u4e09\u5c42\u4ea4\u6362\u673a\u4e0a\u914d\u7f6e\u5b8c\u6210\uff0c\u6bcf\u4e2aVLAN\u7f51\u7edc\u4e0a\u7684\u4e3b\u673a\u90fd\u53ef\u4ee5\u901a\u8fc7 OPNsense \u9632\u706b\u5899\u8bbf\u95ee\u4e92\u8054\u7f51\u3002<\/p>\n<p style=\"text-align: justify;\">\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<ul style=\"text-align: justify;\">\n<li style=\"text-align: justify;\">\u53ea\u80fd\u5728\u4e09\u5c42\u4ea4\u6362\u673a\u4e0a\u521b\u5efa ACL\uff08\u8bbf\u95ee\u63a7\u5236\u5217\u8868\uff09\u6765\u9650\u5236\u6bcf\u4e2a VLAN \u4e4b\u95f4\u7684\u6d41\u91cf\uff0c\u800c\u4e0d\u662f\u5728 OPNsense \u4e0a\u4f7f\u7528\u9632\u706b\u5899\u89c4\u5219\u6765\u8fdb\u884c\u63a7\u5236\u3002<\/li>\n<li style=\"text-align: justify;\">\u5728\u4e09\u5c42\u4ea4\u6362\u673a\u4e0a\u6dfb\u52a0\u5176\u4ed6\u7684VLAN SVI\u65f6\uff0c\u9700\u8981\u540c\u65f6\u5728 OPNsense \u6dfb\u52a0\u5fc5\u8981\u7684\u9759\u6001\u8def\u7531\u548c\u9632\u706b\u5899\/NAT\u89c4\u5219\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u8fdb\u884c Internet \u8bbf\u95ee\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u4e09\u5c42\u4ea4\u6362\u673a\u6765\u5904\u7406 VLAN \u95f4\u8def\u7531\uff0c\u53ef\u4ee5\u8282\u7701\u9632\u706b\u5899\u4e0a\u7684\u8d44\u6e90\uff0c\u540c\u65f6\u63d0\u5347\u7f51\u7edc\u8bbf\u95ee &hellip; <a href=\"https:\/\/blog.pfchina.org\/?p=15495\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[330,227],"class_list":["post-15495","post","type-post","status-publish","format-standard","hentry","category-opnsense","tag-330","tag-227"],"_links":{"self":[{"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=\/wp\/v2\/posts\/15495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15495"}],"version-history":[{"count":18,"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=\/wp\/v2\/posts\/15495\/revisions"}],"predecessor-version":[{"id":15534,"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=\/wp\/v2\/posts\/15495\/revisions\/15534"}],"wp:attachment":[{"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.pfchina.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}