阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS下Radius服务器搭建

156次阅读
没有评论

共计 5234 个字符,预计需要花费 14 分钟才能阅读完成。

一、实现环境:

1. 系统:CentOS  release  6.6 (Final)

2. 需要软件包:

1) freeradius-2.1.12-6.e16.x86_64

  freeradius-MySQL-2.1.12-6.e16.x86_64

2) ppp-2.4.5-5.e16.x86_64

3) rp-pppoe-3.10-11.e16.x86_64

4) mysql-5.1.73-3.e16_5.x86_64

  mysql-devel-5.1.73-3.e16_5.x86_64

5) openssl-1.0.1e-30.e16_6.5.x86_64

二、服务器实际部署环境和简单原理分析:

Radius 是 Remote Access Dial In User Service 的简称。Radius 主要用来提供认证(Authentication)机制,用来辨认使用者的身份与密码,确认通过之后,经由授权(Authorization)使用者登入网域使用相关资源并可提供计费(Accounting)机制,保存使用者的网络记录。Freeradius 是一款 OpenSource 软件,基于 radius 协议,实现 RADIUS AAA(Authentication、Authorization、Accounting)功能。

如下拓扑图所示,为该 radius 服务器实际运行环境和功能。

CentOS 下 Radius 服务器搭建

Radius 服务器和接入服务器配合使用实现用户宽带账号计费拨号获取权限连接 Internet 网络。

三、Radius 服务器搭建:

      1. 安装 CentOS 系统配置好网络之后使用命令:#yum update 更新系统。

      2. 查看各个软件包是否安装:#rpm –q ppp rp-pppoe freeradius mysql-* openssl

如果没有安装则使用命令:#yum install ppp rp-pppoe freeradius-* mysql-* openssl

进行安装,一般 openssl 在系统更新之后就已经安装好了。安装好各个软件之后,使用命令:

#wget ftp://ftp.samba.org/pub/ppp/ppp-2.4.5.tar.gz 下载 ppp 源代码包到创建的 /etc/ppp/radius 目录下。(#mkdir /etc/ppp/radius // 创建目录)

下面就对各服务进行配置:

1. 配置 /etc/ppp/options 文件:

lock

crtscts

nobsdcomp

nodeflate

nopcomp

      2. 配置 /etc/ppp/pppoe-server-options 文件,内容为:

# PPP options for the PPPoE server

# LIC: GPL

auth

require-chap

default-mru

default-asyncmap

lcp-echo-interval 60

lcp-echo-failure 5

ms-dns 202.96.128.86

noipdefault

noipx

nodefaultroute

proxyarp

noktune

logfile /var/log/pppd.log

3. 让 pppoe 服务使用 freeradius 服务器进行验证

1) 首先更改 /etc/ppp/pppoe-server-options,添加两行设置:

#PPP options for the PPPoE server

#LIC: GPL

auth

require-chap

default-mru

default-asyncmap

lcp-echo-interval 60

lcp-echo-failure 5

ms-dns 202.96.128.86

noipdefault

noipx

nodefaultroute

proxyarp

noktune

->plugin    /usr/lib/pppd/2.4.5/radius.so

->radius-config-file /etc/ppp/radiuds/radiusclient.conf

logfile /var/log/pppd.log

表示让 pppoe-server 在运行时加入 pppd 的 radius 查检,可以让 pppoe 服务通过 freeradius 来验证和记账。添加此行之后,可以创建 /etc/ppp/radiuds/ 目录,创建完之后,需要使用一下 ppp 的源代码。解压 ppp 的源代码目录:
#tar -xzf ppp-2.4.5.tar.gz

#cd ppp-2.4.5

#cd pppd/plugins/radius/etc/

#cp  *  /etc/ppp/radiuds/

2) 这个目录下有需要的所有相关的配置文件,其中最重要的是 /etc/ppp/radiuds/radiusclient.conf,先打开此文件配置,其内容为(已去掉注释):

auth_order  radius

login_tries 4

login_timeout 60

nologin  /etc/nologin

issue  /etc/ppp/radiuds/issue

authserver  localhost:1812

acctserver  localhost:1813

servers  /etc/ppp/radiuds/servers

dictionary  /etc/ppp/radiuds/dictionary

login_radius  /usr/local/sbin/login.radius

seqfile  /var/run/radius.seq

mapfile  /etc/ppp/radiuds/port-id-map

default_realm

radius_timeout  10

radius_retries  3

login_local  /bin/login

3) 另外,还需更改此目录下的 servers 文件,此文件用来指定读取的 radius 服务器的主机名称以及 key 值(需要在 freeradius 配置中指定)。

编辑 /etc/ppp/radius/servers , 设定 radius 服务器的位置

localhost  testing123 // 这里的 testing123 是密码

