在Ubuntu 16.04 LTS服務器上安裝FreeRADIUS和Daloradius的方法


FreeRADIUS 為AAA Radius Linux下開源解決方案,DaloRadius為圖形化web管理工具。

freeradius一般用來進行賬戶認證管理,記賬管理,常見的電信運營商的寬帶賬戶,上網賬戶管理,記賬,都是使用的radius服務器進行鑒權記賬的。
常見的radius服務器種類不多,比較強大的當屬開源的freeradius,世界上大部分的radius服務器都是基於freeradius開發而來的。
Freeradius包含一個radius服務器和radius-client,可以對支持radius協議的網絡設備進行鑒權記賬,常見的開源路由器操作系統:如Openwrt,DD-wrt等,都支持radius協議,對PPPOE,熱點,VPN等服務器進行賬戶管理認證,記賬。
freeradius功能十分強大,支持眾多的數據庫。
Freeradius操作稍顯麻煩,內置diaup_admin簡單web管理,需要更簡單易用的管理功能可以使用第三方的管理程序對Freeradius進行賬戶管理,系統配置等。

很多剛入門的朋友,在搭建環境的時候都會遇到各種問題,本文詳細介紹在Ubuntu 16.04 LTS服務器上安裝FreeRADIUS和Daloradius的方法,為初學者省去很多麻煩。

一、在安裝之前建議將系統升級到最新版本,運行以下命令:

1 sudo apt‐get update
2 sudo apt‐get upgrade

升級后重新啟動系統:

1 sudo reboot

系統啟動后,在Ubuntu 16.04系統上開始安裝FreeRADIUS和Daloradius。

二、安裝Apache Web Server和PHP

Daloradius將要求在主機系統上安裝php和Apache Web服務器。

1、在Ubuntu上安裝Apache,運行以下命令安裝Apache Web服務器:

1 sudo apt‐get install apache2

2、要在Ubuntu 16.04上安裝PHP,請運行以下命令:

若要安裝PHP 7.3版本請參考在Ubuntu 18.04或CentOS 7系統上安裝PHP7.3:點擊下面的鏈接進入:
https://ywnz.com/linuxjc/3782.html

1 sudo apt‐get install php libapache2‐mod‐php php‐gd php‐common php‐mail \
2 php‐mail‐mime php‐mysql php‐pear php‐db php‐mbstring php‐xml php‐curl

3、檢查PHP版本以確保安裝成功

1 php ‐v

會輸出這樣的類似版本信息

1 PHP 7.0.33‐0ubuntu0.16.04.16 (cli) ( NTS )
2 Copyright (c) 1997‐2017 The PHP Group
3 Zend Engine v3.0.0, Copyright (c) 1998‐2017 Zend Technologies
4 with Zend OPcache v7.0.33‐0ubuntu0.16.04.16, Copyright (c) 1999‐2017, by Zend Technologies

三、安裝MySQL並創建數據庫

1、接下來是安裝mysql服務器或者MariaDB並為daloRADIUS創建一個數據庫。

1 安裝MYSQL命令:
2 sudo apt ‐y install mysql‐server

若安裝過程中提示你要輸入root的密碼,請按要求輸入密碼,然后"確定"即可。我這里暫設是:123456

若沒有提示輸入密碼的話請運行以下命令:

1 sudo mysql_secure_installation
2 如果您還沒有設置密碼,您將被要求設置密碼,然后如果您想刪除匿名用戶,則禁止遠程root
3 登錄,刪除測試數據庫並重新加載表。除非你有其他的計划,並且知道你在做什么,否則我
4 建議你一直按Enter鍵。

2、安裝並運行后,為FreeRADIUS創建一個數據庫,這將在稍后階段使用:

數據庫名稱:radius
數據庫用戶:radius
數據庫用戶密碼:123456

