CentOS 7 版本下載點
在 CentOS 的安裝上,我是選擇陽春版的方式處理,這樣子等一下會安裝的套件比較多,但是也可以了解是那些套件要安裝,以後查修比較簡單。
安裝前先升級 yum 套件
[root@openvpn]# yum -y update
步驟一:安裝 OPENVPN軟體
================================
[root@openvpn]# yum install -y epel-release
[root@openvpn]# yum install -y openvpn
================================
CentOS 6.10裝法
[root@openvpn]# cd /etc/openvpn
[root@openvpn]# tar -zxf clt_number_shortname.tar
[root@openvpn]# service openvpn restart
[root@openvpn]# chkconfig openvpn on
CentOS 7.0裝法
[root@openvpn]# cd /etc/openvpn
[root@openvpn]# tar -zxf clt_number_shortname.tar
[root@openvpn]# cp client.conf server.conf
[root@openvpn]# systemctl restart openvpn@server
[root@openvpn]# systemctl enable openvpn@server
看 tun0 VPN通道是否有啟動,如 tun0 有產生10.1.X.X代表VPN連線成功
步驟三:安裝 freeradius 軟體套件
================================
[root@freeradius]# yum install -y freeradius freeradius-utils
[root@freeradius]# cd /etc/raddb
[root@freeradius]# vi clients.conf
================================
client 10.1.77.7 {
client 10.1.77.7 {
secret = spiradawn
shortname = roamingcenter
}
shortname = roamingcenter
}
client 192.168.10.199 {
secret = radius-key
shortname = controller
}
client 10.1.77.11 {
secret = spiradawn
shortname = roamingcenter-monitor
shortname = roamingcenter-monitor
}
===================================
修改/etc/raddb的proxy.conf檔案
[root@freeradius]# vi proxy.conf
===================================
<-->-->
realm NULL {
authhost = LOCAL
accthost = LOCAL
secret = niucltcc
}
//設定學校的網域名稱
realm ntusd.ttc.edu.tw {
authhost = LOCAL //設定Radius Server認證(auth)位址
accthost = LOCAL //設定Radius Server計費(accounting)位址
}
realm DEFAULT {
authhost = 10.1.77.7:1812
accthost = 10.1.77.7:1813
secret = spiradawn //漫遊中心給的Radius Key (金鑰)
nostrip
}
authhost = 10.1.77.7:1812
accthost = 10.1.77.7:1813
secret = spiradawn //漫遊中心給的Radius Key (金鑰)
nostrip
}
==============================
啟動 Freeradius 服務
CentOS 6.10的方式
CentOS 6.10的方式
[root@freeradius ]#service radiusd restart
[root@freeradius ]#chkconfig radiusd on -->開機啟動
CentOS 7的方式
[root@freeradius ]# systemctl restart radiusd
[root@freeradius ]# systemctl enable radiusd -->開機啟動
[root@freeradius]# radtest testuser@niu testpass 127.0.0.1 0 testing123
radtest 帳號 密碼 測試伺服器 通訊埠 Secret
Sending Access-Request of id 234 to 10.1.0.7 port 1812
User-Name = "testuser@niu"
User-Password = "testpass"
NAS-IP-Address = 127.0.0.1
NAS-Port = 0
rad_recv: Access-Accept packet from host 10.1.0.7 port 1812, id=234, length=20
以上測試freeradius驗證是否正常
步驟四:修改 selinux 關閉
# vim /etc/sysconfig/selinuxSELINUX=disabled #關閉selinux功能
關閉防火牆功能 --> CentOS 6 指令
# /etc/init.d/iptables save 存檔
# /etc/init.d/iptables stop 停止
開機時停用防火牆
# chkconfig iptables off
關閉 Firewalld 防火牆指令: --> CentOS 7 指令
# systemctl stop firewalld.service
設定下次開機不會啟動 Firewalld 防火牆
# systemctl disable firewalld.service
# systemctl disable firewalld.service
================================
步驟五:安裝perl相關模組
# yum install freeradius-perl perl perl-IO-Socket-SSL
perl-Mail-IMAPClient -y
修改/etc/raddb/mods-available/perl檔案
[root@radius]# vim /etc/raddb/modules/perl -->CentOS 6 指令
perl {
…略…
#module = ${confdir}/example.pl
module = ${confdir}/imap.pl
…略…
|
}
[root@radius]# vim /etc/raddb/mods-available/perl -->CentOS 7 指令
perl {
…略…
#filename = ${modconfdir}/${.:instance}/example.pl
filename =
${modconfdir}/${.:instance}/imap.pl
…略…
|
新增/etc/raddb/mods-config/perl/imap.pl並新增下列內容
[root@radius]# vim /etc/raddb/imap.pl -->CentOS 6 指令
[root@radius]# vim /etc/raddb/mods-config/perl/imap.pl -->CentOS 7 指令
use Mail::IMAPClient;
use
Data::Dumper;
use
constant RLM_MODULE_REJECT=> 0;#
/* immediately reject the request */
use
constant RLM_MODULE_FAIL=> 1;#
/* module failed, don't reply */
use
constant RLM_MODULE_OK=> 2;#
/* the module is OK, continue */
use
constant
RLM_MODULE_HANDLED=>
3;# /* the module handled the
request, so stop. */
use
constant
RLM_MODULE_INVALID=>
4;# /* the module considers the
request invalid. */
use
constant
RLM_MODULE_USERLOCK=>
5;# /* reject the request (user
is locked out) */
use
constant
RLM_MODULE_NOTFOUND=>
6;# /* user not found */
use
constant RLM_MODULE_NOOP=> 7;#
/* module succeeded without doing anything */
use
constant
RLM_MODULE_UPDATED=>
8;# /* OK (pairs modified) */
use
constant
RLM_MODULE_NUMCODES=>
9;# /* How many return codes
there are *
sub
authorize {
return RLM_MODULE_OK;
}
sub
authenticate {
my $imap = Mail::IMAPClient->new(
User => $RAD_REQUEST{'User-Name'},
Password =>
$RAD_REQUEST{'User-Password'},
Server
=> "imap.gmail.com",
Port => 993,
Ssl => 1,
) or return RLM_MODULE_REJECT;
if($imap->connect){
return RLM_MODULE_OK;
$imap->logout;
}
}
|
修改/etc/raddb/proxy.conf 新增realm
[root@radius]# vim
/etc/raddb/proxy.conf
realm XXX.edu.tw
{
type = radius
authhost = LOCAL
accthost = LOCAL
}
|
[root@radius]# vim /etc/raddb/sites- enabled/default
authorize {
…略…
if (!control:Auth-Type
&& User-Password) {
update control {
Auth-Type := Perl #如果沒有認證屬性和密碼屬性使用Perl模組認證
}
}
…略…
}
authenticate {
…略…
Auth-Type Perl { #新增Auth-Perl認證
perl
}
…略…
}
|
[root@freeradius ]#service radiusd restart --> CentOS 6 指令
[root@freeradius ]#systemctl restart radiusd --> CentOS 7 指令
一、 EAP-GTC驗證
1.
修改/etc/raddb/mods-enabled/eap
[root@freeradius
]#vim /etc/raddb/mods-enabled/eap
…略…
gtc{
…略…
auth_type = perl
…略…
}
peap {
…略…
default_eap_type
= gtc
…略…
}
|
修改/etc/raddb/sites-enabled/inner-tunnel
[root@freeradius ]#vim /etc/raddb/sites-enabled/inner-tunnel
authenticate
{
…略…
Auth-Type Perl {
perl
}
…略…
}
|
步驟九:修改 freeradius 修改ntlm_auth模組(802.1X)
=====================================
[root@tanetroaming]# vim /etc/raddb/modules/ntlm_auth
exec ntlm_auth {
wait = yes
#program = "/path/to/ntlm_auth --request-nt-key --domain=MYDOMAIN --username=%{mschap:User-Name} --password=%{User-Password}" #將這一行註銷起來
program = "/usr/bin/ntlm_auth --request-nt-key --domain=aaa.bbb.edu.tw --username=%{%{Stripped-User-Name}:-%{%{User-Name}:-None}} --password=%{User-Password}"
#修改執行路徑和NULL認證方式
}
[root@tanetroaming]# vi /etc/raddb/sites-available/default
=====================================
authorize {
。。。略。。。
# Read the 'users' file
files
if (!control:Auth-Type && User-Password) { #新增ntlm_auth驗證
update control {
Auth-Type := ntlm_auth
}
}
#
# Look in an SQL database. The schema of the database
# is meant to mirror the "users" file.
#
# See "Authorization Queries" in sql.conf
# sql
。。。略。。。
}
。。。略。。。
Auth-Type MS-CHAP {
mschap
}
Auth-Type ntlm_auth { #新增ntlm_auth驗證
ntlm_auth
}
==========================================
[root@freeradius ]# service radiusd restart #重啟 freeradius服務
參考資料如下