Communitygithub.com

家庭实验室VLAN划分

将家庭网络划分为物联网、访客、受信和服务器的VLAN,支持UniFi、pfSense/OPNsense和MikroTik设备,包括交换机Trunk配置、防火墙规则和无线SSID映射。当需要在UniFi、pfSense/OPNsense或MikroTik上将家庭网络拆分为物联网、访客、受信和服务器VLAN时使用。

家庭实验室VLAN划分 是什么?

这是一个针对家庭网络VLAN划分的AI助手技能,旨在帮助用户将家庭网络分割成多个隔离的VLAN,以实现物联网设备、访客网络、受信任设备和服务器之间的安全隔离。该技能支持UniFi、pfSense/OPNsense和MikroTik三大主流平台,提供了从VLAN设计模板到具体配置命令的完整指南。它包含了详细的VLAN划分示例、交换机端口配置、SSID到VLAN的映射规则、防火墙规则以及常见反模式和最佳实践。通过本技能,用户可以创建标准的VLAN布局(如受信VLAN 10、物联网VLAN 20、服务器VLAN 30、访客VLAN 40和管理VLAN 99),并配置相应的防火墙规则来阻止物联网设备访问受信网络,仅允许其访问互联网。技能还特别强调了安全注意事项,如避免将Pi-hole放在物联网VLAN、避免使用原生VLAN作为管理VLAN,以及建议在每个规则变更后测试隔离效果。

兼容平台~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,使物联网设备、访客和您的主PC无法相互通信。这是家庭网络中最有影响力的安全升级。

此处展示的所有防火墙规则都是在各网段之间添加隔离——它们不会移除现有的保护措施。请在一个维护窗口内应用更改,并在进入下一步之前验证各网段之间的连通性。

何时使用

  • 首次在家庭网络上设置VLAN
  • 隔离物联网设备(智能灯泡、摄像头、电视)与受信任设备
  • 创建一个无法访问家庭设备的访客Wi-Fi网络
  • 向不熟悉VLAN概念的人解释VLAN的工作原理
  • 配置Trunk端口、Access端口和SSID到VLAN的映射
  • 在pfSense/OPNsense/UniFi上排查VLAN间路由或防火墙规则问题

工作原理

没有VLAN——扁平网络:
  所有设备在192.168.1.0/24上
  智能电视(潜在恶意软件)→ 可以访问您的NAS、PC等一切设备

有了VLAN:
  VLAN 10 — 受信    192.168.10.0/24  (PC、手机、笔记本)
  VLAN 20 — 物联网  192.168.20.0/24  (智能电视、灯泡、摄像头)
  VLAN 30 — 服务器  192.168.30.0/24  (NAS、Pi、虚拟机)
  VLAN 40 — 访客    192.168.40.0/24  (访客Wi-Fi)
  VLAN 99 — 管理    192.168.99.0/24  (交换机/AP的Web管理界面)

  智能电视 → 被阻止访问192.168.10.0/24和192.168.30.0/24
  访客 → 仅限互联网,无法看到任何家庭设备

VLAN设计模板

VLAN  名称        子网                网关             用途
10    受信        192.168.10.0/24    192.168.10.1    PC、手机、笔记本
20    物联网      192.168.20.0/24    192.168.20.1    智能家居设备
30    服务器      192.168.30.0/24    192.168.30.1    NAS、Pi、自托管服务
40    访客        192.168.40.0/24    192.168.40.1    访客Wi-Fi
99    管理        192.168.99.0/24    192.168.99.1    网络设备Web管理界面

示例

带有UniFi AP和托管交换机的典型家庭实验室:

场景:三居室房屋,UniFi Dream Machine + UniFi 8口交换机 + 2个AP

VLAN 10 — 受信    192.168.10.0/24   MacBook、iPhone、iPad
VLAN 20 — 物联网  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  → 到AP的Trunk(标记VLAN 10、20、40;AP处理每个SSID的标记)
  端口3  → 接入VLAN 30(NAS — 未标记,不需要VLAN感知)
  端口4  → 接入VLAN 30(Pi-hole — 未标记)
  端口5–8 → 接入VLAN 10(有线工作站)

