橋接工作在 OSI 模型第 2 層(數據鏈路層),根據 MAC 地址轉發數據幀。交換機、網橋均屬橋接設備,能隔離衝突域,連接不同物理局域網。
以下配置將 Serial0 (WAN) 與 FastEthernet0 (LAN) 劃入橋接組 1,實現二層透明傳輸:
version 12.1
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname router
!
enable secret 5 $1$BE0q$hj.WBtIBYppMX3zyfaPbR1
!
memory-size iomem 25
ip subnet-zero
no ip routing ! 關鍵:關閉三層路由功能
!
interface Serial0
description 128k DL546267 connect to SZ
ip address 198.127.18.4 255.255.255.0
no ip route-cache
no fair-queue
bridge-group 1 ! 加入橋接組 1
!
interface FastEthernet0
ip address 198.127.18.3 255.255.255.0
no ip route-cache
speed auto
bridge-group 1 ! 加入橋接組 1
!
ip classless
no ip http server
!
bridge 1 protocol ieee ! 採用 IEEE 802.1D 標準
bridge 1 route ip ! 啟用橋接組內的 IP 路由 (IRB)
!
line con 0
transport input none
line aux 0
line vty 0 4
password csl
login
!
no scheduler allocate
end
no ip routing:必須全局關閉路由功能,否則接口 IP 會參與三層轉發,破壞橋接透明性。bridge-group <num>:將接口加入指定橋接組,同組接口構成同一廣播域。bridge <num> protocol ieee:指定生成樹協議為 IEEE 標準,防止環路。bridge <num> route ip:啟用整合路由橋接 (IRB),允許橋接組內部進行三層轉發(需配置 BVI 接口作為網關,此處簡化演示)。| 特性 | 橋接 (Layer 2) | 路由 (Layer 3) |
|---|---|---|
| 轉發依據 | MAC 地址 | IP 地址 |
| 廣播域 | 跨接口共享 | 接口隔離 |
| 適用場景 | 透明接入、擴展 LAN、非 IP 協議 | 互聯網接入、子網劃分、策略控制 |