使用hostapd在linux上建立自己的WLAN-AP
系統版本
基本上為linux至於使用哪個版本的都可以
其他版本可能指令略為不同或需多修改防火牆設定
這裡示範使用為linux ubuntu 16.0.4 LTS
安裝步驟
下面指令遇到權限不足切換ROOT 的問題請自行提權
提權方法(擇一使用就好):
(1)sudo su
(2)sudo <指令>
- 安裝hostapd
apt-get install hostapd
- 設置 hostapd.conf
vim /etc/hostapd/hostapd.conf
1 | interface=wlp8s0 //網卡接口名稱,用ifconfig獲得 |
- 安裝isc-dhcp-server
apt-get install isc-dhcp-server
- 設置isc-dhcp-server指定網卡為wlp8s0
vim /etc/default/isc-dhcp-server
找到下列這段並修改成
INTERFACES="wlp8s0"
- 設置dhcpd.conf修改DNS跟分配的網段
vim /etc/dhcp/dhcpd.conf
打開後找到
1 | option domain-name "example.org"; # 網域名稱 |
- 安裝iptables(如用其他版本的linux可不裝,如:centOS)
apt-get install iptables
- 配置網卡IP
ifconfig wlp8s0 192.168.100.1 netmask 255.255.255.0 up
- 啟動DHCP server
/etc/init.d/isc-dhcp-server start
>
/etc/init.d/isc-dhcp-server restart
重啟DHCP server
- 開啟轉發功能
sysctl -w net.ipv4.ip_forward=1
1 | iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE |
- 啟動AP
hostapd -B /etc/hostapd/hostapd.conf
到這裡基本上就完成了AP架設,但此方法並未設定wifi密碼
因為此篇主要還要實作認證頁面,所以並未設wifi密碼。
認證網頁
webserver 建置以及權限設置問題方法(略)
前端網頁:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<html>
<head>
<meta charset="UTF-8">
<title>網路認證頁面</title>
</head>
<body>
<form method="POST" action="auth.php">
<p align="center">
<b>Authentication Page</br>
<label class="label_input">使用者名稱</label><input type="text" NAME="username" class="text_field"/>
<br>
<label class="label_input">密碼</label><input type="text" NAME="password" class="text_field"/>
<br>
<input type="submit" NAME="submit" value="登入" />
<br>
</p>
</form>
</body>
</html>
後端網頁:
1 |
|
- 網頁建置完後,再輸入這行指令
iptables -t nat -A PREROUTING -i wlp8s0 -p tcp -s 192.168.100.0/24 -j DNAT --to-destination 92.168.100.1
這樣有認證網頁功能的wifi就建置完成了。
這認證網頁只有一次性的效果