Communitygithub.com

homelab-vlan-segmentation

將家庭網路分割成 IoT、訪客、信任和伺服器 VLAN,適用於 UniFi、pfSense/OPNsense 和 MikroTik 設備,包括交換器 trunk 設定、防火牆規則和無線 SSID 對應。當需要在 UniFi、pfSense/OPNsense 或 MikroTik 上將家庭網路分割成 IoT、訪客、信任和伺服器 VLAN 時使用。

homelab-vlan-segmentation 是什麼?

此技能詳細說明如何將家庭網路分割成隔離的 VLAN,以防止 IoT 設備、訪客和主要電腦互相通訊。它提供了一個清晰的 VLAN 設計模板(信任、IoT、伺服器、訪客、管理),並在 UniFi、pfSense/OPNsense 和 MikroTik 平台上提供逐步指令。內容涵蓋 VLAN 建立、SSID 對應、交換器 trunk 與 access 端口設定,以及關鍵的防火牆規則,以確保分段安全。此外,還包含常見反模式(例如建立 VLAN 但未新增防火牆規則)和最佳實踐(例如將 Pi-hole 放在伺服器 VLAN 並允許所有 VLAN 存取 DNS),以幫助使用者避免錯誤並最大化安全性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/homelab-vlan-segmentation

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

家庭實驗室 VLAN 分割

如何將家庭網路分成隔離的 VLAN,讓 IoT 設備、訪客和主要電腦無法互相通訊。這是家庭網路最具影響力的安全升級。

此處顯示的所有防火牆規則都會在分段之間增加隔離——它們不會移除現有的保護。請在維護時段內套用變更,並在繼續下一步之前,驗證每個步驟後各分段之間的連線能力。

使用時機

  • 首次在家庭網路上設定 VLAN
  • 隔離 IoT 設備(智慧燈泡、攝影機、電視)與信任設備
  • 建立無法存取家庭設備的訪客 Wi-Fi 網路
  • 向不熟悉 VLAN 概念的人解釋其運作方式
  • 設定 trunk 端口、access 端口和 SSID 到 VLAN 的對應
  • 在 pfSense/OPNsense/UniFi 上疑難排解 VLAN 間路由或防火牆規則問題

運作原理

沒有 VLAN——扁平網路:
  所有設備都在 192.168.1.0/24
  智慧電視(潛在惡意軟體)→ 可以存取你的 NAS、電腦、一切

有 VLAN:
  VLAN 10 — 信任      192.168.10.0/24  (電腦、手機、筆電)
  VLAN 20 — IoT       192.168.20.0/24  (智慧電視、燈泡、攝影機)
  VLAN 30 — 伺服器    192.168.30.0/24  (NAS、樹莓派、虛擬機)
  VLAN 40 — 訪客      192.168.40.0/24  (訪客 Wi-Fi)
  VLAN 99 — 管理      192.168.99.0/24  (交換器/AP 網頁介面)

  智慧電視 → 被封鎖,無法存取 192.168.10.0/24 和 192.168.30.0/24
  訪客 → 僅能上網,看不到任何家庭設備

VLAN 設計模板

VLAN  名稱       子網域              閘道             用途
10    信任        192.168.10.0/24     192.168.10.1    電腦、手機、筆電
20    iot        192.168.20.0/24     192.168.20.1    智慧家庭設備
30    伺服器      192.168.30.0/24     192.168.30.1    NAS、樹莓派、自託管服務
40    訪客        192.168.40.0/24     192.168.40.1    訪客 Wi-Fi
99    管理        192.168.99.0/24     192.168.99.1    網路設備網頁介面

範例

配備 UniFi AP 和受管交換器的典型家庭實驗室:

情境:三房住宅,UniFi Dream Machine + UniFi 8 埠交換器 + 2 個 AP

VLAN 10 — 信任    192.168.10.0/24   MacBook、iPhone、iPad
VLAN 20 — IoT     192.168.20.0/24   Nest 恆溫器、Philips Hue、Ring 門鈴、智慧電視
VLAN 30 — 伺服器  192.168.30.0/24   Synology NAS (192.168.30.10)、Pi-hole (192.168.30.2)
VLAN 40 — 訪客    192.168.40.0/24   訪客 Wi-Fi — 僅能上網

SSID → VLAN 對應:
  "Home"      → VLAN 10 (WPA2,強密碼,僅信任設備)
  "IoT"       → VLAN 20 (WPA2,單獨密碼,印在路由器上供設定使用)
  "Guest"     → VLAN 40 (WPA2,可隨意分享的簡單密碼)

