# 架設一個訪客用的無線網路

這其實是來自 OpenWRT 官方教程，這裡只是重複操作並翻譯，原始內容來自:

* <https://openwrt.org/docs/guide-user/network/wifi/guestwifi/guest-wlan>
* <https://openwrt.org/docs/guide-user/network/wifi/guestwifi/guest-wlan-webinterface>

第一個網址透過指令列操作，第二個網址則透過 LuCi 操作，以下文章以第一個網址為操作範例。這個教程中，修改了以下 4 設定檔: `/etc/config/network`、`/etc/config/wireless`、`/etc/config/dhcp` 以及 `/etc/config/firewall`。我們將對這些設定進行記錄:

## 子網路設定: /etc/config/network

加入一個新的 interface，也就是一個新的子網路。此子網路也就是為了新建立的訪客無線網路來服務，也因此，我們可以把訪客的資料從原有的內部網路中分離。關於 interface 的設定，可以參考[之前的文章](https://openwrt-nctu.gitbook.io/project/sdnbased-network/zai-openwrt-shang-jia-vlan#interface-ding-de-ming)中的說明。

```
config interface 'guest'
       option proto 'static'
       option ipaddr '10.0.0.1'
       option netmask '255.255.255.0'
```

## 無線網路設定: /etc/config/wireless

接著，增加一個新的 SSID，並讓其附屬於新建的 guest 網路，關於多個 SSID 的設定可以參考[之前的紀錄](https://openwrt-nctu.gitbook.io/project/openwrt-gong-neng/lu-ssid-de-ding)。

```
config wifi-iface 'default_radio2'
        option device 'radio1'
        option network 'guest'
        option mode 'ap'
        option encryption 'none'
        option ssid 'WiSDON-FREE'
        option disabled '0'
        option maxassoc '5'
        option maxrate '500'
```

## DHCP 設定: /etc/config/dhcp

設定 DHCP 的設定，讓連上的使用者可以自動拿到 IP。在 DHCP 設定中，主要有三個參數: 起始的 IP 尾數 (start)、DHCP 最大的數量限制、以及租約 (lease) 的持續時間，設定如下:

```
config dhcp 'guest'
        option interface 'guest'
        option start '50'
        option limit '50'
        option leasetime '1h'
```

## 防火牆設定: /etc/config/firewall

防火牆的設置，我們先用最簡單的設置，也就只是確保網路通訊可以進行，並沒有給予過多的限制。關於 OpenWRT 的防火牆設置應該可以開一篇文章專門說明，不過，已經有許多文章說明此處的設定，因此，大駕可以先參考網路上的[資源](https://openwrt.org/docs/guide-user/firewall/firewall_configuration)。

```
# for the guest-waln
config zone
        option name 'guest'
        option network 'guest'
        option input 'REJECT'
        option forward 'REJECT'
        option output 'ACCEPT'

# Allow Guest -> Internet
config forwarding
        option src 'guest'
        option dest 'wan'

# Allow DNS Guest -> Router
# Client DNS queries originate from dynamic UDP ports (>1023)
config rule
        option name 'Allow DNS Queries'
        option src 'guest'
        option dest_port '53'
        option proto 'tcp udp'
        option target 'ACCEPT'

# Allow DHCP Guest -> Router
# DHCP communication uses UDP ports 67-68
config rule
        option name 'Allow DHCP request'
        option src 'guest'
        option src_port '67-68'
        option dest_port '67-68'
        option proto 'udp'
        option target 'ACCEPT'
```

原本文章中，事實上有對防火牆做更多的設定，來限制訪客的行為，有興趣可以參考原始的教學文件。

## 網路的流量限制

完成以上四個步驟，已經產生一個可供上網的訪客無線網路。接下來，我們要對此訪客無線網路進行限制，有以下兩種方式: 第一、在 wireless 中限制連上的使用者數量以及頻寬，如在無線網路中所做的設定。第二、透過 OpenWRT 上的其他套件，如: wshaper、qos-scripts、sqm-scripts，來達成需求。

這部分在原始教程中有說明，不過尚未實作，因此先不紀錄。


---

# Agent Instructions: 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/experiment-sdn/openwrt-guest-network.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.
