VLAN (Virtual Local Area Network) 將物理網絡劃分為邏輯廣播域,提升安全性與管理靈活性。本文詳細演示思科路由器配置 VLAN 子接口 IP 的 5 步法,並附贈路由器/交換機 IP 配置、靜態/默認/浮動路由等高頻命令速查表。
場景:在 FastEthernet 4/0 物理接口下創建 VLAN 333 子接口,IP 192.168.1.13/24
! 1. 進入物理接口
host1(config)# interface fastEthernet 4/0
! 2. 封裝協議 (通常為 802.1Q)
host1(config-if)# encapsulation dot1Q 333
! 3. 創建子接口 (編號習慣與 VLAN ID 一致)
host1(config-if)# interface fastEthernet 4/0.333
! 4. 指定 VLAN ID (封裝命令已隱含,此行視具體 IOS 版本而定)
host1(config-subif)# encapsulation dot1Q 333
! 5. 配置 IP 地址
host1(config-subif)# ip address 192.168.1.13 255.255.255.0
host1(config-subif)# no shutdown
注意: 原文 encapsulation vlan 及 vlan id 333 非標準 Cisco IOS 命令,實際應用中請使用 encapsulation dot1Q <vlan-id>。
router(config)# interface fastethernet 0/1
router(config-if)# ip address 192.168.1.100 255.255.255.0
router(config-if)# no shutdown
switch(config)# interface vlan 1
switch(config-if)# ip address 192.168.1.100 255.255.255.0
switch(config-if)# no shutdown
router(config)# ip route 192.168.1.0 255.255.255.0 192.168.10.1
router(config)# ip route 0.0.0.0 0.0.0.0 192.168.10.1
router(config)# ip route 192.168.1.0 255.255.255.0 192.168.10.1 50
router(config)# ip route 0.0.0.0 0.0.0.0 192.168.10.1 50
switch(config)# ip default-gateway 192.168.2.254
switch(config-if)# ip address 192.168.1.1 255.255.255.0 secondary
write memory 或 copy running-config startup-config 保存