🧭 一、背景說明
在 OPNsense 25.x 版本後,GeoIP 功能已完全整合至核心系統中,不再需要安裝 os-geoip 外掛。
但同時,MaxMind 授權機制也改變:
不再只用 License Key,現在必須同時使用 Account ID 與 License Key 在 URL 中進行授權。
⚙️ 二、在 MaxMind 建立授權資料
Step 1️⃣ :註冊 MaxMind 帳戶
- 前往 https://www.maxmind.com/en/geolite2/signup
- 註冊免費帳號,登入後開啟個人主頁。
Step 2️⃣ :查找 Account ID
- 登入後,進入右上角 My Account。
- 在頁面上方會看到你的 Account ID(例如
123456)。
→ 這是新版授權流程中必要的一部分。
Step 3️⃣ :建立 License Key
- 前往:My Account → Manage License Keys
或直接訪問
https://www.maxmind.com/en/accounts/current/license-key - 點擊 「Generate New License Key」。
- 輸入描述(例如
OPNsense GeoIP),
並勾選:✅ Yes, this key will be used for GeoIP Update Program - 建立完成後,你會獲得一組長字串,例如:
AbCdEfGhIjKlMnOpQrStUvWxYz123456
🌐 三、在 OPNsense 中設定 GeoIP URL
- 登入 OPNsense Web GUI
- 前往:
防火牆 → 別名 → GeoIP 設定 (Firewall → Aliases → GeoIP settings) - 在「網址 (URL)」欄中輸入以下格式的下載路徑:
https://AccountID:LicenseKey@download.maxmind.com/geoip/databases/GeoLite2-Country-CSV/download?suffix=zip📘 範例:https://123456:AbCdEfGhIjKlMnOpQrStUvWxYz123456@download.maxmind.com/geoip/databases/GeoLite2-Country-CSV/download?suffix=zip - 點擊 「套用 (Apply)」
✅ 四、驗證結果
成功後,頁面上會顯示:
- 最後更新 (Last Updated) → 顯示時間日期
- 範圍總數 (Total Ranges) → 顯示數百萬筆 IP
代表 GeoIP 資料庫已成功下載並生效。
🧩 五、建立 GeoIP 別名應用範例
🔹 封鎖特定國家
建立別名 BLOCK_CN_RU
在 GeoIP 中選擇:China、Russia
防火牆規則:
Action: Block
Source: BLOCK_CN_RU
Destination: any
🔹 僅允許特定國家 VPN 登入
建立別名 VPN_ALLOWED
選擇 Taiwan、Malaysia、Thailand
Action: Pass
Source: VPN_ALLOWED
Destination: WAN address (VPN Port)
⚡ 六、注意事項與最佳實務
| 項目 | 建議 |
|---|---|
| 授權機制 | 需同時使用 Account ID 與 License Key |
| URL 格式 | 必須為 完整 URL 含 @download.maxmind.com |
| 資料來源 | 使用 GeoLite2-Country ( CSV 格式 ) |
| 更新頻率 | 預設每月自動更新,可手動按 Apply 重抓 |
| 效能建議 | 將 Firewall Maximum Table Entries 設為 4 M 以上 |
🎯 七、總結
| 項目 | 舊版 (≤ 24.7) | 新版 (≥ 25.x) |
|---|---|---|
| GeoIP 功能 | 外掛 os-geoip | 內建核心 |
| 授權方式 | License Key 單一字串 | 需 Account ID + License Key |
| URL 輸入位置 | Services → MaxMind | Firewall → Aliases → GeoIP 設定 |
| URL 格式 | 自動產生 | 需手動輸入完整 https://AccountID:LicenseKey@… |