交換器連接埠行為:
  連接埠 1  → trunk 到路由器(標記 VLAN 10、20、30、40、99)
  連接埠 2  → trunk 到 AP(標記 VLAN 10、20、40;AP 處理每個 SSID 的標記)
  連接埠 3  → access VLAN 30(NAS — 未標記,無需 VLAN 感知)
  連接埠 4  → access VLAN 30(Pi-hole — 未標記)
  連接埠 5–8 → access VLAN 10(有線工作站)

防火牆規則套用(所有規則皆增加隔離,不會移除現有保護):
  IoT → 信任:封鎖
  IoT → 伺服器:封鎖,但允許 192.168.30.2:53 (Pi-hole DNS)
  IoT → 網際網路:允許
  訪客 → 本地網路:封鎖
  訪客 → 網際網路:允許
  信任 → 所有地方:允許

UniFi 設定

在 UniFi 控制器中建立網路

設定 → 網路 → 建立新網路

針對每個 VLAN:
  名稱:IoT
  用途:企業  (提供 DHCP + 路由)
  VLAN ID:20
  網路:192.168.20.0/24
  閘道 IP:192.168.20.1
  DHCP:啟用
  DHCP 範圍:192.168.20.100 – 192.168.20.254

將 SSID 對應到 VLAN(UniFi)

設定 → WiFi → 建立新 WiFi

  名稱:IoT-Network
  密碼:<單獨密碼>
  網路:IoT  ← 在此選擇你的 VLAN
  # 所有連接到此 SSID 的設備都會進入 VLAN 20

  名稱:Guest
  密碼:<訪客密碼>
  網路:Guest
  訪客政策:啟用  ← 同時將訪客彼此隔離

UniFi 防火牆規則(流量規則)

設定 → 流量與安全性 → 流量規則

# 封鎖 IoT 存取信任 VLAN
  動作:封鎖
  類別:本地網路
  來源:IoT (192.168.20.0/24)
  目的地:信任 (192.168.10.0/24)

# 僅允許 IoT 存取網際網路
  動作:允許
  來源:IoT
  目的地:網際網路

# 封鎖訪客存取所有本地網路
  動作:封鎖
  來源:Guest
  目的地:本地網路

pfSense / OPNsense 設定

建立 VLAN

介面 → 指派 → VLAN → 新增

  父介面:em1  (你的 LAN 網卡)
  VLAN 標籤:20
  描述:IoT

# 對每個 VLAN 重複,然後將每個 VLAN 指派到一個介面:
介面 → 指派 → 新增
  選擇你建立的 VLAN → 點選新增
  啟用該介面,設定 IP 為閘道位址 (192.168.20.1/24)

為每個 VLAN 設定 DHCP

服務 → DHCP 伺服器 → 選擇你的 VLAN 介面

  啟用 DHCP
  範圍:192.168.20.100 到 192.168.20.254
  DNS 伺服器:192.168.30.2  ← 如果有的話,Pi-hole IP

防火牆規則(pfSense/OPNsense)

# 規則從上到下處理,第一個符合者勝出。

# 在 IoT 介面(VLAN 20)上:
  規則 1:允許 IoT → Pi-hole DNS  ← 必須在 RFC1918 封鎖規則之前
    協定:UDP/TCP
    來源:IoT 網路
    目的地:192.168.30.2 埠 53
    動作:允許

  規則 2:封鎖 IoT → RFC1918(所有私有 IP 範圍)
    協定:任意
    來源:IoT 網路
    目的地:RFC1918  (192.168.0.0/16、10.0.0.0/8、172.16.0.0/12)
    動作:封鎖

  規則 3:允許 IoT → 網際網路
    協定:任意
    來源:IoT 網路
    目的地:任意
    動作:允許

# 在信任介面(VLAN 10)上:
  允許所有(信任設備可存取一切)
    來源:信任網路
    目的地:任意
    動作:允許

# 需要特定本地服務的 IoT 設備的其他例外:
  插入在規則 2(RFC1918 封鎖)之前:
    協定:TCP
    來源:IoT 網路
    目的地:192.168.30.x 埠 8123  ← Home Assistant
    動作:允許

MikroTik 設定

# 步驟 1:建立橋接器並啟用 VLAN 過濾
/interface bridge
add name=bridge vlan-filtering=yes

