目前域名解析,明明是正确的域名却无法解析,总是跳到ISP的网站上去了。使用OpenDNS基本可以解决问题。如再不行就要通过手动修改本地hosts文件,或者远程解析DNS来解决这种错误的域名解析,为什么要远程解析?这就涉及到了DNS污染技术。

  DNS污染是一种让一般用户由于得到虚假目标主机IP而不能与其通信的方法,是一种DNS缓存投毒攻击(DNS cache poisoning)。其工作方式是:在UDP端口53上的DNS查询进行入侵检测,一经发现与关键词相匹配的请求则立即伪装成目标域名的解析服务器(NS,Name Server)给查询者返回虚假结果。由于通常的DNS查询没有任何认证机制,而且DNS查询通常基于的UDP是无连接不可靠的协议,查询者只能接受最先到达的格式正确结果,并丢弃之后的结果。对于不了解相关知识的网民来说也就是,由于系统默认使用的ISP提供的NS查询国外的权威服务器时被劫持,其缓存受到污染,因而默认情况下查询ISP的服务器就会获得虚假IP;而用户直接查询境外NS(比如OpenDNS)又可能被劫持,从而在没有防范机制的情况下仍然不能获得正确IP

  在Firefox中,设置远程解析DNS很简单,只需要在在about:config 改成 network.proxy.socks_remote_dns=true 就可以了。对于IE或者其他用户来说,需要安装一个名为SocksCap的软件,选中Resolve all names remot即可。

OpenVPN可以解决PPTP 因电信屏蔽特定端口或路由器转发不支持的VPN问题。

---------------------------------------------------------------------------------------------------------------

无论你何时使用Internet,都会用到DNS。每次发送电子邮件或是在网上冲浪,你都必须依赖DNS。DNS负责主机名字之间和互联网络地址之间的映射,是由计算机来处理的,要是连接DNS服务器的过程出现延迟,或者如果DNS服务器解析某个地址时间过长,那么访问就会出现延迟。而如果能够以某种方式加快域名解析,就能够加快上网冲浪的速度,下面介绍的是一种加速方法:使用OpenDNS。

(nslookup命令的功能是查询一台机器的IP地址和其对应的域名。它通常需要一台域名服务器来提供域名服务。如果用户已经设置好域名服务器,就可以用这个命令查看不同主机的IP地址对应的域名)

一.OpenDNS的特点有三个:

1.OpenDNS具有更安全的特点。OpenDN可以识别和阻止钓鱼(Phishing)网站,就像在你访问的网站和你之间设了一个检查站,保护你的安全。

2.OPEN DNS具有更快的特点。它比一般的

2、点击网络和因特网 。

3、点击网络中心 。

4、点击个性化 ,未来你的网络。

5、点击性能按钮。

6、另一个窗口会弹出-再点击特性按钮后。

7、vista会问你许可作出改动,点击继续按钮。

8、选择互联网协议第4版( tcp/ipv4 ) ,然后点击按钮特性 。

9、点击按钮电台使用下列域名服务器地址和类型opendns地址首选域名服务器 和候补域名服务器领域。

请写下您当前的dns设置,然后切换到opendns ,如果你想回到你的老设定任何理由。---http://www.bianceng.cn

首选域名服务器的地址开放dns是:

208.67.222.222

208.67.222.222

候补域名服务器的地址开放dns是:

208.67.220.220

208.67.220.220

10、点击ok按钮。

11、重新启动计算机。

访问http://welcome.opendns.com/测试你的新风貌。 你应该看到欢迎页,从opendns ,如下所示。

 

三.配置路由器

如果只对一台PC进行配置,那么就只有这台PC才能使用OpenDNS服务器。如果希望网络上的所有PC都可以使用这种服务器,只要告诉路由器使用OpenDNS服务器,然后网络上的所有PC都会照着做。这样一来,就不必对每台PC进行配置了。

下面以Linksys WRT54GL为例介绍一下如何设置路由器:

1、访问路由器的ip地址在新的浏览窗口。

http://192.168.1.1是默认的linksys路由器的ip地址。

2、进入网络密码。

"输入网络密码"窗口就会出现。跳过用户名称和类型路由器的密码(管理员是默认的密码,如果你没有改变它) ,点击ok按钮。

3、类型opendns地址静态域名1和静态域名2场。

请写下您当前的dns设置,然后切换到opendns ,如果你想回到你的老设定任何理由。

地址公开域名:

208.67.222.222

208.67.220.220

4、单击保存设置按钮。

5、重新启动计算机和路由器。

访问http://welcome.opendns.com/测试你的新风貌。

你应该看到欢迎页,从opendns ,如下所示。

四、如果运行企业网络,又需要设置方面的帮助,最好的办法就是参阅OpenDNS FAQ页面(http://www.opendns.com/faq/)。如果使用虚拟专用网(VPN),OpenDNS可能无法正常工作。譬如说,使用思科VPN,就无法让OpenDNS正常工作。如果连接在企业网络上,在使用OpenDNS之前,应找系统管理员联系一下。

五、OpenDNS还可以创建快捷键,那样只要输入一个字母或者一组字母,而不是输入完整的URL,即可访问相应网站。为此,首先需要进行注册,这是免费的。注册完毕后登录,点击“快捷键”链接。在随后出现的页面上,在顶部方框里输入快捷键文本,在底部方框里输入URL,然后点击“创建快捷键”。之后,每当往浏览器窗口里面输入快捷键文本,就会被带到完整的URL。

OpenDNS使用的种种问题

1、为什么我不能访问网站?

如果你有问题,进入了一个网站,首先要肯定域正确解决了,用我们cachecheck节目http://www.opendns.com/cache

如果域不解决后,清新缓存,然后再次尝试第三方域名遍历报告。如果域名遍历报告显示,并非所有的比赛记录,或有没有一个记录,该域名,那么,这是不是一个opendns问题。相反,这是一个问题同authoriative域名服务器是域。

如果cachecheck和第三方域名遍历报告表明没有解决问题,那么它有可能是服务器的问题。

2、电脑进入一个专用网络的名称

opendns不能解决名字私人网络。你可以绕过这个由拥有这些名字在当地hosts文件。 对linux / unix系统或mac os x中,包括姓名和联系地址,在/ etc / hosts文件。 对窗口,包括姓名和联系地址,在主机或lmhosts文件( / windows/system32/drivers/etc ) 。 如果你使用lmhosts文件,你将需要使lmhosts查找你的tcp / ip连接。

3、如何检查opendns的缓存,如果你有麻烦,解决域名

opendns拥有庞大储藏,其中原因之一是opendns使你的互联网体验更快。可以检查什么opendns见客户时,他们要求一个域名。 如果有什么不当,你可以刷新opendns的缓存该域名。 OpenDNS CacheCheck: http://cache.opendns.com opendns cachecheck : http://cache.opendns.com

4、opendns不寄送电子邮件

opendns不发送电子邮件给任何人,除非其注册成员,然后才不定期或请求。 。如果你得到一个电子邮件和一个链接需你opendns指导,这并不意味着opendns发送电子邮件。相反,它意味着谁发送电子邮件(垃圾,垃圾邮件,或其他方式)产生了无效域名或断链接在其电子邮件。 这是不幸的共通点,尤其是来自少合法来源。

总结:尽管opendns以更快更安全更稳定的特性,逐渐被社会各界认可。但OpenDNS服务器是在国外,所以在使用国内的一些基站服务的时候,会有一定的网速慢,或者称为延迟的现象出现,比如使用在先看股票的一些软件,在寻找服务器测速的时候,会普遍显示网速“慢”,另外,对于一些游戏玩家来说可能是不好的消息,使用OpenDNS以后,无论是浩方还是QQ对战等一些游戏对战平台都会出现ping值高于500,同样,玩国内股务器的网络游戏也会出现ping值过高的情况,所以我的建议就是:介于设置OpenDNS的方法十分简单,不妨在平时浏览网页时使用OpenDNS,而在网游的时候将OpenDNS的设置解除,也就是说在玩网游的时候依旧使用ADSL的服务器。相信OPENDNS将会发展得更号,我们拭目以待吧!

-----------------------------------------------------------------------------------------

下载安装OpenVPN:

用Flashget或者其它任何方式下载OpenVPN的安装包,然后安装,记得选上easy-rsa这部分脚本,
用于管理CA的bat脚本。
http://openvpn.se/files/install_packages/openvpn-2.0.5-gui-1.0.3-install.exe

安装完毕后,easy-rsa在C:\Program Files\OpenVPN\目录下。

下面开始配置:
把easy-rsa目录下的vars.bat.sample改名为vars.bat,并且修改其内容:
==================================
set KEY_COUNTRY=CN
set KEY_PROVINCE=Liaoning
set KEY_CITY=Shenyang
set KEY_ORG=OpenVPN
set KEY_EMAIL=elm@elm.freetcp.com
==================================
其它部分就不用修改了,上面部分修改成你自己的配置。

把easy-rsa下的openssl.cnf.sample改成openssl.cnf。

然后进入cmd.exe
=============================================
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>cd "\Program Files\OpenVPN\easy-rsa"

C:\Program Files\OpenVPN\easy-rsa>vars

C:\Program Files\OpenVPN\easy-rsa>clean-all.bat
系统找不到指定的文件。
已复制         1 个文件。
已复制         1 个文件。

C:\Program Files\OpenVPN\easy-rsa>

生成Root CA
格式: build-ca.bat
输出: keys/ca.crt keys/ca.key
======================================================================
C:\Program Files\OpenVPN\easy-rsa>build-ca.bat
Using configuration from openssl.cnf
Generating a 1024 bit RSA private key
......++++++
.........++++++
writing new private key to 'keys\ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) []:OpenVPN ORG
Common Name (eg, your name or your server's hostname) []:OpenVPN RootCA
Email Address [elm@elm.freetcp.com]:

C:\Program Files\OpenVPN\easy-rsa>

生成dh1024.pem文件,Server使用TLS必须使用的一个文件。
格式: build-dh.bat
输出: keys/dh1024.pem
============================================================================
C:\Program Files\OpenVPN\easy-rsa>build-dh.bat
warning, not much extra random data, consider using the -rand option
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
.....................+...............+........+.................................
....................................+...........................+...............
........................................+.......................................
.........................................+...............+......................
................................................................................
.......................+..................................+.....................
..........................+.........................+...........+...............
.......+.........................+..............................................
........+....+..................................................................
................................................................................
...+....+.+...........................................+.........................
....................................................................+...........
.................+.....................................................+........
..............................................................+...+.............
.....+.........................+...........+....................................
................+......................+.....................................+..
....................................................................+.........+.
......+........................................................+................
...............................+..+.............................+...............
..............................................+.......................+.........
................................................................................
............................................................................+...
...................................+.............+..............................
.............................................................+.+........+.......
..............................................+.................................
...+............................................................................
............+..................................................+................
...........................+..........................................+........+
.........+.........+..........................................+................+
..+..........................................................................+..
.....+..+....................+.....................+............................
................................................................................
...........+.........+....+.........................+...........+.......+.+.....
.....................................................+................+.........
..........+.....................................................................
................+...............................................+..........+....
................................................................................
.................+.........................................+....................
..............................................................................+.
.......+.......................................................+..+.............
+................................+...+..........................+...............
..........................................................+..................+..
................................................................................
......................................................+.........................
....+.......................+.......................+...........................
..............+.................................................................
.......................................................+........................
..........................................................................+.....
......+..................................+......................................
...................................................+..................+.........
..............+.......................+.........................................
................................................................................
.....+....................+...........................+.........................
................................................................................
........................................................................++*++*++
*

C:\Program Files\OpenVPN\easy-rsa>

下面开始生成Server使用的证书了:
格式: build-key-server.bat <filename>
输出: keys/<filename>.crt <filename>.csr <filename>.key
================================================================================
C:\Program Files\OpenVPN\easy-rsa>build-key-server.bat server01
Using configuration from openssl.cnf
Generating a 1024 bit RSA private key
................++++++
.....++++++
writing new private key to 'keys\server01.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) []:OpenVPN ORG
Common Name (eg, your name or your server's hostname) []:Server01
Email Address [elm@elm.freetcp.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from openssl.cnf
Check that the request matches the signature
Signature ok
The Subjects Distinguished Name is as follows
countryName           :PRINTABLE:'CN'
stateOrProvinceName   :PRINTABLE:'Liaoning'
localityName          :PRINTABLE:'Shenyang'
organizationName      :PRINTABLE:'OpenVPN'
organizationalUnitName:PRINTABLE:'OpenVPN ORG'
commonName            :PRINTABLE:'Server01'
emailAddress          :IA5STRING:'elm@elm.freetcp.com'
Certificate is to be certified until Feb  9 10:01:34 2016 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

C:\Program Files\OpenVPN\easy-rsa>

下面开始为client办法证书:
格式: build-key.bat <filename>
输出: keys/<filename>.crt keys/<filename>.csr keys/<filename>.key
===========================================================================
C:\Program Files\OpenVPN\easy-rsa>build-key.bat elm
Using configuration from openssl.cnf
Generating a 1024 bit RSA private key
.....................................................++++++
...................................................++++++
writing new private key to 'keys\elm.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) []:OpenVPN ORG
Common Name (eg, your name or your server's hostname) []:ELM
Email Address [elm@elm.freetcp.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from openssl.cnf
Check that the request matches the signature
Signature ok
The Subjects Distinguished Name is as follows
countryName           :PRINTABLE:'CN'
stateOrProvinceName   :PRINTABLE:'Liaoning'
localityName          :PRINTABLE:'Shenyang'
organizationName      :PRINTABLE:'OpenVPN'
organizationalUnitName:PRINTABLE:'OpenVPN ORG'
commonName            :PRINTABLE:'ELM'
emailAddress          :IA5STRING:'elm@elm.freetcp.com'
Certificate is to be certified until Feb  9 10:05:53 2016 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

C:\Program Files\OpenVPN\easy-rsa>

下面生成ta.key文件
格式: openvpn --genkey --secret keys/ta.key
输出: keys/ta.key
=========================================================================
C:\Program Files\OpenVPN\easy-rsa>openvpn --genkey --secret keys/ta.key

C:\Program Files\OpenVPN\easy-rsa>

OK,那些keys就搞定了,下面开始写配置文件。
server01.ovpn内容:
----------------CUT Here-------------
port 1194
proto udp
dev tap
ca ca.crt
cert server01.crt
key server01.key # This file should be kept secret
;crl-verify vpncrl.pem
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-to-client
;duplicate-cn
keepalive 10 120
tls-auth ta.key 0 # This file is secret
comp-lzo
;max-clients 100
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
verb 3
--------------Cut Here-----------------
把配置文件放到C:\Program Files\OpenVPN\config\目录下。
把easy-rsa\keys\下的 ca.crt server01.crt server01.key ta.key dh1024.pem
复制到server01.ovpn所在目录。

Server的配置已经结束,可以启动Server了,在右下角OpenVPN-gui上点右键,然后选择connected。
需要服务器启动后自动运行,修改 "控制面板" 下面的 "管理工具" 下的 "服务" 把OpenVPN设置成自动启动。

Client的配置文件:
-------------Cut Here---------------------
client
dev tap
proto udp

remote 61.1.1.2 1194
;remote my-server-2 1194

;remote-random

resolv-retry infinite
nobind
user nobody
group nobody
route 192.168.0.0 255.255.252.0
persist-key
persist-tun

;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

ca ca.crt
cert elm.crt
key elm.key

ns-cert-type server
tls-auth ta.key 1
comp-lzo
# Set log file verbosity.
verb 4
--------------Cut Here---------------------
并且把easy-rsa/keys下的ca.crt elm.crt elm.key ta.key一起放到Client的
<OPENVPN_HOME>\config目录下。

Client的配置已经结束,可以连接Server了,在右下角OpenVPN-gui上点右键,然后选择connected。


OK,整个配置就完成了。

需要为其它用户颁发证书,只需如下步骤:
进入cmd.exe

cd <OPENVPN_HOME>\easy-rsa
vars.bat
build-kye.bat <filename>

Client所需要的文件:

client.ovpn (需要修改部分配置)
ca.crt
<fielname>.crt
<filename>.key (<filename>为 文件名,如: elm 等)
ta.key

 

 


------------------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------


OpenVPN在Windows下使用User/Pass验证

对于Windows下使用User/Pass验证已经是很久以前的承诺了,因为一开始一直都是在找寻
使用CMD(bat)文件检查用户名/密码的方式,但是一直没有结果,最后使用C写了一个小程
序实现用户名/密码验证。

转载请注明出处,如有疑问访问: http://wenzk.cublog.cn 反馈。

Windows安装OpenVPN是很容易的,OpenVPN GUI下载网址:
http://openvpn.se/files/install_packages/openvpn-2.0.7-gui-1.0.3-install.exe

记得选上easy-rsa这部分脚本,安装完毕后,easy-rsa在C:\Program Files\OpenVPN\目录下。

把easy-rsa目录下的vars.bat.sample改名为vars.bat,并且修改其内容:
==================================
set KEY_COUNTRY=CN
set KEY_PROVINCE=Liaoning
set KEY_CITY=Shenyang
set KEY_ORG=OpenVPN
set KEY_EMAIL=elm@elm.freetcp.com
==================================
其它部分就不用修改了,上面部分修改成你自己的配置。

把easy-rsa下的openssl.cnf.sample改成openssl.cnf。

然后进入cmd.exe
=============================================
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>cd "\Program Files\OpenVPN\easy-rsa"

C:\Program Files\OpenVPN\easy-rsa>vars

C:\Program Files\OpenVPN\easy-rsa>clean-all.bat
系统找不到指定的文件。
已复制         1 个文件。
已复制         1 个文件。

C:\Program Files\OpenVPN\easy-rsa>

生成Root CA
格式: build-ca.bat
输出: keys/ca.crt keys/ca.key
======================================================================
C:\Program Files\OpenVPN\easy-rsa>build-ca.bat
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
................................................................................
....++++++
....................................++++++
writing new private key to 'keys\ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) []:OpenVPN ORG
Common Name (eg, your name or your server's hostname) []:OpenVPN ROOTCA
Email Address [elm@elm.freetcp.com]:


生成dh1024.pem文件,Server使用TLS必须使用的一个文件。
格式: build-dh.bat
输出: keys/dh1024.pem
============================================================================
C:\Program Files\OpenVPN\easy-rsa>build-dh.bat
Loading 'screen' into random state - done
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
............................................................+.................+.
................................................................................
................................................................................
....+..................+...........................+..........................+.
.........................+............................+.+.......................
............................................+......+...+...............+........
..+...........+............+.....................+...+.........................+
.....+..............................................................+...........
...............+....................................+.......................+...
.....................................................+..........................
..................................................+.............................
......................................+..............+.+........................
+..........................................................................+....
................................................................+...............
......................................+...+.............................+.......
............+...........+................+......................................
.........+...........................................+..........................
................................................................................
.+.......+....+..............+..................................................
.........................................................................+......
..........+.....................................................................
................................................................................
...........................+....................................................
........+.......................................................................
...................................................+..............+.........+...
........................................+.........+...................+.........
.............+.......+..........+............+................+.................
................................................................................
................................................................................
.................................+.................................++*++*++*

C:\Program Files\OpenVPN\easy-rsa>

下面开始生成Server使用的证书:
格式: build-key-server.bat <filename>
输出: keys/<filename>.crt <filename>.csr <filename>.key
================================================================================
C:\Program Files\OpenVPN\easy-rsa>build-key-server.bat server01
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
...............++++++
...........++++++
writing new private key to 'keys\server01.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) []:OpenVPN ORG
Common Name (eg, your name or your server's hostname) []:Server01
Email Address [elm@elm.freetcp.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from openssl.cnf
Loading 'screen' into random state - done
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'CN'
stateOrProvinceName   :PRINTABLE:'Liaoning'
localityName          :PRINTABLE:'Shenyang'
organizationName      :PRINTABLE:'OpenVPN'
organizationalUnitName:PRINTABLE:'OpenVPN ORG'
commonName            :PRINTABLE:'Server01'
emailAddress          :IA5STRING:'elm@elm.freetcp.com'
Certificate is to be certified until Jul  7 13:33:23 2016 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

C:\Program Files\OpenVPN\easy-rsa>

下面生成ta.key文件
格式: openvpn --genkey --secret keys/ta.key
输出: keys/ta.key
=========================================================================
C:\Program Files\OpenVPN\easy-rsa>openvpn --genkey --secret keys/ta.key

C:\Program Files\OpenVPN\easy-rsa>

OK,那些keys就搞定了,下面开始写配置文件。
server01.ovpn内容:
----------------CUT Here-------------
port 1194
; proto tcp
proto udp
; dev tap
dev tun
;dev-node MyTap
ca ca.crt
cert server01.crt
key server01.key  # This file should be kept secret
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-to-client
;duplicate-cn
keepalive 10 120
tls-auth ta.key 0 # This file is secret
auth-user-pass-verify checkpsw.exe via-env
client-cert-not-required
username-as-common-name
;cipher BF-CBC        # Blowfish (default)
;cipher AES-128-CBC   # AES
;cipher DES-EDE3-CBC  # Triple-DES
comp-lzo
;max-clients 100
user nobody
group nobody
persist-key
persist-tun
status status.log
;log         /var/log/openvpn.log
;log-append  /var/log/TCP_openvpn.log
verb 4
;mute 20
----------------CUT Here-------------
把配置文件放到C:\Program Files\OpenVPN\config\目录下。
把easy-rsa\keys\下的 ca.crt server01.crt server01.key ta.key dh1024.pem
复制到server01.ovpn所在目录。

同时下载本人写的破烂验证程序(checkpsw.exe)[不要仍砖块]放到OpenVPN配置目录下
程序在Windows XP SP2下测试通过,其他系统如果有问题,可以用源文件进行编译
程序在压缩包里面:
 文件: checkpsw.rar
大小: 9KB
下载: 下载
 

在checkpsw.exe目录下建立password.txt[用于存放用户名&密码]文件:
password.txt文件格式:
用户名           密码            是否活动(0/1) 中间用空格隔开
Username     Password    Active
-------------Cut Here---------------------
wzk         wzk         1
-------------Cut Here---------------------

 

Server的配置已经结束,可以启动Server了,在右下角OpenVPN-gui上点右键,然后选择connected。
需要服务器启动后自动运行,修改 "控制面板" 下面的 "管理工具" 下的 "服务" 把OpenVPN设置成自动启动。

Client的配置文件:
client.ovpn
-------------Cut Here---------------------
client
dev tun
proto udp

remote 61.1.1.2 1194
;remote my-server-2 1194

;remote-random

resolv-retry infinite
nobind
user nobody
group nobody
route 192.168.0.0 255.255.252.0
persist-key
persist-tun

;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

ca ca.crt
auth-user-pass

ns-cert-type server
tls-auth ta.key 1
comp-lzo
# Set log file verbosity.
verb 4
--------------Cut Here---------------------
并且把easy-rsa/keys下的ca.crt ta.key一起放到Client的
<OPENVPN_HOME>\config目录下。

Client的配置已经结束,可以连接Server了,在右下角OpenVPN-gui上点右键,然后选择connected。


OK,整个配置就完成了。

 

------------------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------

OpenVPN 配置文件详解
Server使用的配置文件server.conf
—————————–
#申明本机使用的IP地址,也可以不说明
;local a.b.c.d
#申明使用的端口,默认1194
port 1194
#申明使用的协议,默认使用UDP,如果使用HTTP proxy,必须使用TCP协议
;proto tcp
proto udp
#申明使用的设备可选tap和tun,tap是二层设备,支持链路层协议。
#tun是ip层的点对点协议,限制稍微多一些,本人习惯使用TAP设备
dev tap
;dev tun
#OpenVPN使用的ROOT CA,使用build-ca生成的,用于验证客户是证书是否合法
ca ca.crt
#Server使用的证书文件
cert server.crt
#Server使用的证书对应的key,注意文件的权限,防止被盗
key server.key # This file should be kept secret
#CRL文件的申明,被吊销的证书链,这些证书将无法登录
crl-verify vpncrl.pem
#上面提到的生成的Diffie-Hellman文件
dh dh1024.pem
#这是一条命令的合集,如果你是OpenVPN的老用户,就知道这条命令的来由
#这条命令等效于:
# mode server #OpenVPN工作在Server模式,可以支持多client同时动态接入
# tls-server #使用TLS加密传输,本端为Server,Client端为tls-client
#
# if dev tun: #如果使用tun设备,等效于以下配置
# ifconfig 10.8.0.1 10.8.0.2 #设置本地tun设备的地址
# ifconfig-pool 10.8.0.4 10.8.0.251 #说明OpenVPN使用的地址池(用于分配给客户),分别是起始地址、结束地址
# route 10.8.0.0 255.255.255.0 #增加一条静态路由,省略下一跳地址,下一跳为对端地址,这里是: 10.8.0.2
# if client-to-client: #如果使用client-to-client这个选项
# push “route 10.8.0.0 255.255.255.0″ #把这条路由发送给客户端,客户连接成功后自动加入路由表,省略了下一跳地址: 10.8.0.1
# else
# push “route 10.8.0.1″ #否则发送本条路由,这是一个主机路由,省略了子网掩码和下一跳地址,分别为: 255.255.255.255 10.8.0.1
#
# if dev tap: #如果使用tap设备,则等效于以下命令
# ifconfig 10.8.0.1 255.255.255.0 #配置tap设备的地址
# ifconfig-pool 10.8.0.2 10.8.0.254 255.255.255.0 #客户端使用的地址池,分别是起始地址、结束地址、子网掩码
# push “route-gateway 10.8.0.1″ #把环境变量route-gateway传递给客户机
#
server 10.8.0.0 255.255.255.0 #等效于以上命令
#用于记录某个Client获得的IP地址,类似于dhcpd.lease文件,
#防止openvpn重新启动后“忘记”Client曾经使用过的IP地址
ifconfig-pool-persist ipp.txt
#Bridge状态下类似DHCPD的配置,为客户分配地址,由于这里工作在路由模式,所以不使用
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
#通过VPN Server往Client push路由,client通过pull指令获得Server push的所有选项并应用
;push “route 192.168.10.0 255.255.255.0″
;push “route 192.168.20.0 255.255.255.0″
#VPN启动后,在VPN Server上增加的路由,VPN停止后自动删除
;route 10.9.0.0 255.255.255.252
#Run script or shell command cmd to validate client
#virtual addresses or routes. 具体查看manual
;learn-address ./script
#其他的一些需要PUSH给Client的选项
#
#使Client的默认网关指向VPN,让Client的所有Traffic都通过VPN走
;push “redirect-gateway”
#DHCP的一些选项,具体查看Manual
;push “dhcp-option DNS 10.8.0.1″
;push “dhcp-option WINS 10.8.0.1″
#如果可以让VPN Client之间相互访问直接通过openvpn程序转发,
#不用发送到tun或者tap设备后重新转发,优化Client to Client的访问效率
client-to-client
#如果Client使用的CA的Common Name有重复了,或者说客户都使用相同的CA
#和keys连接VPN,一定要打开这个选项,否则只允许一个人连接VPN
;duplicate-cn
#NAT后面使用VPN,如果VPN长时间不通信,NAT Session可能会失效,
#导致VPN连接丢失,为防止之类事情的发生,keepalive提供一个类似于ping的机制,
#下面表示每10秒通过VPN的Control通道ping对方,如果连续120秒无法ping通,
#认为连接丢失,并重新启动VPN,重新连接
#(对于mode server模式下的openvpn不会重新连接)。
keepalive 10 120
#上面提到的HMAC防火墙,防止DOS攻击,对于所有的控制信息,都使用HMAC signature,
#没有HMAC signature的控制信息不予处理,注意server端后面的数字肯定使用0,client使用1
tls-auth ta.key 0 # This file is secret
#对数据进行压缩,注意Server和Client一致
comp-lzo
#定义最大连接数
;max-clients 100
#定义运行openvpn的用户
user nobody
group nobody
#通过keepalive检测超时后,重新启动VPN,不重新读取keys,保留第一次使用的keys
persist-key
#通过keepalive检测超时后,重新启动VPN,一直保持tun或者tap设备是linkup的,
#否则网络连接会先linkdown然后linkup
persist-tun
#定期把openvpn的一些状态信息写到文件中,以便自己写程序计费或者进行其他操作
status openvpn-status.log
#记录日志,每次重新启动openvpn后删除原有的log信息
log /var/log/openvpn.log
#和log一致,每次重新启动openvpn后保留原有的log信息,新信息追加到文件最后
;log-append openvpn.log
#相当于debug level,具体查看manual
verb 3
——————————-
把server.conf文件保存到/etc/opennvpn目录中,并把使用easy-rsa下的脚本什成的key都复制到/etc/openvpn目录下,命令如下:
#cd /etc/openvpn
#cp easy-rsa/keys/ca.crt .
#cp easy-rsa/keys/server.crt .
#cp easy-rsa/keys/server.key .
#cp easy-rsa/keys/dh1024.pem .
#cp easy-rsa/keys/ta.key .
#cp easy-rsa/keys/vpncrl.pem .
创建OpenVPN启动脚本,可以在源代码目录中找到,在sample-scripts目录下的openvpn.init文件,将其复制到/etc/init.d/目录中,改名为openvpn
然后运行:
#chkconfig –add openvpn
#chkconfig openvpn on
立即启动openenvpn
#/etc/init.d/openvpn start

接下来配置客户端的配置文件client.conf:
Linux或Unix下使用扩展名为.conf Windows下使用的是.ovpn,并把需要使用的keys复制到配置文件所在目录ca.crt elm.crt elm.key ta.key
———————————-
# 申明我们是一个client,配置从server端pull过来,如IP地址,路由信息之类“Server使用push指令push过来的”
client

#指定接口的类型,严格和Server端一致
dev tap
;dev tun

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# 使用的协议,与Server严格一致
;proto tcp
proto udp

#设置Server的IP地址和端口,如果有多台机器做负载均衡,可以多次出现remote关键字

remote 61.1.1.2 1194
;remote my-server-2 1194

# 随机选择一个Server连接,否则按照顺序从上到下依次连接
;remote-random

# 始终重新解析Server的IP地址(如果remote后面跟的是域名),
# 保证Server IP地址是动态的使用DDNS动态更新DNS后,Client在自动重新连接时重新解析Server的IP地址
# 这样无需人为重新启动,即可重新接入VPN
resolv-retry infinite

# 在本机不邦定任何端口监听incoming数据,Client无需此操作,除非一对一的VPN有必要
nobind

# 运行openvpn用户的身份,旧版本在win下需要把这两行注释掉,新版本无需此操作
user nobody
group nobody

#在Client端增加路由,使得所有访问内网的流量都经过VPN出去
#当然也可以在Server的配置文件里头设置,Server配置里头使用的命令是
# push “route 192.168.0.0 255.255.255.0″
route 192.168.0.0 255.255.0.0

# 和Server配置上的功能一样如果使用了chroot或者su功能,最好打开下面2个选项,防止重新启动后找不到keys文件,或者nobody用户没有权限启动tun设备
persist-key
persist-tun

# 如果你使用HTTP代理连接VPN 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 #]

# 对于无线设备使用VPN的配置,看看就明白了
# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# Root CA 文件的文件名,用于验证Server CA证书合法性,通过easy-rsa/build-ca生成的ca.crt,和Server配置里的ca.crt是同一个文件
ca ca.crt
# easy-rsa/build-key生成的key pair文件,上面生成key部分中有提到,不同客户使用不同的keys修改以下两行配置并使用他们的keys即可。
cert elm.crt
key elm.key

# Server使用build-key-server脚本什成的,在x509 v3扩展中加入了ns-cert-type选项
# 防止VPN client使用他们的keys + DNS hack欺骗vpn client连接他们假冒的VPN Server
# 因为他们的CA里没有这个扩展
ns-cert-type server

# 和Server配置里一致,ta.key也一致,注意最后参数使用的是1
tls-auth ta.key 1

# 压缩选项,和Server严格一致
comp-lzo

# Set log file verbosity.
verb 4

OpenVPN使用User/Pass验证登录

penVPN使用User/Pass验证登录

在之前的OpenVPN+CA中已经介绍了使用CA验证登录的方式,
详见:http://bbs.chinaunix.net/forum/viewtopic.php?t=503434&show_type=new

本文主要介绍使用Username/Password方式验证登录VPN的方法,虽然使用的是User/Pass
方式登录,但是在Server端仍然需要证书,这样的VPN和web的HTTPs方式有点类似(不能等同),
只需Server端有证书,Client可以不提供自己的证书,Client只需验证Server的合法性即可,
所以Client端只需ca.crt(根证书)即可。当然,由于Client不是使用证书验证的,所以安全
性方面必然有所下降,但是省去了烦琐的CA管理,我们可以通过用户名和密码来登录VPN,
这样使得VPN可以很容易和论坛、邮件系统或者其他统一验证系统结合,使用现成的管理界面。

关于VPN的一些初步认识,可以从下面这个URL获得:(E文的)
http://blog.chinaunix.net/resserver.php?blogId=2389&resource=OpenVPN%20and%20the%20SSL%20VPN%20Revolution.pdf
原文出自:
http://www.giac.org/certified_professionals/practicals/gsec/3985.php
文中觉得很有意义的语句是: A VPN is a site-to-site tunnel. Let me say that one more time, a VPN is a site-to-site tunnel.
这篇文章介绍了OpenVPN1.x,也简单介绍了OpenVPN 2.x的一些新特性,同时也简单的介绍了
其他VPN以及不同方式实现的VPN产品、软件,有时间看看是很有必要的。

关于VPN比较通俗的理解,在OpenVPN的FAQ中找到的:
Imagine you had a direct physical wire (i.e. a long cable) connecting two computers (A and B) at different locations. On each computer there would be a /dev/longcable which would be a network device. You could route IP traffic over it, and do everything you could normally do with a network device.

下面开始介绍VPN的安装和配置:

环境:
OS: FC2 (在公司网络出口处,作路由或者是NAT设备使用)
eth0: 61.1.1.2 (外网地址,直接与Internet相连)
eth1: 192.168.0.1 (内网地址,连接公司内部,假设公司内部使用192.168.0.0/22这4个C地址)

Client端硬件及网络环境配置:
OS: Windown 2000 XP 为主,部分Linux (配置文件通用)
单网卡,IP地址不固定

需要达到的目的:
VPN Client可以随处通过User/Pass登录VPN,访问内网资源。

Server端配置

首先检查pam-devel包是否安装,否则从系统盘安装改软件包
[root@vpn ~]# rpm -qa | grep pam
pam_smb-1.1.7-3.1
pam-0.77-40
pam_krb5-2.0.10-1
pam-devel-0.77-40
[root@vpn ~]#

检查Mysql是否安装,确认mysql-devel包已经安装,否则从系统盘安装改软件包
[root@vpn ~]# rpm -qa | grep mysql
mysql-3.23.58-9
mysql-server-3.23.58-9
mysql-devel-3.23.58-9
[root@vpn ~]#

检查lzo包是否有安装,如果没有,可以到http://rpmfind.net去找
[root@vpn ~]# rpm -qa | grep lzo
[root@vpn ~]# wget ftp://rpmfind.net/linux/dag/fedora/2/en/i386/dag/RPMS/lzo-1.08-3.1.fc2.dag.i386.rpm
[root@vpn ~]# rpm -ivh lzo-1.08-3.1.fc2.dag.i386.rpm
[root@vpn ~]# wget ftp://rpmfind.net/linux/dag/fedora/2/en/i386/dag/RPMS/lzo-devel-1.08-3.1.fc2.dag.i386.rpm
[root@vpn ~]# rpm -ivh lzo-devel-1.08-3.1.fc2.dag.i386.rpm
[root@vpn ~]# rpm -qa | grep lzo
lzo-devel-1.08-3.1.fc2.dag
lzo-1.08-3.1.fc2.dag
[root@vpn ~]#

下面开始编译安装OpenVPN
[root@vpn ~]# wget http://mesh.dl.sourceforge.net/sourceforge/openvpn/openvpn-2.0_rc16.tar.gz
[root@vpn ~]# rpmbuild -tb openvpn-2.0_rc16.tar.gz
[root@vpn ~]# cd /usr/src/redhat/RPMS/i386/
[root@vpn /usr/src/redhat/RPMS/i386]# rpm -ivh openvpn-2.0_rc6-1.i386.rpm

为了能使用OpenVPN的PAM验证插件,我们安装pam_mysql使用MySQL数据库存储用户数据,其它数据库可以找相应的PAM验证模块
[root@vpn ~]# wget http://internap.dl.sourceforge.net/sourceforge/pam-mysql/pam_mysql-0.5.tar.gz
[root@vpn ~]# tar -zxvf pam_mysql-0.5.tar.gz
[root@vpn ~]# cd pam_mysql
[root@vpn ~]# make
[root@vpn ~]# cp pam_mysql.so /lib/security/

配置数据库
以管理员身份登录数据库:
mysql> create database vpn;
mysql> GRANT ALL ON vpn.* TO vpn@localhost IDENTIFIED BY 'vpn123';
mysql> flush privileges;
mysql> use vpn;
mysql> CREATE TABLE vpnuser (
-> name char(20) NOT NULL,
-> password char(128) default NULL,
-> active int(10) NOT NULL DEFAULT 1,
-> PRIMARY KEY (name)
-> );
mysql> insert into vpnuser (name,password) values('elm',password('elm'));

#创建vpn用户,对vpn这个database有所有操作权限,密码为vpn123
#active不为1,无权使用VPN
#增加用户 用户名:elm 密码:elm

配置pam_mysql模块
创建/etc/pam.d/openvpn文件,文件内容如下:
===================CUT Here================
auth sufficient pam_mysql.so user=vpn passwd=vpn123 host=localhost db=vpn \
table=vpnuser usercolumn=name passwdcolumn=password \
where=active=1 sqllog=0 crypt=2
account required pam_mysql.so user=vpn passwd=vpn123 host=localhost db=vpn \
table=vpnuser usercolumn=name passwdcolumn=password \
where=active=1 sqllog=0 crypt=2
==================Cut Here=================
crypt(0) -- Used to decide to use MySQL's PASSWORD() function or crypt()
0 = No encryption. Passwords in database in plaintext. NOT recommended!
1 = Use crypt
2 = Use MySQL PASSWORD() function

下面可以测试pam_mysql是否工作正常,先检查saslauthd是否安装:
[root@vpn ~]# rpm -qa | grep sasl
cyrus-sasl-plain-2.1.18-2
cyrus-sasl-md5-2.1.18-2
cyrus-sasl-devel-2.1.18-2
cyrus-sasl-2.1.18-2
[root@vpn ~]#

有cyrus-sasl-2.1.18-2应该就可以了,如果没有请安装相应的软件包,不安装也行,可以通过其它方法测试

[root@vpn ~]# saslauthd -a pam
[root@vpn ~]# testsaslauthd -u elm -p elm -s openvpn
0: OK "Success."
[root@vpn ~]#

恭喜,pam_mysql工作正常了,下面可以开始配置OpenVPN服务器了。

配置VPN Server:
[root@vpn /usr/src/redhat/RPMS/i386]# cd
[root@vpn ~]# cp -r /usr/share/openvpn/easy-rsa/ /etc/openvpn/
[root@vpn ~]# cd /etc/openvpn/easy-rsa/
[root@vpn /etc/openvpn/easy-rsa]# vi vars
修改vars 文件
-----------------------------------------
# 定义你所在的国家,2个字符
export KEY_COUNTRY=CN
# 你所在的省份
export KEY_PROVINCE=Liaoning
# 你所在的城市
export KEY_CITY=Shenyang
# 你所在的组织
export KEY_ORG="ELM OpenVPN ORG"
# 你的邮件地址
export KEY_EMAIL="elm@elm.freetcp.com"
-----------------------------------------

#使修改的环境变量生效

[root@vpn /etc/openvpn/easy-rsa]# . vars
NOTE: when you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys

#初始化keys目录

[root@vpn /etc/openvpn/easy-rsa]# ./clean-all

#生成Root CA证书,用于签发Server和Client证书,请保护好keys/ca.key文件。

[root@vpn /etc/openvpn/easy-rsa]# ./build-ca
Generating a 1024 bit RSA private key
........................++++++
.............++++++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]: #如果无需修改,直接回车
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [ELM OpenVPN ORG]:
Organizational Unit Name (eg, section) []: OpenVPN Service
Common Name (eg, your name or your server's hostname) []:OpenVPN Root CA
Email Address [elm@elm.freetcp.com]:

#查看生成的keys

[root@vpn /etc/openvpn/easy-rsa]# ls keys
ca.crt ca.key index.txt serial

#我们可以看到ca.crt ca.key文件已经生成了。
#面我们为服务器生成 Diffie-Hellman 文件
#TLS server 需要使用的一个文件

[root@vpn /etc/openvpn/easy-rsa]# ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
..+..............................................................+.................
...................................................+....+........+.........+.......
.............................................+.+...................................
...................................................................................
............................................+......................................
.+.................................+.............+.................................
................................................+..................................
.....................+.............................++*++*++*

#创建并签发VPN Server使用的CA
# `server' 为创建后的文件名,分别为server.crt server.key

[root@vpn /etc/openvpn/easy-rsa]# ./build-key-server server
Generating a 1024 bit RSA private key
......................++++++
...............++++++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [ELM OpenVPN ORG]:
Organizational Unit Name (eg, section) []:OpenVPN Service
Common Name (eg, your name or your server's hostname) []:Server No.1
Email Address [elm@elm.freetcp.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'Liaoning'
localityName :PRINTABLE:'Shenyang'
organizationName :PRINTABLE:'ELM OpenVPN ORG'
organizationalUnitName:PRINTABLE:'OpenVPN Service'
commonName :PRINTABLE:'Server No.1'
emailAddress :IA5STRING:'elm@elm.freetcp.com'
Certificate is to be certified until Feb 26 14:43:44 2015 GMT (3650 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

#为防止恶意攻击(如DOS、UDP port flooding),我们生成一个"HMAC firewall"

[root@vpn /etc/openvpn/easy-rsa]# openvpn --genkey --secret keys/ta.key

#Server使用的配置文件server.conf
----------------CUT Here-------------
port 1194
;proto tcp
proto udp
;dev tap
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
server 10.8.0.0 255.255.0.0
ifconfig-pool-persist ipp.txt
;client-to-client
;duplicate-cn
keepalive 10 120
tls-auth ta.key 0
plugin ./openvpn-auth-pam.so openvpn
client-cert-not-required
username-as-common-name
comp-lzo
;max-clients 100
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
;log /var/log/openvpn.log
;log-append openvpn.log
verb 4
;mute 20
--------------Cut Here-----------------

;client-to-client #如果让Client之间可以相互看见,去掉本行的注释掉,否则Client之间无法相互访问
;duplicate-cn #是否允许一个User同时登录多次,去掉本行注释后可以使用同一个用户名登录多次
plugin ./openvpn-auth-pam.so openvpn #说明使用的插件,openvpn为插件的参数,使用pam的servicesname
client-cert-not-required #不请求客户的CA证书,使用User/Pass验证
username-as-common-name #使用客户提供的UserName作为Common Name

把server.conf文件保存到/etc/opennvpn目录中,并把使用easy-rsa下的脚本什成的key都复制到/etc/openvpn目录下,命令如下:
[root@vpn /etc/openvpn/easy-rsa]# cp keys/ca.crt ../
[root@vpn /etc/openvpn/easy-rsa]# cp keys/server.crt ../
[root@vpn /etc/openvpn/easy-rsa]# cp keys/server.key ../
[root@vpn /etc/openvpn/easy-rsa]# cp keys/dh1024.pem ../
[root@vpn /etc/openvpn/easy-rsa]# cp keys/ta.key ../
[root@vpn /etc/openvpn/easy-rsa]# cp /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so ../

#立即启动openenvpn
[root@vpn /etc/openvpn/easy-rsa]# /etc/init.d/openvpn start

#接下来配置客户端的配置文件client.conf:
#Linux或Unix下使用扩展名为.conf Windows下使用的是.ovpn,并把需要使用的文件复制到配置文件所在目录ca.crt ta.key
-------------Cut Here---------------------
client
;dev tap
dev tun
;proto tcp
proto udp
remote 61.1.1.2 1194
;remote my-server-2 1194
remote-random
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
auth-user-pass
ns-cert-type server
tls-auth ta.key 1
route 192.168.0.0 255.255.252.0
comp-lzo
verb 4
;mute 20
------------Cut Here-----------------------

auth-user-pass #询问用户名和密码

Linux下Client的OpenVPN的安装方法一样,只是配置文件和keys上的不同,只要把client.conf ca.crt ta.key复制到/etc/openvpn目录即可启动VPN。
Win下OpenVPN的安装,WIN下有图形界面的OpenVPN-GUI程序,下载地址http://openvpn.se

这里使用的是TUN设备,主要考虑到Client客户多,VPN的效率和广播的问题,选用TUN设备,因为客户端可能是
Windows系统,Win系统TUN设备获得的IP地址将会是/30的地址,所以有3*Client个地址浪费,所以地址池设置得比较大。

这样你每次使用VPN登录的时候,程序会自动询问你得用户名和密码,输入正确后就可以连接上VPN了,
连接VPN后所有访问内网(192.168.0.0/22)的数据都从VPN经过。
如果Win的Client比较多,可以试着把ca.crt ta.key client.ovpn打包到安装包程序里,具体操作方法参见:

http://openvpn.se/files/howto/openvpn-howto_roll_your_own_installation_package-Rev1.1.html

然后发布改软件包即可,最好小心保管ta.key文件(防止Dos攻击)。

设置可以让远程vpn的客户端通过openvpn服务器来上internet , 在openvpn中开启了 push "redirect-gateway"  ,也就是 自动將 远程client 的 default gateway 设置经由 VPN server 出去, 远程clinet拨上后上网没有问题。