2026年1月22日 星期四

練習題:wan(P1)+lan(P2)(P3)同一個DHCP88分配

 練習題:wan(P1)+lan(P2)(P3)同一個DHCP88分配

這是一個非常標準的「靜態 IP (Static IP) + 區域網路 (LAN) DHCP」的設定需求。

為了達成您的目標,我們需要執行以下 5 個主要步驟。

  • WAN (外網) 接口是 `ether1  WAN IP `172.20.1.50` 是一個 IP 地址
  • LAN (內網) 接口是 `ether2` 和 `ether3

1. 建立 Bridge (橋接器)

因為您希望 `ether2` 和 `ether3` 都在同一個網段 (192.168.88.x),所以必須把這兩個孔綁定在一起。

/interface bridge

add admin-mac=08:55:31:FF:20:2D auto-mac=no comment=defconf name=bridge

/interface list

add comment=defconf name=WAN

add comment=defconf name=LAN

2.建立一個橋接介面,命名為 bridge-lan

/interface bridge

add name=bridge-lan

# 將 ether2 和 ether3 加入這個橋接器

/interface bridge port

add bridge=bridge-lan interface=ether2

add bridge=bridge-lan interface=ether3

3. 設定 IP 地址 (WAN 和 LAN)

這裡設定外網 IP 和內網 IP。

/ip address

# 設定 LAN IP (給橋接器,這樣 ether2,3 都會生效)

add address=192.168.88.1/24 interface=bridge-lan comment="LAN Gateway"

# 設定 WAN IP (請確認您的子網掩碼是否為 /24)

add address=172.20.1.50/24 interface=ether1 comment="WAN Static IP"

4. 設定路由 (Gateway) 與 DNS

這是為了讓路由器知道如何把資料傳出去給網際網路。

# 設定預設路由

# [重要] 請將 172.20.1.254 改為您實際的上層通訊閘 IP

/ip route

add gateway=172.20.1.254

5.設定 DNS 伺服器 (這裡使用 Google DNS,也可改為中華電信 168.95.1.1)

/ip dns

set servers=8.8.8.8,1.1.1.1 allow-remote-requests=yes

6. 設定 DHCP Server這步驟是為了讓插在 eth2, eth3 的電腦自動取得 IP。

# 1. 設定 IP 池 (Pool):定義可以發放的 IP 範圍

/ip pool

add name=dhcp-pool ranges=192.168.88.2-192.168.88.254

7. 設定 DHCP 網路屬性:告訴電腦拿到 IP 後,Gateway 和 DNS 要填什麼

/ip dhcp-server network

add address=192.168.88.0/24 gateway=192.168.88.1 dns-server=192.168.88.1

8. 啟動 DHCP 伺服器:綁定在 bridge-lan 上

/ip dhcp-server

add name=server1 interface=bridge-lan address-pool=dhcp-pool disabled=no

9. 設定防火牆 NAT (偽裝)Masquerade,沒有這一步,內網電腦無法上網。

/ip firewall nat

add action=masquerade chain=srcnat out-interface=ether1 comment="WAN Masquerade"

設定完成後,請檢查以下兩點以確保運作正常:

1. **WAN Gateway:** 您的上層設備 IP 是多少?如果不是 `172.20.1.254`,請務必在 `IP > Routes` 中修改 `0.0.0.0/0` 的 Gateway。

2. **WAN Subnet:** 您的 `172.20.1.50` 是 `/24` (255.255.255.0) 嗎?如果是 `/16` 或其他遮罩,請在 `IP > Addresses` 中修正。

如果不知道 Gateway 是多少,通常是該網段的 `.1` 或 `.254`,您可以嘗試 Ping 看看。

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。