4) 编辑 /etc/ppp/radius/dictionary,修改一些路径设置,主要是最后一个 dictionary.microsoft 的路径设置。

INCLUDE /etc/ppp/radiuds/dictionary.microsoft

5) 此时 pppoe 服务已经可以通过 radius 认证了。然后进行 freeradius 的配置。

其中 freeradius-mysql 包使用来让 freeradius 连接 mysql 数据库的,本部分还用不到。

首先打开 /etc/raddb/clients.conf 配置客户端访问控制,文件内容如下:

Client localhost {

Secret = testing123

Shortname = localhost

Nastype = other

}

表示客户端之允许从 127.0.0.1 的 ip 登录 radius 服务,并且需要验证的 secret 为 testing123,就是在上面的 servers 文件中需要配置的信息。若要实现可以从别的机器访问,请参考注释获得帮助。

6) 然后配置 /etc/raddb/naslist 文件,内容为:

# NAS Name  Short Name Type

#portmaster1.isp.com  pm1.NY 

livingston

#portmaster2.isp.com  pm1.LA 

livingston

localhost  local  portslave

此文件用来配置记录有哪些指定的 nas 服务器需要使用 radius 进行记账。现在指定的是 localhost。

7) 主控配置文件是 radiusd.conf,此文件主要是用来指定 freeradius 服务器默认的验证和记账方式。我们目前使用本地的文件方式,就是 /etc/raddb/users 文件,在其中添加需要提供给 pppoe 服务认证的用户信息,内容如下(用户名前面一定不能有空格):

Aaa Auth-Type := Local, Simultaneous-Use := 1,User-Password:= “aaa”

[tab]Service-Type = Framed-User,

[tab]Framed-Protocol = PPP,

[tab]Framed-IP-Netmask = 255.255.255.255

其中 Simultaneous-Use := 1 字段用来设置每个用户同时登录的个数。

8) 为了让 radius 能正确地调用 mysql,还要指定一下库的位置:

echo /usr/lib >> /etc/ld.so.conf

ldconfig

9) 都配置完毕后,可以通过 radiusd - X 命令以排错方式启动,此时再启动 pppoe-server, 用客户端拨号验证一下,检查 pppoe 服务是否成 功通过 freeradius 来验证用户。如果成功,这一部分完成。可通过 service radius restart 来正常启动 radius 服务。

Radiusd  -X

radtest  aaa  aaa  localhost  0  testing123

看到 Access-Accept 之类的字样就表示成功了。这时可以正式启动 radiusd。

5. 配置 freeradius 从 mysql 数据库读取用户信息

      1.#mysql –u root –p 123  // 登录 mysql

      2.>create database radius;  // 创建数据库

      3.>exit  // 退出数据库

      4.#cd /etc/raddb/sql/mysql

      5.#mysql –u root –p radius < schema.sql  // 把表导入到数据库中,到数据库中查看是否导入 7 张表

      6. 修改 /etc/raddb/sites-enabled/default 文件,把 authorize{}、accounting{} 中的 sql 的注释 #去掉,并把 authorize{} 中的 files 的注释# 加上。如下所示:

Authorize{

Chap

Mschap

Suffix

Eap

#files

Sql

Pap

}

Accounting{

Detail

Unix

Redutmp

sql

}

      7. 修改 mysql 数据库连接的配置文件 /etc/raddb/sql.conf

      Server =“localhost”

      Login =“root”

      Password =“123”

      Radius_db  =“radius”// 数据库名称

      8. 修改 /etc/raddb/radius.conf 文件:

      将 $INCLUDE  sql.conf 的注释 #去掉即可。

      9. 在数据库中加入测试账号:

      #mysql –u root –p 123

      >use radius;

建立组信息:

      >insert into radgroupreply (groupname,attribute,op,value) values (’user’,’Auth-Type’,’:=’,’Local’);

      > insert into radgroupreply (groupname,attribute,op,value) values (’user’,’Service-Type’,’:=’,’Framed-User’);

      > insert into radgroupreply (groupname,attribute,op,value) values (’user’,’Feamed-IP-Address’,’:=’,’255.255.255.255’);

      > insert into radgroupreply (groupname,attribute,op,value) values (’user’,’Framed-IP-Netmask’,’:=’,’255.255.255.0’);

建立用户信息:

      > insert into radcheck (username,attribute,op,value) values (’test’,’User-Password’,’:=’,’110’);

将用户加入组中:

      > insert into radusergroup (username,groupname) values (’test’,’user’);

      >exit;  // 退出数据库

四、测试 radius:

1.#radius –X // 以检错方式启动 radius 服务

2. 开另一个终端使用命令:

#radtest  test  110  localhost  10  testing123  进行测试。

如果显示 Access-Accept 则表示安装成功。

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-06/119102.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计5234字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中