老谢博客

  • 首页
  • WordPress
  • 网络技术
  • 乱七八糟
  • 运维技术
  • 给我留言
  • 关于老谢

CentOS安装配置OpenVPN并结合freeradius验证

分类:运维技术日期:2012-12-02 - 10:32:04作者:老谢

配置OpenVPN服务器端

wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh epel-release-5-4.noarch.rpm
yum install openvpn
cp -R /usr/share/openvpn/easy-rsa /etc/openvpn/
cd /etc/openvpn/easy-rsa/2.0
vim vars

wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm rpm -Uvh epel-release-5-4.noarch.rpm yum install openvpn cp -R /usr/share/openvpn/easy-rsa /etc/openvpn/ cd /etc/openvpn/easy-rsa/2.0 vim vars

根据自己实际情况修改下面的信息:

export KEY_COUNTRY=”CN”
export KEY_PROVINCE=”TJ”
export KEY_CITY=”TJ”
export KEY_ORG=”liukangxu.info”
export KEY_EMAIL=”admin@liukangxu.info”

export KEY_COUNTRY=”CN” export KEY_PROVINCE=”TJ” export KEY_CITY=”TJ” export KEY_ORG=”liukangxu.info” export KEY_EMAIL=”admin@liukangxu.info”

source ./vars
./clean-all #全部回车
./build-ca server #前面全回车,最后两步y
./build-key-server server #前面全回车,最后两步y
 ./build-key vpn1 #vpn1是客户端名称
./build-dh #生成Diffie Hellman参数

source ./vars ./clean-all #全部回车 ./build-ca server #前面全回车,最后两步y ./build-key-server server #前面全回车,最后两步y ./build-key vpn1 #vpn1是客户端名称 ./build-dh #生成Diffie Hellman参数

编辑/etc/openvpn/server.conf放入下面的内容:

port 443
proto tcp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 192.168.20.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
comp-lzo
persist-key
persist-tun

port 443 proto tcp dev tun ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt cert /etc/openvpn/easy-rsa/2.0/keys/server.crt key /etc/openvpn/easy-rsa/2.0/keys/server.key dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem server 192.168.20.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "redirect-gateway" push "dhcp-option DNS 8.8.8.8" keepalive 10 120 comp-lzo persist-key persist-tun

启用ip包转发

sed -i "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" /etc/sysctl.conf
sysctl -p

sed -i "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" /etc/sysctl.conf sysctl -p

然后配置iptables规则,很重要,不然会导致连接后无法访问外网

iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -j SNAT –to-source 你的服务器IP地址
/etc/init.d/iptables save
/etc/init.d/iptables restart

iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -j SNAT –to-source 你的服务器IP地址 /etc/init.d/iptables save /etc/init.d/iptables restart

最后启动openvpn以及加入开机启动

service openvpn start
chkconfig openvpn on

service openvpn start chkconfig openvpn on

配置OpenVPN客户端

下载OpenVPN的windows客户端:http://swupdate.openvpn.org/community/releases/openvpn-2.2.1-install.exe

下载安装完成以后,把OpenVPN服务器/etc/openvpn/easy-rsa/2.0/keys目录下的vpn1.crt、vpn1.csr、vpn1.key、ca.crt、ca.key五个文件复制到OpenVPN客户端安装目录下的config目录下

然后再config目录下新建vpn1.ovpn文件,编辑内容如下:

client
dev tun
proto tcp
remote OpenVPN服务器ip 443
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert vpn1.crt
key vpn1.key
ns-cert-type server
comp-lzo
verb 3

client dev tun proto tcp remote OpenVPN服务器ip 443 resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert vpn1.crt key vpn1.key ns-cert-type server comp-lzo verb 3

至此全部操作完成,打开OpenVPN客户端连接试试看吧!

以上内容主要参考以下文章:

OpenVZ VPS 下 CentOS 安装 OpenVPN 详细教程
CentOS 安装和配置OpenVPN

感谢以上所有文章的原作者!

结合freeradius验证

上面全部操作没有问题以后,请再继续下面的步骤:

上面是使用个人证书验证,由于要结合freeradius,所以要修改使用用户名、密码验证,请保证/etc/openvpn/server.conf配置文件如下:

port 443
proto tcp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 192.168.20.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
comp-lzo
persist-key
persist-tun
status 1194.log
verb 3
 