1 $ mysql ‐u root ‐p //進入mysql
2 MariaDB [(none)]> CREATE DATABASE radius; //創建一個數據庫用戶
3 Query OK, 1 row affected (0.000 sec)
4 // 設置數據庫用戶密碼
5 MariaDB [(none)]> GRANT ALL ON radius.* TO radius@localhost IDENTIFIED BY "123456";
6 Query OK, 0 rows affected (0.000 sec)
7 MariaDB [(none)]> FLUSH PRIVILEGES; //刷新MySQL的系統權限相關表
8 Query OK, 0 rows affected (0.001 sec)9 MariaDB [(none)]> EXIT; //退出
10 Bye

四、安裝和配置FreeRADIUS

1、由於Ubuntu 16.04系統,版本2.x是官方存儲庫中提供的軟件包,要安裝3.0版,請為FreeRADIUS版本3添加PPA:

1 sudo add‐apt‐repository ppa:freeradius/stable‐3.0
2 sudo apt‐get update

安裝以下FreeRADIUS軟件包:

1 sudo apt‐get install freeradius freeradius‐mysql freeradius‐utils
2 sudo ufw allow to any port 1812 proto udp
3 sudo ufw allow to any port 1813 proto udp

並在調試模式下運行它

1 sudo freeradius ‐X

輸出應該很長,並以這樣的內容結尾

1 Listening on auth address * port 1812 bound to server default
2 Listening on acct address * port 1813 bound to server default
3 Listening on auth address :: port 1812 bound to server default
4 Listening on acct address :: port 1813 bound to server default
5 Listening on auth address 127.0.0.1 port 18120 bound to server inner‐tunnel
6 Listening on proxy address * port 42463
7 Listening on proxy address :: port 55492
8 Ready to process requests

按Ctrl+C退出調試模式。

2、檢查目錄下是否有schema.sql文件

1 cd /etc/freeradius/mods‐config/sql/main/mysql
2 find schema.sql

3 若提示沒有找到該文件,可能是安裝出錯沒有生成也可能是目錄層次不同,可嘗試下:find ‐name "schema.sql"

若提示在目錄下能找到這個文件則導入freeradius MySQL數據庫方案:

1 sudo mysql ‐u root ‐p radius < /etc/freeradius/mods‐config/sql/main/mysql/schema.sql

3、檢查創建的表:

1 mysql ‐u root ‐p ‐e "use radius;show tables;"

會顯示這樣圖形輸出例子

1 +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+
2 | Tables_in_radius |
3 +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+
4 | nas |
5 | radacct |
6 | radcheck |
7 | radgroupcheck |
8 | radgroupreply |
9 | radpostauth |
10 | radreply |
11 | radusergroup |
12 +‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+

4、創建一個從SQL模塊到/etc/freeradius/3.0/mods啟用目錄的符號鏈接:

1 sudo ln ‐s /etc/freeradius/mods‐available/sql /etc/freeradius/mods‐enabled/

5、配置SQL模塊並更改數據庫連接參數以適合你的環境:

1 sudo vim /etc/freeradius/mods‐enabled/sql

你的sql部分應該類似於下面的部分:
如果你有專用數據庫服務器,請將localhost替換為源FreeRadius服務器的IP:

1 sql {
2 driver = "rlm_sql_mysql"
3 dialect = "mysql"
4 # Connection info:
5 server = "localhost"
6 port = 33067 login = "radius"
8 password = "123456"
9 # Database table configuration for everything except Oracle
10 radius_db = "radius"
11 }
12 # Set to ‘yes’ to read radius clients from the database (‘nas’ table)
13 # Clients will ONLY be read on server startup.
14 read_clients = yes
15
16 # Table to keep radius client info
17 client_table = "nas"

6、然后更改/etc/freeradius/mods-enabled/sql的組權限:

1 sudo chgrp ‐h freerad /etc/freeradius/mods‐available/sql
2 sudo chown ‐R freerad:freerad /etc/freeradius/mods‐enabled/sql