防火墙规则(所有规则添加隔离,不移除现有保护):
  物联网 → 受信:阻止
  物联网 → 服务器:阻止,除192.168.30.2:53(允许Pi-hole DNS)
  物联网 → 互联网:允许
  访客 → 本地网络:阻止
  访客 → 互联网:允许
  受信 → 所有位置:允许

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防火墙规则(流量规则)

设置 → 流量与安全 → 流量规则

# 阻止物联网访问受信VLAN
  操作:阻止
  类别:本地网络
  来源:物联网 (192.168.20.0/24)
  目标:受信 (192.168.10.0/24)

# 允许物联网仅访问互联网
  操作:允许
  来源:物联网
  目标:互联网

# 阻止访客访问所有本地网络
  操作:阻止
  来源:访客
  目标:本地网络

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)

# 规则从上到下处理,第一个匹配生效。

# 在物联网接口(VLAN 20)上:
  规则1:允许物联网 → Pi-hole DNS  ← 必须位于RFC1918阻止规则之前
    协议:UDP/TCP
    来源:物联网网络
    目标:192.168.30.2 端口53
    操作:允许

  规则2:阻止物联网 → RFC1918(所有私有IP范围)
    协议:任意
    来源:物联网网络
    目标:RFC1918(192.168.0.0/16、10.0.0.0/8、172.16.0.0/12)
    操作:阻止

  规则3:允许物联网 → 互联网
    协议:任意
    来源:物联网网络
    目标:任意
    操作:允许

# 在受信接口(VLAN 10)上:
  允许所有(受信设备可以访问一切)
    来源:受信网络
    目标:任意
    操作:允许

# 针对需要特定本地服务的物联网设备的额外例外:
  在规则2(RFC1918阻止规则)之前插入:
    协议:TCP
    来源:物联网网络
    目标: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

# 受信设备的接入端口(未标记VLAN 10)
/interface bridge port
add bridge=bridge interface=ether2 pvid=10 frame-types=admit-only-untagged-and-priority-tagged

# 物联网设备的接入端口(未标记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:防火墙 — 阻止物联网访问受信VLAN
/ip firewall filter
add chain=forward src-address=192.168.20.0/24 dst-address=192.168.10.0/24 \
    action=drop comment="阻止物联网到受信"

交换机Trunk与Access端口

# Trunk端口:承载多个VLAN(带标记)— 连接交换机到交换机、交换机到路由器、交换机到AP
# Access端口:承载一个VLAN(未标记)— 连接终端设备(PC、摄像头、NAS)

# 连接到路由器的托管交换机端口应为Trunk:
  允许的VLAN:10、20、30、40、99

# 连接到PC的端口应为Access端口:
  VLAN:10(受信)
  无标记 —  PC不关心也不了解VLAN

# 连接到AP的端口必须是Trunk:
  AP将来自每个SSID的流量标记上正确的VLAN ID
  允许的VLAN:10、20、40(AP服务的任何SSID)

反模式

# 错误:创建VLAN但不添加防火墙规则
# 没有防火墙规则的VLAN无法提供安全性——VLAN间路由默认是开放的
# 正确:创建VLAN后立即添加明确的阻止规则

# 错误:将Pi-hole放在物联网VLAN中
# 物联网设备可以访问它,但受信设备无法访问(除非添加额外规则)
# 正确:Pi-hole放在服务器VLAN中,并允许所有VLAN访问端口53

# 错误:原生VLAN等于管理VLAN
# 未标记流量落入您的管理VLAN中,使得VLAN跳转攻击成为可能
# 正确:使用一个专用的未使用VLAN作为原生VLAN(例如VLAN 999),让管理流量保持带标记

# 错误:物联网SSID和受信SSID使用相同的Wi-Fi密码
# 任何知道密码的人都可以将物联网设备连接到错误的网段

最佳实践

  • 从4个VLAN开始:受信、物联网、服务器、访客——根据需要再添加更多
  • 将Pi-hole放在服务器VLAN中(192.168.30.x)
  • 添加一个防火墙规则,允许从所有VLAN到Pi-hole IP的DNS(端口53)——在任何RFC1918阻止规则之前
  • 每次更改规则后测试隔离:从物联网VLAN尝试ping一个受信设备——应该失败
  • 为交换机和AP的Web管理界面使用管理VLAN,并仅限制受信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.

相关技能