Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

網路基礎筆記:三層交換機原理與 NAT 地址轉換詳細解析

編輯:Linux 系統常見問題解答

一、 三層交換機核心原理

三層交換機解決了「單臂路由」的流量瓶頸,核心機制是一次路由、多次交換:

  1. 首次通訊時,查詢路由表決定下一跳,並記錄來源 MAC、目的 MAC、VLAN 對應關係,建立「路由表 + ARP 表」的映射快取。
  2. 後續同 VLAN 間通訊,直接由硬體高速轉發,不再經由 CPU 處理路由查找,大幅提升效能。

關鍵特性

  • 可配置路由表,透過建立虛擬 VLAN 介面(SVI)為各 VLAN 指定閘道 IP。
  • 交換機本身的管理 IP 通常配置於專用管理 VLAN 的虛擬介面上。
  • 每個 VLAN 介面擁有獨立 MAC 位址。

基本配置步驟

1. 開啟虛擬 VLAN 介面:interface vlan 10
2. 啟用路由功能:ip routing
3. 配置 VLAN 介面 IP:ip address 192.168.10.1 255.255.255.0
4. 建立管理用 VLAN 介面(可選)

二、 NAT(網路位址轉換)三大模式

模式特點適用場景
靜態 NAT一對一:內網私有 IP 固定映射到公網公有 IP發布伺服器(Web、Mail 等)
動態 NAT多對多:內網 IP 從公有 IP 池自動取用內網主機上網,公有 IP 數量足夠時
PAT/NAPT(埠多工)多對一:內網 IP + 埠號 共用單一公有 IP最常見,解決 IPv4 稀缺,家用/企業上網

三、 路由器上 NAT 配置實戰指令

A. 靜態 NAT

configure terminal
ip nat inside source static 192.168.1.10 203.0.113.5
interface g0/0
 ip nat inside
interface g0/1
 ip nat outside

B. 動態 NAT

configure terminal
access-list 1 permit 172.16.0.0 0.0.0.255
ip nat pool MY_POOL 203.0.113.10 203.0.113.20 netmask 255.255.255.0
ip nat inside source list 1 pool MY_POOL
interface g0/0
 ip nat inside
interface g0/1
 ip nat outside

注意: 同一時間最多支援公有 IP 池大小的並發連線,用完即無法上網。

C. PAT(埠多工)

# 方式一:指定單一公有 IP
ip nat pool MY_POOL 203.0.113.5 203.0.113.5 netmask 255.255.255.0
ip nat inside source list 1 pool MY_POOL overload

# 方式二:直接使用外部介面 IP(適用於動態取得公網 IP 的場景)
ip nat inside source list 1 interface g0/1 overload
Copyright © Windows教程網 All Rights Reserved