重啟freeradius服務:

1 sudo systemctl restart freeradius.service

最后,我們將在調試模式下運行FreeRADIUS以確保一切正常工作。

7、首先停止當前運行的服務

1 sudo systemctl stop freeradius.service

在調試模式下運行FreeRADIUS

1 sudo freeradius ‐X

輸出的末尾應該是這樣的

1 Listening on auth address * port 1812 bound to server default
2 Listening on acct address * port 1813 bound to server default
3 Listening on auth address :: port 1812 bound to server default
4 Listening on acct address :: port 1813 bound to server default
5 Listening on auth address 127.0.0.1 port 18120 bound to server inner‐tunnel
6 Listening on proxy address * port 55873
7 Listening on proxy address :: port 46059
8 Ready to process requests

按Ctrl+C退出調試模式。

8、重新啟動FreeRADIUS服務。

1 sudo systemctl start freeradius.service

五、在Ubuntu 16.04上安裝和配置Daloradius

1、如果沒有安裝wget和unzip,則安裝wget和unzip

1 sudo apt ‐y install wget unzip

下載並解壓daloRADIUS和cd到目標文件夾中,這個文件夾是daloRADIUS-master

1 wget https://github.com/lirantal/daloradius/archive/master.zip
2 unzip daloradius‐master.zip
3 mv daloradius‐master/ daloradius
4 cd daloradius
5 若無法下載,可用瀏覽器打開https://github.com/lirantal/daloradius/archive/master.zip下載

2、我們將用daloRADIUS模式填充FreeRADIUS使用的數據庫。它是我們在前面的案例中創建的數據庫radius。

1 sudo mysql ‐u root ‐p radius < contrib/db/fr2‐mysql‐daloradius‐and‐freeradius.sql
2 sudo mysql ‐u root ‐p radius < contrib/db/mysql‐daloradius.sql

從“daloradius”目錄中退出,並將該文件夾移動到文檔根目錄中,並將其重命名為“daloradius”

1 cd ..
2 sudo mv daloradius /var/www/html/

3、將daloradius文件夾的所有者和組更改為www-data:www-data,這是運行Apache Web Server的所有者和組。

1 sudo chown ‐R www‐data:www‐data /var/www/html/daloradius/

4、接下來,我們需要創建daloRADIUS配置文件。daloRADIUS提供了一個配置文件模板,名

為/var/www/html/daloradius/library/daloradius.conf.php。我們只復制樣本。

1 sudo cp /var/www/html/daloradius/library/daloradius.conf.php.sample

/var/www/html/daloradius/library/daloradius.conf.php將配置文件的權限更改為664

1 sudo chmod 664 /var/www/html/daloradius/library/daloradius.conf.php

5、接下來,我們將編輯daloRADIUS配置文件中的一些值,以便它連接到我們之前為FreeRADIUS創建的數據庫。

1 sudo vim /var/www/html/daloradius/library/daloradius.conf.php

我們將更改以下值

1 $configValues['CONFIG_DB_USER'] = 'root';
2 $configValues['CONFIG_DB_PASS'] = '';
3 $configValues['CONFIG_DB_NAME'] = 'radius';

下面是我如何根據前面創建的數據庫名、用戶和密碼修改它們的。

1 $configValues['CONFIG_DB_USER'] = 'radius';
2 $configValues['CONFIG_DB_PASS'] = '123456';
3 $configValues['CONFIG_DB_NAME'] = 'radius'

6、最后重啟daloRADIUS和Apache

1 sudo systemctl restart freeradius.service apache2

六、訪問daloRADIUS

1、要訪問daloRADIUS,請在瀏覽器中訪問本機的IP或域名,然后是/daloRADIUS,例如https://your_server_ip/daloradius
除非您配置了SSL,否則請確保它是http://,並且瀏覽器不會將其更改為https://,,因為有時可能會發生這種情況。
這就是daloRADIUS的樣子

