# 計網實驗 Lab 2 本頁連結:https://hackmd.io/@kinoRAS/cnl2 常用連結:[投影片](https://www.pcs.csie.ntu.edu.tw/views/courses/cnl/2024/2024_Lab2_WLAN(exeriment).pdf), [PHP](https://www.pcs.csie.ntu.edu.tw/views/courses/cnl/2024/hotspotlogin.php.txt) ## 設定步驟 ### A. 安裝 LAMP Server 及 phpMyAdmin 1. 安裝套件 - `sudo apt-get install tasksel` - `sudo tasksel install lamp-server` - `sudo apt-get install phpmyadmin` - 建議所有密碼皆設為 123456 2. 複製及修改 phpMyAdmin 設定檔 - `sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d` - `sudo gedit /etc/apache2/apache2.conf` - 在最後一行加入 `Include /etc/phpmyadmin/apache.conf` 3. 重啟 Apache Server - `sudo /etc/init.d/apache2 restart` 4. 測試 phpMyAdmin - http://localhost/phpmyadmin 5. 啟用 Apache 的 SSL 功能 - `sudo a2enmod ssl` - `sudo a2ensite default-ssl` - `sudo /etc/init.d/apache2 restart` ### B. 安裝 FreeRADIUS 1. 安裝套件 - `sudo apt-get install freeradius` - `sudo apt-get install freeradius-mysql` 2. 重啟 FreeRADIUS - `sudo /etc/init.d/freeradius restart` 3. 修正 localhost hotsname 混淆問題 - `sudo gedit /etc/hosts` - 註解 `::1 localhost ip6-localhost ip6-loopback` 一行 ### C. 建立 FreeRADIUS 資料庫 1. 新增 RADIUS 資料庫 - `mysql –u root –p` - `CREATE DATABASE radius;` 2. 匯入 RADIUS 資料庫架構 - `sudo su root` - `cd /etc/freeradius/sql/mysql/` - `mysql -u root -p radius < ippool.sql` - `mysql -u root -p radius < schema.sql` - `mysql -u root -p radius < nas.sql` - `mysql -u root -p radius < admin.sql` 3. 設定使用者 radius 之權限 - 登入 phpMyAdmin 並選取資料庫 radius - 在導覽列選擇 More > Privileges - 編輯使用者 radius 的權限,選擇 Check All 並儲存 - 另外,要手動重設使用者 radius 的密碼 4. 設定使用者 radius 之密碼 ### D. 修改 FreeRADIUS 設定 1. `gedit /etc/freeradius/sites-enabled/default` - 取消以下各句之下一行之註解 - `# See "Authorization Queries" in sql.conf` - `# See "Accounting queries" in sql.conf` - `# See "Simultaneous Use Checking Queries" in sql.conf` - `# See "Authentication Logging Queries" in sql.conf` 2. `gedit /etc/freeradius/radiusd.conf` - `# Port on which to listen.` 後的 `port` 改為 `1812` - `This second "listen" section` 後的 `port` 改為 `1813` 3. `gedit /etc/freeradius/radiusd.conf` - 取消 `$INCLUDE sql.conf` 之註解 - `stripped names = no` 改為 `stripped names = yes` - `auth = no` 改為 `auth = yes` - `auth_badpass = no` 改為 `auth_badpass = yes` 4. `gedit /etc/freeradius/sql.conf` - `# Connection info:` 後 - `login = "radius"` - `password = "123456"` - 取消 `readclients = yes` 之註解 5. `gedit /etc/freeradius/clients.conf` - 新增 ``` client 192.168.1.0/24{ secret = [key here ...] } ``` ### E. phpMyadmin 內設定 1. 新增使用者 "radius" - 進入首頁,在導覽列選擇 User Accounts > Add user account - 按照以下設定新增使用者 - User name = radius - Host name = Any host 及 % - 勾選 Create database with same name and grant all privileges - 勾選 Global privileges 的 Check all 2. 加入資料 - 選取資料庫 radius,在導覽列選擇 SQL - 加入群組資料 - `INSERT INTO radgroupreply (groupname,attribute,op,value) VALUES ('user','Auth-Type',':=','CHAP');` - `INSERT INTO radgroupreply (groupname,attribute,op,value) VALUES ('user','Service-Type',':=','Framed-User');` - 加入測試帳號 "ta" - `INSERT INTO radcheck (username,attribute,op,value) VALUES ('ta', 'Cleartext-Password',':=','tatest'); - 把帳號加入群組 - `INSERT INTO radusergroup (username,groupname) VALUES ('ta','user');` 3. 加入更多資料 - `INSERT INTO radcheck (username,attribute,op,value) VALUES ('帳號','User-Password',':=','密碼');` - `INSERT INTO radusergroup (username,groupname) VALUES ('帳號','user');` 4. 測試 FreeRADIUS - `radtest ta tatest localhost 1 testing123` - 若成功會顯示 request accept ### F. FreeRADIUS 1. 開啟/停止/重啟 - `sudo /etc/init.d/freeradius start` - `sudo /etc/init.d/freeradius stop` - `sudo /etc/init.d/freeradius restart` 2. Debug 模式 - `sudo /etc/init.d/freeradius stop` - `sudo freeradius -X` 3. Log 檢視 - `sudo tail -n 30 /var/log/freeradius/radius.log` - `sudo tail -n 30 /var/log/freeradius/radius.log | grep Error` ### G. AP 設定 依投影片指示進行。