client-cert-not-required
username-as-common-name

port 443 proto tcp dev tun ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt cert /etc/openvpn/easy-rsa/2.0/keys/server.crt key /etc/openvpn/easy-rsa/2.0/keys/server.key dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem server 192.168.20.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "redirect-gateway" push "dhcp-option DNS 8.8.8.8" keepalive 10 120 comp-lzo persist-key persist-tun status 1194.log verb 3 client-cert-not-required username-as-common-name

安装必要的包

yum install libgcrypt libgcrypt-devel gcc-c++

yum install libgcrypt libgcrypt-devel gcc-c++

安装radius的插件

wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz
tar xvfz radiusplugin_v2.1a_beta1.tar.gz
cd radiusplugin_v2.1a_beta1/
make
cp radiusplugin.so /etc/openvpn/
cp radiusplugin.cnf /etc/openvpn/

wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz tar xvfz radiusplugin_v2.1a_beta1.tar.gz cd radiusplugin_v2.1a_beta1/ make cp radiusplugin.so /etc/openvpn/ cp radiusplugin.cnf /etc/openvpn/

编辑/etc/openvpn/radiusplugin.cnf,保证server部分信息如下,其他部分不动:

erver
{
        # The UDP port for radius accounting.
        acctport=1813
        # The UDP port for radius authentication.
        authport=1812
        # The name or ip address of the radius server.
        name=YOUR RADIUS SERVER IP
        # How many times should the plugin send the if there is no response?
        retry=1
        # How long should the plugin wait for a response?
        wait=1
        # The shared secret.
        sharedsecret=YOUR RADIUS SERVER SECRET
}

erver { # The UDP port for radius accounting. acctport=1813 # The UDP port for radius authentication. authport=1812 # The name or ip address of the radius server. name=YOUR RADIUS SERVER IP # How many times should the plugin send the if there is no response? retry=1 # How long should the plugin wait for a response? wait=1 # The shared secret. sharedsecret=YOUR RADIUS SERVER SECRET }

编辑/etc/openvpn/server.conf在最下面加入:

plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf
service openvpn restart

plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf service openvpn restart

至此,openvpn服务器端配置完成,下面是客户端,配置文件如下即可:

client
dev tun
proto tcp
remote OpenVPN-Server-IP PORT
resolv-retry infinite
nobind
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
persist-key
persist-tun
ca ca.crt
auth-user-pass
comp-lzo
verb 3

client dev tun proto tcp remote OpenVPN-Server-IP PORT resolv-retry infinite nobind tun-mtu 1500 tun-mtu-extra 32 mssfix 1450 persist-key persist-tun ca ca.crt auth-user-pass comp-lzo verb 3

原文地址 : https://www.xj123.info/3191.html

本站遵循 : 署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5)

版权声明 : 原创文章转载时,请务必以超链接形式标明文章原始出处

Tags: FreeRADIUS , openvpn
  • 上一篇:CentOS安装配置L2TP并结合freeradius验证
  • 下一篇:KeyCool 87开箱+使用体验
10条评论
  1. 阳光不锈 说:

    很好的教程!
    正好有限制VPS,试验下!

    POST:2012-12-04 11:42 回复
  2. 所谓刚子 说:

    我之前折腾过 不过没折腾好!

    POST:2012-12-05 19:06 回复
  3. Breeze_CN 说:

    现在需要利用freeRADIUS搭建一个AAA服务器,不知道users之类的文件怎么配置……

    POST:2012-12-18 17:40 回复
  4. 不语 说:

    SIGUSR1[soft,connection-reset] received, client-instance restarting
    TCP/UDP: Closing socket
    报错了,不用radius验证就能过

    POST:2013-03-26 21:44 回复
    • 老谢 说:

      @不语 需要在/etc/openvpn/server.conf里面添加配置使radius插件生效的

      POST:2013-03-27 09:56 回复
      • 不语 说:

        已经添加 就是添加了才验证不过 不添加直接用证书即可通过

        POST:2013-03-27 15:34 回复
        • 老谢 说:

          @不语 那就说明radius验证是失败的,可以用radius的debug模式,判断下是哪边的问题

          POST:2013-03-28 09:36 回复
  5. ch.gvim@gmail.com 说:

    radius 这块的配置有链接吗

    POST:2013-03-27 12:17 回复
    • 老谢 说:

      @ch.gvim@gmail.com 我的博客写过,也可以网上搜,这方面的教程很多

      POST:2013-03-28 09:39 回复
  6. 小清新 说:

    昨天我弄了一天,都没有弄好!气死我了!

    POST:2013-04-22 13:43 回复
