> For the complete documentation index, see [llms.txt](https://openwrt-nctu.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openwrt-nctu.gitbook.io/project/openwrt-functions/openwrt-login-from-wan.md).

# 從 WAN 登入 OpenWRT

當我們要操控 OpenWRT 時，有兩種不同的方式: SSH 直接更改 OpenWRT 的設定，或是使用網頁透過 LuCi 來更改設定。在原本的 OpenWRT 架構下，只有在 WiFi AP 管轄下的 WLAN  (或是有線的 LAN 網路孔) 才能連上 OpenWRT，這樣一來，不論是透過有線或是無線的方式，都使更改設定變得困難。

為了要從遠方更改 OpenWRT 設定，也就是從 WAN 來存取 OpenWRT 需要進行兩項設定:

1. NAT 的對應: 從 WAN 的 IP (如: 192.168.2.100) 轉換到 LAN 上 OpenWRT 的 IP (如: 192.168.9.1)，在 LAN 上 OpenWRT 的角色相當於 router，因此，IP 應該是 192.168.X.1。
2. 軟體的存取權限。這部分要去修改 SSH server (dropbear) 的設定，對於 LuCi 來說，就沒有這個問題。

首先，我們先透過 LuCi 加入 NAT 的設定，路徑為 (Firewall -> Port Forwards)，加入兩組設定，分別對應於 WAN:80 <- TCP -> OpenWRT: 80 以及 WAN:22 <- TCP -> OpenWRT: 22，如下圖所示。

![NAT設定](/files/-LQIP9KYjrTQ-Ug4olEQ)

接著，要對 SSH server 進行設定 (System -> Administration)，開放從 WAN 來的登入資訊。

![](/files/-LQIZxbIRZRC_A2cnB8X)

完成後，就可以從 WAN 登入 OpenWRT。

![](/files/-LQIaJMpRoU3aDrD4NI1)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openwrt-nctu.gitbook.io/project/openwrt-functions/openwrt-login-from-wan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