# 步驟 2:將實體連接埠加入橋接器
# trunk 連接埠到路由器/上行鏈路(標記所有 VLAN)
/interface bridge port
add bridge=bridge interface=ether1 frame-types=admit-only-vlan-tagged

# access 連接埠給信任設備(未標記 VLAN 10)
/interface bridge port
add bridge=bridge interface=ether2 pvid=10 frame-types=admit-only-untagged-and-priority-tagged

# access 連接埠給 IoT 設備(未標記 VLAN 20)
/interface bridge port
add bridge=bridge interface=ether3 pvid=20 frame-types=admit-only-untagged-and-priority-tagged

# 步驟 3:定義哪些 VLAN 允許在哪個連接埠上
/interface bridge vlan
add bridge=bridge tagged=ether1 untagged=ether2 vlan-ids=10
add bridge=bridge tagged=ether1 untagged=ether3 vlan-ids=20

# 步驟 4:在橋接器上建立 VLAN 介面(閘道 IP)
/interface vlan
add interface=bridge name=vlan10 vlan-id=10
add interface=bridge name=vlan20 vlan-id=20

# 步驟 5:指派閘道 IP
/ip address
add interface=vlan10 address=192.168.10.1/24
add interface=vlan20 address=192.168.20.1/24

# 步驟 6:DHCP 池與伺服器
/ip pool
add name=pool-trusted ranges=192.168.10.100-192.168.10.254
add name=pool-iot ranges=192.168.20.100-192.168.20.254

/ip dhcp-server
add interface=vlan10 address-pool=pool-trusted name=dhcp-trusted
add interface=vlan20 address-pool=pool-iot name=dhcp-iot

/ip dhcp-server network
add address=192.168.10.0/24 gateway=192.168.10.1
add address=192.168.20.0/24 gateway=192.168.20.1

# 步驟 7:防火牆——封鎖 IoT 存取信任 VLAN
/ip firewall filter
add chain=forward src-address=192.168.20.0/24 dst-address=192.168.10.0/24 \
    action=drop comment="封鎖 IoT 到信任"

交換器 Trunk 與 Access 連接埠

# Trunk 連接埠:承載多個 VLAN(標記)——連接交換器到交換器、交換器到路由器、交換器到 AP
# Access 連接埠:承載一個 VLAN(未標記)——連接到終端設備(電腦、攝影機、NAS)

# 連接到路由器的受管交換器連接埠應為 trunk:
  允許的 VLAN:10、20、30、40、99

# 連接到電腦的連接埠應為 access 連接埠:
  VLAN:10(信任)
  無標記——電腦不知道也不關心 VLAN

# 連接到 AP 的連接埠必須是 trunk:
  AP 將來自每個 SSID 的流量標記上正確的 VLAN ID
  允許的 VLAN:10、20、40(AP 服務的任何 SSID)

反模式

# 不好:建立 VLAN 但未新增防火牆規則
# 沒有防火牆規則的 VLAN 無法提供安全性——VLAN 間路由預設是開放的
# 好:在建立 VLAN 後立即新增明確的封鎖規則

# 不好:將 Pi-hole 放在 IoT VLAN 中
# IoT 設備可以存取它,但信任設備不行(除非有額外規則)
# 好:Pi-hole 在伺服器 VLAN 中,並設定規則允許所有 VLAN 存取埠 53

# 不好:原生 VLAN 等於管理 VLAN
# 未標記流量進入你的管理 VLAN 會啟用 VLAN 跳躍攻擊
# 好:使用專用的未使用 VLAN 作為原生(例如 VLAN 999),讓管理流量保持標記

# 不好:IoT SSID 和信任 SSID 使用相同的 Wi-Fi 密碼
# 任何知道密碼的人可以將 IoT 設備連接到錯誤的分段

最佳實踐

  • 從 4 個 VLAN 開始:信任、IoT、伺服器、訪客——根據需要增加更多
  • 將 Pi-hole 放在伺服器 VLAN(192.168.30.x)中
  • 新增一條防火牆規則,允許所有 VLAN 存取 Pi-hole IP 的 DNS(埠 53)——在任何 RFC1918 封鎖規則之前
  • 每次規則變更後測試隔離:從 IoT VLAN 嘗試 ping 一個信任設備——應失敗
  • 使用管理 VLAN 來管理交換器和 AP 網頁介面,並僅限制信任 VLAN 的存取
  • 以表格(VLAN ID、名稱、子網域、用途)記錄你的 VLAN 設計

相關技能

  • homelab-network-setup
  • homelab-pihole-dns
  • homelab-wireguard-vpn

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能