默認的登錄憑據是:
username: administrator
password: radius

七、測試 FreeRADIUS和daloRADIUS

1、NAS (Network Access Server)客戶端表充當了到受保護資源的網關。為了讓另一個設備連接到我們的FreeRADIUS服務器,需

要將它添加到NAS客戶端表中。
我們通過登錄到daloRADIUS儀表板來添加NAS客戶端表。然后導航到Management > NAS(在藍色的子菜單中)> New
NAS(在左邊,深灰色的邊欄)。
我們需要填寫的最小選項如下所示

1 NAS IP/Host:你將連接的計算機的IP。
2 NAS Secret:密鑰。
3 NAS Type:你可以在這里任意填寫
4 NAS Shortname:方便您使用的短名稱

我將填寫以下內容

2、創建daloRADIUS用戶

為了測試我們的服務器,我們還需要一個用戶。
通過在頂部菜單導航到Management > Users(在藍色子菜單中)> New User(在左邊,深灰色的邊欄)。
對於我們的示例,我將使用以下憑證創建用戶

在創建用戶時,除了Username,Password外,還有其他字段可用,但對於我們的目的,這些就足夠了。

3、在調試模式下運行FreeRADIUS

接下來,我們將在調試模式下運行FreeRADIUS,這樣我們就可以看到當我們向它發送認證請求時會發生什么。
首先停止正在運行的進程。

1 sudo systemctl stop freeradius.service

在調試模式下運行FreeRADIUS

1 sudo freeradius ‐X

注意:每次添加新的NAS表時,都需要重新啟動FreeRADIUS服務器,以便它獲取更新后的表。

4、使用NTRadPing測試FreeRADIUS服務器

測試服務器的一個方便方法是使用一種叫做NTRadPing的免費Windows軟件。
你可以在這里下載https://community.microfocus.com/t5/OES-Tips-Information/NTRadPing-1-5-RADIUS-TestUtility/ta-p/1777768
這是到檔案的直接鏈接
https://community.microfocus.com/dcvta86296/attachments/dcvta86296/OES_Tips/148/1/ntradping.zip
這是VirusTotal的報告,所以你知道它是安全的
https://www.virustotal.com/gui/file/e1b3318b884e4643a043ec5e3104638016c343c447424c244fc1da4f6e7165ec/detection
只需解壓歸檔文件並運行可執行文件以運行NTRadPing即可。

5、我們將使用NTRadPing向在調試模式下運行FreeRADIUS的服務器發送身份驗證請求。

我們將按如下方式填寫

1 RADIUS Server/port:FreeRADIUS服務器的IP /端口1812
2 Reply timeout (sec.):1
3 Retries: 1
4 RADIUS Secret Key:testing1235 User‐Name:test_1
6 Password:A123456
7 選中CHAP復選框,這樣請求使用CHAP密碼,而不是PAP密碼。
8 現在單擊Send按鈕發送身份驗證請求。
9 如果您接收到Access‐Accept響應,那么我們可以假定它可以工作。

NTRadPing的輸出應該像這樣

在調試模式下運行FreeRADIUS的終端中,輸出應該以這樣的內容結束

希望您也已經成功地在ubuntu16.0.4上安裝了FreeRADIUS,並安裝和配置了daloRADIUS,然后成功地測試了FreeRADIUS服
務器。

八、常見錯誤

Failed binding with auth address [ ] when running in debug mode

1 Failed binding to auth address * port 1812 bound to server default: Address already in use
2 /etc/freeradius/3.0/sites‐enabled/default[59]: Error binding to port for 0.0.0.0 port 1812

這個錯誤發生在你試圖運行FreeRADIUS,但有另一個FreeRADIUS實例已經在運行,所以你需要運行下面的命令來停止它

1 sudo systemctl stop freeradius.service

快抓緊來操作吧!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM