- (四) 搭建Open××× Server 路由模式 + 口令认证+TEXT/POP3
还是(一)的网络环境
目的:客户端还是连接到公司局域网中,但为了用户管理方便,认证数据从TEXT 数据库中提取。
Open××× Server 基本设定:连接方式采用路由,认证方式采用TEXT/POP3认证,虚拟设备使用tun
- 1. 下载TEXT认证脚本 checkpsw.sh ,并且复制到 /usr/local/etc/ 目录中同时chmod u+x 。
http://openvpn.se/files/other/
注意: 1.脚本保存到 windows 中再上传导 linux 有问题,最好在那个目录新建一个同名文件再从控制台粘贴进去。
2.脚本的开始不是 #! 要改正。
2.配置服务器配置文件, 在(一)的基础上
添加如下几行:
# auth-user-pass-verify cmd method: Query client for username/password and
# run script cmd to verify. If method='via-env', pass
# user/pass via environment, if method='via-file', pass
# user/pass via temporary file.
auth-user-pass-verify /usr/local/etc/checkpsw.sh via-env
#不请求客户的CA证书,使用User/Pass验证
client-cert-not-required
#使用客户提供的UserName作为Common Name
username-as-common-name
3..配置客户端配置文件
注释掉
;cert client1.crt
;key client1.key
增加
#询问用户名和密码
auth-user-pass
4.更改 checkpsw.sh 中的PASSFILE 变量为。
PASSFILE="/usr/local/etc/psw-file"
- 5. 创建 /usr/local/etc/psw-file 内容如下:
格式:用户名Tab密码
User1 pass
User2 pass
注:实验成功后我自己仿照 checkpsw.sh 用 perl 重写了一遍(目录中的checkpsw.pl),也可以使用。
6.同样的原理我们还可以使用POP3 认证(^_^ 其他的当然也可以)
脚本见目录中的 popauth.pl
- (五) 搭建Open××× Server 路由模式 + 口令认证+RADIUS
网络环境:在(一)的基础上添加一台 win2003 服务器 ip 为 192.168.80.130
^_^ 不好意思,我把服务器给放到了公网上了。不过还好是测试。
目的:客户端还是连接到公司局域网中,但为了用户管理方便,认证数据从radius 数据库中提取。
Open××× Server 基本设定:连接方式采用路由,认证方式采用radius认证,虚拟设备使用tun
- 1. 搭建 Radius 服务器
见附录 搭建 win2003 下的IAS 服务
- 2. 配置 radiusplugin
1.radiusplugin_v2.0.tar.gz: 可以编译得到radiusplugin.so
到http://www.nongnu.org/radiusplugin/下载
2.libgcrypt 支持库: 可以编译得到/usr/lib/libgcrypt.so.11
到ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.2.4.tar.gz 下载
3.libgpg-error 支持库: 可以编译得到/usr/local/lib/libgpg-error.so.0
到ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.5.tar.gz 下载
简单的编译以上3 个支持库,configure;make;make install。
我们要用到radiusplugin.so,其他是radiusplugin.so 的支持库。
好了如果能够得到radiusplugin.so,已经成功了80%,其他的就是配置了。
把radiusplugin.so 拷贝到/usr/local/etc/lib 下,并配置其配置文件radiusplugin.conf
内容如下:
# The NAS identifier which is sent to the RADIUS server
NAS-Identifier=OpenVpn
# The service type which is sent to the RADIUS server
Service-Type=5
# The framed protocol which is sent to the RADIUS server
Framed-Protocol=1
# The NAS port type which is sent to the RADIUS server
NAS-Port-Type=5
# 这是运行openvpn 服务器的ip,作为radius 客户端
NAS-IP-Address=192.168.80.129
#这里指明openvpn 的配置位置
Open×××Config=/usr/local/etc/server.conf
# 这里定义 radius server 参数可以超过1 个作为备份
server
{
# The UDP port for radius accounting.
acctport=1813
# The UDP port for radius authentication.
authport=1812
# 这是我radius 服务器的ip,并添加了用户。
name=192.168.80.130
# 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.共享密钥,在winradius 里配置,设置-系统-NAS 密钥
sharedsecret=123456
}
3.配置服务器配置文件, 在(一)的基础上
添加如下几行:
#说明使用的插件
plugin /usr/local/etc/lib/radiusplugin.so /usr/local/etc/radius.conf
#不请求客户的CA证书,使用User/Pass验证
client-cert-not-required
#使用客户提供的UserName作为Common Name
username-as-common-name
4.配置客户端配置文件
注释掉
;cert client1.crt
;key client1.key
增加
#询问用户名和密码
auth-user-pass
使用客户端连接服务器 测试 ok
- (六) 搭建Open××× Site to Site
目的:公司局域网 LAN B 和在其它城市公司分部网络 LAN A 要互相连通,共享彼此的资源。
Open××× Server 基本设定:连接方式采用路由,认证方式采用证书认证,虚拟设备使用tun
网络环境:
- 1. vpn client 和 vpn server两台设备都将作为各自网络的GW,系统为 CentOS 5.2 上面安装 Open××× 软件。并开启 ip 转发,防火墙已设置妥当。
- 2. 配置openvpn server 在(一) 的基础上:
添加:
route 192.168.90.0 255.255.255.0
client-config-dir /usr/local/etc/ccd
配置要点:
使用 tun 点对点的虚拟连接(路由)
dev tun
在本机添加一条到 192.168.90.0 255.255.255.0 via 就是对端 (10.9.0.2)
route 192.168.90.0 255.255.255.0
push一条路由到客户端,告诉客户机 172.18.2.0 255.255.255.0 在它的对端 (10.9.0.5)
push "route 172.18.2.0 255.255.255.0"
为vpn clien 设置单独配置文件,内容是:iroute 192.168.90.0 255.255.255.0
client-config-dir /usr/local/etc/ccd
- 3. 配置 ××× Client
同(一)
4.使用 ping pathping tracert 等命令测试, LAN A 和 LAN B 两个网络连通 ok
至此 Open××× Site to Site 配置完成。
- (七) Open ××× 其它配置选项
- 1. 服务器选项
- a) #定义最大连接数 ;max-clients 100
- b) #记录日志,每次重新启动openvpn后删除原有的log信息 log /var/log/openvpn.log #和log一致,每次重新启动openvpn后保留原有的log信息,新信息追加到文件最后 ;log-append openvpn.log
- c) #如果可以让××× Client之间相互访问直接通过openvpn程序转发, #不用发送到tun或者tap设备后重新转发,优化Client to Client的访问效率 client-to-client
- d) #使Client的默认网关指向×××,让Client的所有Traffic都通过×××走 ;push "redirect-gateway"
- e) 在vpn client 连接或退出时,执行脚本。可以用于生成用户访问日志。
client-connect /usr/local/etc/connect client-disconnect /usr/local/etc/disconnect
脚本 见附录
f)#定义运行openvpn的用户 user nobody group nobody
- 2. 客户端选项
a)可以有多个vpn 服务器做负载均衡,然后客户端配置这样写
remote 61.1.1.2 1194
remote 22.1.1.2 1194
# 随机选择一个Server连接,否则按照顺序从上到下依次连接
;remote-random
b)如果 remote 后接的是域名
# 始终重新解析Server的IP地址(如果remote后面跟的是域名), # 保证Server IP地址是动态的使用DDNS动态更新DNS后,Client在自动重新连接时重新解析Server的IP地址 # 这样无需人为重新启动,即可重新接入××× resolv-retry infinite
C)# 如果你使用HTTP代理连接××× Server,把Proxy的IP地址和端口写到下面 # 如果代理需要验证,使用http-proxy server port [authfile] [auth-method] # 其中authfile是一个2行的文本文件,用户名和密码各占一行,auth-method可以省略,详细信息查看Manual ;http-proxy-retry # retry on connection failures ;http-proxy [proxy server] [proxy port #]