💡 Hairpin NAT (NAT Loopback) — Allow Internal Users to Access Internal Servers Using Public Domain Names 🧱 1. The Scenario In many corporate or home networks, administrators use NAT (Network Address Translation) to expose internal servers to the Internet.For example: External users can access mail.example.com without issues.However, when internal users try to access the…
Category: Linux
About Linux Tech
Hairpin NAT vs Split DNS:哪種才是正確做法?
🧱 一、發生的情境 在企業或家庭網路中,我們常透過 NAT(Network Address Translation) 將內部伺服器對外提供服務。例如: 這時候,外部用戶從網際網路訪問 mail.example.com 一切正常。但公司內部用戶如果也輸入相同網址(mail.example.com),卻發現: ❌ 無法連線、逾時、或導向錯誤的主機。 這就是典型的 Hairpin NAT(又稱 NAT Loopback) 問題。 🧭 二、問題的本質 NAT 裝置(例如 Router、防火牆、OPNsense、Linux Gateway)收到封包時的邏輯如下: 簡單說,NAT 預設只處理外部 → 內部 的轉換,而不會自我迴圈。這就像你寄信到自己的郵局地址,但郵差不知道該送回自己家。 ⚙️ 三、Hairpin NAT 的運作原理 Hairpin NAT 讓「內部客戶端 → NAT 公網 IP → 內部伺服器」的封包能正確繞回內網。 流程如下: 最關鍵的部分是第 3 步的 SNAT: 如果不改變來源 IP,Server 看到來源為同網段(192.168.1.20),會直接回封包,不經 NAT,導致連線中斷。 🧩 四、常見環境設定方式 🔹 1️⃣…
Fixing Default Route Override on Ubuntu (WMS Server on AWS)
In our AWS environment, the WMS server (Warehouse Management System) operates strictly within the internal network.All external traffic is routed through a single NAT gateway — TPM1 (172.17.10.10). However, after some time in operation, the WMS server’s default route keeps getting replaced with 172.17.10.1, breaking external connectivity and disrupting communication with other systems. 🔍 Problem…
AWS主機:預設路由被 DHCP 覆寫的解決方案(Ubuntu + Netplan)
在 AWS 上的 WMS 主機僅提供內網服務,所有外部連線都統一經由 TPM1 (172.17.10.10) 這台主機進行 NAT 轉址。但實際運行一段時間後,發現主機的預設路由 (default gateway) 會不定期被系統自動改回 172.17.10.1,導致外部通訊中斷。 問題現象 執行 route -n 或 ip route 觀察到如下狀況: 手動設定的 gateway (172.17.10.10) 經常在系統重新啟動或 DHCP 更新租約後消失。 問題原因 檢視系統日誌 (journalctl -u systemd-networkd -b) 後,發現關鍵訊息: 👉 原因是:systemd-networkd 透過 DHCP 自動取得 IP 時,也同時套用了 DHCP 伺服器提供的 gateway(172.17.10.1)。因此,每當 DHCP 重新租約,就會覆蓋掉手動設定的路由。 解決思路 我們要達成兩個目標: Ubuntu 20.04 之後的版本使用 Netplan + systemd-networkd,所以最佳做法是直接在…
Fixing WordPress REST API Error: cURL Error 28 in Docker Environments
When running WordPress, you might encounter this warning in your Site Health Check page: REST API ErrorThe REST API is one way WordPress and other applications communicate with the server. Error: (http_request_failed) cURL error 28: Connection timed out after 10001 milliseconds This message indicates that your WordPress instance failed to communicate with itself through the…
解決 WordPress REST API 錯誤:cURL error 28 的實戰過程
在使用 WordPress 時,如果在「網站健康檢查」頁面看到以下訊息: REST API 發生錯誤REST API 是 WordPress 及其他應用程式與伺服器進行通訊的一種方式。以區塊編輯器畫面為例,它便是依賴 REST API 來顯示與儲存內容。測試 REST API 時發生錯誤:REST API 回應: (http_request_failed) cURL error 28: Connection timed out after 10001 milliseconds 代表你的 WordPress 無法透過內部網路與自己通訊。這種錯誤看似奇怪,實際上非常常見,尤其當你的網站部署在 Docker 或反向代理環境 中。 🔍 問題現象 WordPress 會在檢查 REST API 時,嘗試透過 HTTP 請求連到自己的網址(例如 https://www.nuface.tw/wp-json/)。但如果容器內的 DNS 無法解析這個網域,就會出現逾時錯誤 cURL error 28。 簡單來說,就是「WordPress 呼叫自己時,找不到自己」。 🧠 問題原因分析 在 Docker…
Adjusting Display Language in Linux (Fixing Locale Issues in Ubuntu 24)
After upgrading to Ubuntu 24, you might find that Vim displays garbled or unreadable Chinese characters.This issue usually occurs when the terminal encoding and Vim’s internal encoding settings don’t match.During the upgrade from Ubuntu 22 → 24, the system’s default locale may have been reset to C or POSIX, which are non-UTF-8 environments. 🔍 Step-by-Step…
Linux 中調整顯示語系
升級到 Ubuntu 24 之後,Vim 顯示中文亂碼。原因通常是「終端機編碼 / Vim 編碼設定不一致」,Ubuntu 22 → 24 預設 locale 可能被重置成 C 或 POSIX,不是 UTF-8。 🔍 排查步驟 1. 看系統 locale 如果看到類似: 那就不是 UTF-8。 Ubuntu 24 預設應該是: 或至少是 en_US.UTF-8。 2. 修正 locale 如果缺中文 locale,先裝: 設定環境: 登出再登入,或直接測:
Troubleshooting PPPoE Issues After Upgrading to Ubuntu 24
After upgrading from Ubuntu 22 to Ubuntu 24, many users have found that PPPoE tools—such as pppoeconf, pppoe-discovery, or pppd-pppoe—no longer work properly.This is mainly due to changes in pppd behavior and kernel module handling introduced in newer Ubuntu releases. 🔍 Why PPPoE Fails on Ubuntu 24 1. pppoeconf Has Been Removed Starting from Ubuntu…
PPPoE 問題處理
在 Ubuntu 22 升級到 Ubuntu 24 之後,pppoe(通常指 pppoeconf / pppoe-discovery / pppd-pppoe 等工具)會遇到無法正常運作的情況。這主要和 pppd 與內核模組的變化 有關。 為什麼 Ubuntu 24 之後 PPPoE 會失效? 檢查與排錯步驟 解決方案 方法一:繼續用傳統 pppd 方法二:改用 NetworkManager 如果是桌面或伺服器有啟用 NetworkManager,可以直接用: nm-connection-editor 方法三:使用 systemd service 自動化 建立一個 systemd unit [Unit]Description=PPPoE connectionAfter=network.target [Service]ExecStart=/usr/bin/pon dsl-providerExecStop=/usr/bin/poff dsl-providerRemainAfterExit=yes [Install]WantedBy=multi-user.target 儲存為 /etc/systemd/system/pppoe.service,然後啟用: 先檢查 pppoe 模組是否有載入(lsmod | grep ppp),這通常是 Ubuntu 24 升級後最常見的問題。