发表评论 点击取消评论.

*必填

*必填

  • 文章归档
  • 子网计算
  • 我的共享
  • 锻炼计划
  • 给我留言
  • 关于老谢
2023年 4月
一 二 三 四 五 六 日
 12
3456789
10111213141516
17181920212223
24252627282930
« 10月    

最新文章

  • 2021好久没更新博客
  • Zabbix监控oxidized备份状态
  • Zabbix 5.0 LTS版本MySQL表分区及编译安装随记
  • centos7.9部署oxidized自动备份交换机配置
  • Surface Pro 4更换屏幕与电池
  • VCSA中删除horizon view链接克隆生成的replica-受保护副本
  • Esxi6.7U3安装SanDisk Fusion-io 1.3T ioscale Pci SSD加速卡驱动
  • 搭建ELK日志系统分析处理fortigate的syslog日志
  • 华为USG防火墙配置NAT映射回流解决内网通过公网映射访问内部服务器
  • 飞塔防火墙fortitoken配置

最新评论

  • 无敌风火轮:和索尼没啥关系,这是索尼电脑的...
  • zhudong:老大,有VMware Horizon 7.12相关资...
  • qx:所有连接失效了,求一份
  • RainH:大佬,这个111.111.111.111是什么鬼?...
  • 王叨叨:幸福的人都是相似的,不幸的人各有各...
  • 李海博客:李海博客前来学习!
  • 明月登楼:最近使用了ZeroSSL证书,感觉还不...
  • 鸟叔:尽管不知道干啥的,还是来顶一下
  • 鸟叔:鸟叔来贵博客参观学习,通过十年之约穿...
  • 周良粥凉:往前看。

日志存档

  • 2021年10月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2020年11月
  • 2020年9月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年1月
  • 2019年12月
  • 2019年10月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年3月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年1月
  • 2017年10月
  • 2017年9月
  • 2017年8月
  • 2017年7月
  • 2017年2月
  • 2017年1月
  • 2016年12月
  • 2016年11月
  • 2016年10月
  • 2016年7月
  • 2016年6月
  • 2016年4月
  • 2016年2月
  • 2016年1月
  • 2015年12月
  • 2015年10月
  • 2015年9月
  • 2015年7月
  • 2015年5月
  • 2015年4月
  • 2015年3月
  • 2015年2月
  • 2015年1月
  • 2014年12月
  • 2014年10月
  • 2014年9月
  • 2014年8月
  • 2014年7月
  • 2014年6月
  • 2014年5月
  • 2014年4月
  • 2014年3月
  • 2014年2月
  • 2014年1月
  • 2013年12月
  • 2013年11月
  • 2013年10月
  • 2013年9月
  • 2013年8月
  • 2013年7月
  • 2013年6月
  • 2013年5月
  • 2013年4月
  • 2013年3月
  • 2013年2月
  • 2013年1月
  • 2012年12月
  • 2012年11月
  • 2012年9月
  • 2012年8月
  • 2012年7月
  • 2012年6月
  • 2012年5月
  • 2012年4月
  • 2012年3月
  • 2012年2月
  • 2012年1月
  • 2011年12月
  • 2011年11月
  • 2011年10月
  • 2011年9月
  • 2011年8月
  • 2011年7月
  • 2011年6月
  • 2011年5月
  • 2011年4月
  • 2011年3月
  • 2011年2月
  • 2011年1月
  • 2010年12月
  • 2010年11月
  • 2010年10月
  • 2010年9月
  • 2010年8月
  • 2010年7月

W3C

  • XHTML 1.0 Transitional
  • CSS level 3
  • Google+
Copyright © 2010-2023 老谢博客 All rights reserved.
Gzipped 76.5% | Optimized loading 65 queries in 0.346 seconds | Memory 33.59 MB | 皖ICP备13010663号-1
Powered by WordPress. | Hosted By 腾讯云 | Theme by WordPress主题巴士 | 站点地图 | SiteMap | Uptime | 技术支持:苏州天剑计算机系统有限公司