小辉程序员之路, since 1996 http://www.xiaohui.com
乐走天涯: 工作并快乐着,职业并休闲着
 » 首页 > 服务器维护与开发笔记

Linux 下 OpenVPN 安装和 Windows OpenVPN GUI 安装笔记


http://www.XiaoHui.com 日期: 2007-05-13 14:00

  基于伟大的 GFW 越来越牛B,网站的正常维护如 FTP、pop & smtp 的邮件收发、在 google 查技术资料,都经常被 GFW 强行断开。为了解决这个问题,于是我在自己的国外主机上安装了一个 OpenVPN,当时记录了一下安装的经过。

  今天正好又有一个朋友问及 OpenVPN 安装的事情,于是我重新整理一下这篇Linux 下 OpenVPN 安装和 Windows OpenVPN GUI 安装笔记(http://www.xiaohui.com/dev/server/20070514-install-openvpn.htm), 希望对大家有所帮助。

  当时在安装 OpenVPN 的时候,得到了 WenZK 的指导帮助。在此表示感谢。

一. OpenVPN 安装环境

    Server 端的环境
  1. redhat, kernel版本: 2.4.20-31.9, IP 为 70.8.7.6
  2. kernel 需要支持 tun 设备, 需要加载 iptables 模块.
    检查 tun 是否安装:
    代码:
    root@a [/]# modinfo tun 
    filename:    /lib/modules/2.4.20-31.9/kernel/drivers/net/tun.o 
    description:  
    author:       
    license:     "GPL" 
    
    如果没有 modinfo 命令, 直接找一下, 看看 kernel 里是否有 tun.o 文件:
    代码:
    find -name tun.o 
    ./lib/modules/2.4.20/kernel/drivers/net/tun.o 
    
    检查iptables 模块, 查看是否有下列文件:
    /etc/init.d/iptables
  3. 安装的 OpenVPN 的版本: 2.0.5. 现在似乎已经有一个更新的版本了. 可在http://openvpn.net 上下载.

    Client 端的环境:
  1. Windows XP PRO SP2
  2. OpenVPN GUI For windows 1.0.3 , 可在 openvpn.se 下载
    注意: OpenVPN GUI for windows 的版本要和 OpenVPN Server 的版本配套.
    例如, 服务器装的是 OpenVPN 2.0.5, 那么下载的 OpenVPN GUI fow windows 应该是: openvpn-2.0.5-gui-1.0.3-install.exe
    OpenVPN GUI的所有历史版本: http://openvpn.se/files/install_packages/

二. OpenVPN 服务端安装过程

http://www.xiaohui.com/dev/server/20070514-install-openvpn.htm
  1. 用 SecureCRT 登录到 host, 进入根目录 代码:
    cd / 
  2. 下载 LZO,解压到lzo-2.02.

    地址: http://www.oberhumer.com/opensource/lzo/download/ 代码:

    wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.02.tar.gz
  3. 下载 OpenVPN, 解压到openvpn-2.0.5

    地址: http://openvpn.net/download.html 代码:

    wget http://openvpn.net/release/openvpn-2.0.5.tar.gz
  4. 安装 LZO 代码:
    cd /lzo-2.02 
    ./configure 
    make 
    make check 
    make install 
  5. 安装 OpenVPN

    代码:

    cd /openvpn-2.0.5
    ./configure 
    # 或用指定dir: (注:下述命令, 应该在一行写完. 为了方便显示, 这里分成了四行)
    # ./configure --with-lzo-headers=/usr/local/include 
    #  --with-lzo-lib=/usr/local/lib 
    #  --with-ssl-headers=/usr/local/include/openssl 
    #  --with-ssl-lib=/usr/local/lib 
    make 
    make install 
    
  6. 生成证书Key

    初始化 PKI

    (如果没有 export 命令也可以用 setenv [name] [value] 命令)

    代码:

    cd /openvpn-2.0.5/easy-rsa 
    export D=`pwd` 
    export KEY_CONFIG=$D/openssl.cnf 
    export KEY_DIR=$D/keys 
    export KEY_SIZE=1024 
    export KEY_COUNTRY=CN 
    export KEY_PROVINCE=GD 
    export KEY_CITY=SZ 
    export KEY_ORG="dvdmaster" 
    export KEY_EMAIL="support@cooldvd.com" 
    Build:

    代码:

    ./clean-all 
    ./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) [GD]: 
    Locality Name (eg, city) [SZ]: 
    Organization Name (eg, company) [dvdmaster]: 
    Organizational Unit Name (eg, section) []:dvdmaster 
    Common Name (eg, your name or your server's hostname) []:server 
    Email Address [support@cooldvd.com]: 
    # 建立 server key 代码: 代码:
    ./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) [GD]: 
    Locality Name (eg, city) [SZ]: 
    Organization Name (eg, company) [dvdmaster]: 
    Organizational Unit Name (eg, section) []:dvdmaster 
    Common Name (eg, your name or your server's hostname) []:server 
    Email Address [support@cooldvd.com]: 
    
    Please enter the following 'extra' attributes 
    to be sent with your certificate request 
    A challenge password []:abcd1234 
    An optional company name []:dvdmaster 
    Using configuration from /openvpn-2.0.5/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:'GD' 
    localityName          :PRINTABLE:'SZ' 
    organizationName      :PRINTABLE:'dvdmaster' 
    organizationalUnitName:PRINTABLE:'dvdmaster' 
    commonName            :PRINTABLE:'server' 
    emailAddress          :IA5STRING:'support@cooldvd.com' 
    Certificate is to be certified until Mar 19 08:15:31 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 

    #生成客户端 key

    代码:

    ./build-key client1 
    Generating a 1024 bit RSA private key 
    .....++++++ 
    ......++++++ 
    writing new private key to 'client1.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) [GD]: 
    Locality Name (eg, city) [SZ]: 
    Organization Name (eg, company) [dvdmaster]: 
    Organizational Unit Name (eg, section) []:dvdmaster 
    Common Name (eg, your name or your server's hostname) []:client1    #重要: 每个不同的 client 生成的证书, 名字必须不同. 
    Email Address [support@cooldvd.com]: 
    
    Please enter the following 'extra' attributes 
    to be sent with your certificate request 
    A challenge password []:abcd1234 
    An optional company name []:dvdmaster 
    Using configuration from /openvpn-2.0.5/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:'GD' 
    localityName          :PRINTABLE:'SZ' 
    organizationName      :PRINTABLE:'dvdmaster' 
    organizationalUnitName:PRINTABLE:'dvdmaster' 
    commonName            :PRINTABLE:'client1' 
    emailAddress          :IA5STRING:'support@cooldvd.com' 
    Certificate is to be certified until Mar 19 08:22:00 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 

    依次类推生成其他客户端证书/key

    代码:

    ./build-key client2 
    ./build-key client3 
    注意在进入 Common Name (eg, your name or your server's hostname) []: 的输入时, 每个证书输入的名字必须不同.
  7. build: 代码:
    
    ./build-dh 
  8. 将 keys 下的所有文件打包下载到本地

    代码:

    tar -cf mykeys.tar /openvpn-2.0.5/easy-rsa/keys 
    cp mykeys.tar /home/dvdmastersys/public_html/mykeys.tar 
    将 mykeys.tar 移到 web public(绝对路径因人而异) 上, 然后用 http://www.a.com/mykeys.tar 方式将其下载到本地保存, 然后将其从server删除: 代码:
    rm /home/dvdmastersys/public_html/mykeys.tar 
    也可以用其他方法把 key file搞到本地,例如 ftp.
  9. 创建服务端配置文件

    从样例文件创建:

    代码:

    cd $dir/sample-config-files/ # 进入源代码解压目录下的sample-config-files子目录 
    cp server.conf /usr/local/etc  # cp服务器配置文件到/usr/local/etc 
    vi /usr/local/etc/server.conf 
    我建立的server.conf 的内容稍后另附.
  10. 创建客户端配置文件

    代码:

    cd $dir/sample-config-files/  #进入源代码解压目录下的sample-config-files子目录 
    cp client.conf /usr/local/etc  #cp客户端配置文件到/usr/local/etc 
    vi /usr/local/etc/client.conf 
    我建立的client.conf 的内容稍后另附.
  11. 启动Openvpn: openvpn [server config file] 代码:
    /usr/local/sbin/openvpn --config /usr/local/etc/server.conf 

三. OpenVPN GUI For Windows 客户端安装过程

  1. 安装 OpenVPN GUI For Windows, 到 http://openvpn.se 下载. 目前的版本是 1.0.3. 注意: OpenVPN GUI 的版本要和 OpenVPN Server 的版本配套. 详见第一节一. 安装环境中的说明.
  2. 依屏幕指示安装openvpn gui.
  3. 配置 openvpn gui

    安装结束后, 进入安装文件夹下的 config 目录, 然后将上面第 10 步建立的 client.conf 文件从 server 上下载到此文件夹, 并更名为 client.ovpn

    同时, 将第8 步打包的 mykeys.tar 中的下列证书文件解压到此文件夹:

    代码:

    ca.crt 
    ca.key 
    client1.crt 
    client1.csr 
    client1.key 
    然后双击 client.ovpn 即可启动 openvpn, 或者通过 OpenVPN GUI 的控制启动 VPN.

    如果双击 client.ovpn 没有反应, 则在任务栏点 OpenVPN GUI 的小图标右键, 选择 edit config, 将内容复制过去再保存. 然后再点右键中的 connect即可.

    如果需要第二台机器上使用 vpn , 进行同样的配置, 只需要将 client1.crt, client1.csr, client1.key 换成对应的 client2.xxx 即可, 然后将 client.ovpn 中的对应key文件值改掉.

四. OpenVPN 配置样例文件

  1. OpenVPN 服务端:server.conf

    代码:

    local 70.8.7.6 
    port 1194 
    proto udp 
    
    dev tun 
    
    ca /openvpn-2.0.5/easy-rsa/keys/ca.crt 
    cert /openvpn-2.0.5/easy-rsa/keys/server.crt 
    key /openvpn-2.0.5/easy-rsa/keys/server.key  # This file should be kept secret 
    dh /openvpn-2.0.5/easy-rsa/keys/dh1024.pem 
    
    server 10.8.0.0 255.255.255.0 
    
    client-to-client 
    keepalive 10 120 
    
    comp-lzo 
    
    persist-key 
    persist-tun 
    status /openvpn-2.0.5/easy-rsa/keys/openvpn-status.log 
    verb 4 
    
    push "dhcp-option DNS 10.8.0.1" 
    push "dhcp-option DNS 70.88.98.10"  # name server 地址, 如何获取见随后说明 
    push "dhcp-option DNS 70.88.99.11"  # name server 地址, 如何获取见随后说明 
    说明: 有些 domain 被 GFW 封掉了, 这时, 如果要访问这些网站, 应该将 server 上的 DNS push 到 client. 上面示例中的 dns ip: 70.88.98.10, 70.88.99.10, 可以在 /etc/resolv.conf 中找到: 代码:
    vi /etc/resolv.conf 
    nameserver   70.88.98.10 
    nameserver   70.88.99.11 
  2. OpenVPN 客户端: client.ovpn

    代码:

    client 
    
    dev tun 
    proto udp 
    
    remote 70.8.7.6 1194 
    
    persist-key 
    persist-tun 
    ca ca.crt 
    cert client1.crt 
    key client1.key 
    ns-cert-type server 
    comp-lzo 
    verb 3 
    
    redirect-gateway def1 

五. OpenVPN 访问外网的设置

  1. 打开路由 VPN连接成功后, 还需要设置路由, 才能透过VPN访问Internet. 在 linux host 上添加路由: 代码:
    iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 70.8.7.6 
    /etc/init.d/iptables save 
    /etc/init.d/iptables restart 
    不同的机器,-o eth0 参数可能不一样,具体可输入 ifconfig 查看,搞清 ip(70.8.7.6)所在的网卡号.

    同时, 需要将 ip forward 打开. 不要用 echo 1 > /proc/sys/net/ipv4/ip_forward 的方式, 这种方式重启后无效. 先查看一下:

    代码:

    
    sysctl -a | grep for 
    #查看结果: 
    net.ipv4.conf.tun0.mc_forwarding = 0 
    net.ipv4.conf.tun0.forwarding = 1 
    net.ipv4.conf.eth0.mc_forwarding = 0 
    net.ipv4.conf.eth0.forwarding = 1 
    net.ipv4.conf.lo.mc_forwarding = 0 
    net.ipv4.conf.lo.forwarding = 1 
    net.ipv4.conf.default.mc_forwarding = 0 
    net.ipv4.conf.default.forwarding = 1 
    net.ipv4.conf.all.mc_forwarding = 0 
    net.ipv4.conf.all.forwarding = 1 
    net.ipv4.ip_forward = 1 
    如果你的主机上列数值不是为1, 则要将其改成1, 例如:

    代码:

    sysctl -w net.ipv4.ip_forward=1 
    依此类推.
  2. 开启域名服务器

    如果你需要访问一些已经被GFW封掉了域名的网站, 但你的 OpenVPN 服务器没有被封的话,那么你需要在你的主机上开启 name server, 并将 dns push 给 client。 一般的独立主机, 都带有 private dns server.

    代码:

    rpm -qa | grep bind 
    /etc/init.d/named start 
    另外, 必须保证 server.conf 配置中, 有这三个配置:

    代码:

    push "dhcp-option DNS 10.8.0.1" 
    push "dhcp-option DNS 70.88.98.10"  # name server 地址 
    push "dhcp-option DNS 70.88.99.11"  # name server 地址 
    当 client 连接成功后, 在 cmd 下执行 ipconfig /all, 应该有这类似这样的输出:

    代码:

    Ethernet adapter Local Area Connection 3: 
            Connection-specific DNS Suffix  . : 
            Description . . . . . . . . . . . : TAP-Win32 Adapter V8 
            Physical Address. . . . . . . . . : 00-FF-AA-B0-60-2B 
            Dhcp Enabled. . . . . . . . . . . : Yes 
            Autoconfiguration Enabled . . . . : Yes 
            IP Address. . . . . . . . . . . . : 10.8.0.6 
            Subnet Mask . . . . . . . . . . . : 255.255.255.252 
            Default Gateway . . . . . . . . . : 10.8.0.5 
            DHCP Server . . . . . . . . . . . : 10.8.0.5 
            DNS Servers . . . . . . . . . . . : 10.8.0.1 
                                                70.88.98.10 
                                                70.88.99.11 
            Lease Obtained. . . . . . . . . . : 2006年5月25日 5:13:52 
            Lease Expires . . . . . . . . . . : 2007年5月25日 5:13:52 

六. 设置 OpenVPN 服务器 reboot后自动启动 openvpn

执行命令:

代码:

vi /etc/rc.local 
然后在最后面加入此行:

代码:

/usr/local/sbin/openvpn --config /usr/local/etc/server.conf > /dev/null 2>&1 & 

七. OpenVPN 测试

你可以用 VPN 登录上去之后, 测试 MSN, QQ, IE 等网络应用, 也可以尝试访问一些被 GFW 禁掉的网站, 当然, 前提是你的 VPN 服务器不在境内.

八. 使用 OpenVPN 的强烈注意事项

不建议用 VPN 登录 paypal 帐户和 google adsense 帐户. 否则有可能导致帐户受限或带来其他风险.

相关文章:

如何在 Linux OpenVPN 服务端吊销(revoke) 客户端证书?

Tags: VPN | Linux | OpenVPN | DNS


 文章评论


第 1 楼  Rony 发表于 2007-06-28 12:23
很详细。 非常感谢。

第 2 楼  拉拉 发表于 2008-09-10 11:48
谢谢

第 3 楼  flintt 发表于 2008-09-12 21:47
启动openvpn的终端关闭后,好像sever端停止了vpn的服务

第 4 楼  rrt 发表于 2008-09-19 17:23
明显有硬伤,我只问一句,lz你自己严格按照你的文档做了没有。

结果怎么样?


我很怀疑你的iptables的nat设置。
XiaoHui 回复于 2008-09-19 19:37 :
如果有错误,还请麻烦指出。:)

有时候我记不清设置,都是直接看这篇笔记来做的。我按这个文档,装了不下十台 VPN SERVER了。

第 5 楼  gniudad 发表于 2008-11-07 09:21
不错,感谢。
我也按这个文档装了不下10台了。哈哈。
只是文中:如果你的主机上列数值不是为1, 则要将其改成1, 例如:

代码:

sysctl -w net.ipv4.ip_forward=1

依此类推.
我以为全部要改成1,但好像只要最后一项改1就行了。

第 6 楼  tt 发表于 2008-12-12 10:01
为什么我在做这一步# 建立 server key 代码: 代码: ./build-key-server server
的时候出错:error loading extension section server,请指教。
XiaoHui 回复于 2008-12-15 14:34 :

抱歉,今天才看到你的邮件。

我没有遇到过这个错误。你确认你的环境变量、软件版本、目录设置,都是按我说的来做的吗?

刚才在GOOGLE搜索了一下,你看看这里:

http://episteme.arstechnica.com/eve/forums/a/tpc/f/96509133/m/732009283831

注意最后的一个贴子,他说他解决了这个问题。你看看对你有用没。


第 7 楼  marion 发表于 2008-12-25 11:00
搞多公钥-私钥对有什么必要?
为什么不用 duplicate-cn?

第 8 楼  zengw 发表于 2009-01-16 14:08
我做到这一步:
cd /openvpn-2.0.5/easy-rsa
export D=`pwd`
export KEY_CONFIG=$D/openssl.cnf
export KEY_DIR=$D/keys
export KEY_SIZE=1024
export KEY_COUNTRY=CN
export KEY_PROVINCE=GD
export KEY_CITY=SZ
export KEY_ORG="dvdmaster"
export KEY_EMAIL="support@cooldvd.com"
./clean-all
后显示
mkdir:无法创建目录'pwd/keys': 没有那个文件或目录
XiaoHui 回复于 2009-01-17 19:12 :
你所使用的 OPENVPN,版本号是多少?

第 9 楼  zengw 发表于 2009-01-18 11:33
OPENvpn 是2.0.9的,LZO是2.02的,Linux是redhat9的,内核为2.4.20;虚拟机是5.5.1版本的;
XiaoHui 回复于 2009-01-18 12:21 :
你尝试自己先手工把那几个目录建好看看。我没折腾过 OpenVPN 2.0.9。直接用文中的步骤安装 2.0.5 是没有问题的。

第 10 楼  zengw 发表于 2009-01-18 11:42
以下是我的操作跟出错代码:
[root@localhost openvpn-2.0.9]# cd easy-rsa/
[root@localhost easy-rsa]# ls
2.0 build-key build-req make-crl revoke-crt Windows
build-ca build-key-pass build-req-pass openssl.cnf revoke-full
build-dh build-key-pkcs12 clean-all pwd sign-req
build-inter build-key-server list-crl README vars
[root@localhost easy-rsa]# pwd
/openvpn-2.0.9/easy-rsa
[root@localhost easy-rsa]# ./clean-all
you must define KEY_DIR
[root@localhost easy-rsa]# export D='pwd'
[root@localhost easy-rsa]# export KEY_CONFIG=$D/openssl.cnf
[root@localhost easy-rsa]# export KEY_DIR=$D/keys
[root@localhost easy-rsa]# export KEY_SIZE=1024
[root@localhost easy-rsa]# export KEY_COUNTRY=CN
[root@localhost easy-rsa]# export KEY_PROVINCE=GD
[root@localhost easy-rsa]# export KEY_CITY=SZ
[root@localhost easy-rsa]# export KEY_ORG="dvdmaster"
[root@localhost easy-rsa]# export KEY_EMAIL="support@cooldvd.com"
[root@localhost easy-rsa]# ./vars
NOTE: when you run ./clean-all, I will be doing a rm -rf on pwd/keys
[root@localhost easy-rsa]# ./clean-all
[root@localhost easy-rsa]# ./build-ca
error on line -1 of pwd/openssl.cnf
1984:error:02001002:system library:fopen:No such file or directory:bss_file.c:104:fopen('pwd/openssl.cnf','rb')
1984:error:2006D080:BIO routines:BIO_new_file:no such file:bss_file.c:107:
1984:error:0E064072:configuration file routines:CONF_load:no such file:conf_def.c:197:[root@localhost easy-rsa]#

第 11 楼  zengw 发表于 2009-01-19 10:15
能给我发一个openvpn2.0.5的安装包吗?网上找不到了
XiaoHui 回复于 2009-01-20 15:07 :
http://openvpn.net/release/

第 12 楼  zengw 发表于 2009-01-20 17:06
问题已经得到解决,TKS!

第 13 楼  harley_chen 发表于 2009-02-05 04:54
iptables 的ip伪装 我也设置了, 可是 vpn连接后, 还是没办法上网,不能ping外网...

nat功能也开了...

没用

第 14 楼  zengw 发表于 2009-02-10 11:39
没做/etc/init.d/named start 这一步,完成后我用Windows vpn客户端拨号到vmware上去成功了并能上网,但是公司另一台PC拨号拨上去后却不能上网,其获得的IP和DNS均正常!请问是不是跟没做/etc/init.d/named start 这一步有关,但是跟vmware同一台PC上的Windows却可以上网!

第 15 楼  ks 发表于 2009-02-20 20:12
我用freebsd和windowsxp,都已经配置安装完毕,客户端也分配到ip,但是互相之间却无法ping通
我已经在server端的配置文件中配置了local的地址,server端的ifconfig显示如下
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1500
inet 192.168.10.1 --> 192.168.10.2 netmask 0xffffffff
在server端本机ping 192.168.10.1也ping不通
client端ipconfig 显示的ip正常 只是没有网关
请问是什么原因
XiaoHui 回复于 2009-02-21 00:02 :
你本地局域网的 IP 段是多少?是不是SERVER指定的IP段,与本地局域网指定的相冲突?

第 16 楼  poppy 发表于 2009-02-25 21:09
我在安装Openvpn的过程中,出现了这么个问题:
#modprobe tun
FATAL: Could not load /lib/modules/2.6.18-ovz028stab053.5-smp/modules.dep: No such file or directory

而且/lib/modules/下面是空的。。
我检查了下
# lsmod
Module Size Used by
没有tun设备~~
# modinfo tun
modinfo: could not open /lib/modules/2.6.18-ovz028stab053.5-smp/modules.dep

郁闷了。。是系统没有加载tun设备呢? 还是我哪个地方要开启tun设备?
怎么解决这个tun设备的问题啊。。谢谢了

第 17 楼  kingstar 发表于 2009-02-25 22:39
看了这篇文章之后才装的 OPENVPN,稳妥起见,下载的 OPENVPN 版本正是楼主例文中的 2.0.5。

我在 theplanet 的主机上安装成功。终于破墙了。

感谢XH。

第 18 楼  SanGe 发表于 2009-03-29 12:31
才看到。我也顶一下。:)

第 19 楼  FlyFire 发表于 2009-03-29 22:44
XiaoHui 是不是写了个 HOOK,将网站文章的评论 和 论坛回贴,同步了?

我看见论坛里好多回贴的都标着“通过 XiaoHui.com 评论系统发表”。:)

第 20 楼  XiaoHui 发表于 2009-03-29 23:28
原帖由 FlyFire 于 2009-3-29 21:44 发表
XiaoHui 是不是写了个 HOOK,将网站文章的评论 和 论坛回贴,同步了?

我看见论坛里好多回贴的都标着“通过 XiaoHui.com 评论系统发表”。:)


点头。我做了一个关联。如果论坛上讨论的话题,是我网站上发表的文章,就建立关联。然后用定时程序,将网站的评论和论坛的回贴进行同步。

第 21 楼  王菲菲 发表于 2009-05-06 09:53
成功了到底是一种什么情况。我是第一次用linux,第一次设置VPN。谢谢!怎么测试他的成功。
XiaoHui 回复于 2009-05-08 18:27 :
连接成功后,任务栏图标区的 OPENVPN GUI的 ICON, 会由暗红色变成绿色。

第 22 楼  秋天的树 发表于 2009-05-20 23:46
感谢@_@!

第 23 楼  pan 发表于 2009-05-21 22:15
我的服务器跟客户机连接不上。我们电信网一个IP下有几个主机,而且IP是动态生成的,不知道是不是跟这个有关系?
XiaoHui 回复于 2009-05-22 11:56 :
你自己看日志记录,确保是连接到了正确的服务器上。

第 24 楼  liusir 发表于 2009-05-22 12:29
上面安装不成功的,可能是 OPENVPN 不同版本的问题引起的差异。我刚才严格按 XIAOHUI 文档里说的 OPENVPN版本进行了安装,一路绿灯,成功了。:)

第 25 楼  pan 发表于 2009-05-26 16:38
想在Windows下装个Redhat虚拟机,Redhat作服务器,Windows作客户机,但他们共用一个ip,而且ip是动态分配的,这样他们之间的openvpn能建立起来吗?
server.conf的local怎么写?
XiaoHui 回复于 2009-05-26 20:54 :
不懂,没试过。
虚拟机应该可以分配不同的IP的。

第 26 楼  luo 发表于 2009-05-29 12:29
请问openvpn如何把两个不同区域的局域局连成一个局域网,就是说,两个公司,不同城市,两台linux做点对点连接后,下面的客户端可以互通?

第 27 楼  luo 发表于 2009-05-29 16:59
按楼主的配置,winxp连接openvpn一直提示‘connecting to client has failed’,下面是客户端的日志。楼主帮我看看
Fri May 29 15:03:43 2009 OpenVPN 2.0.5 Win32-MinGW [SSL] [LZO] built on Nov 2 2005
Fri May 29 15:03:43 2009 IMPORTANT: OpenVPN's default port number is now 1194, based on an official port number assignment by IANA. OpenVPN 2.0-beta16 and earlier used 5000 as the default port.
Fri May 29 15:03:43 2009 LZO compression initialized
Fri May 29 15:03:43 2009 Control Channel MTU parms [ L:1544 D:140 EF:40 EB:0 ET:0 EL:0 ]
Fri May 29 15:03:43 2009 Data Channel MTU parms [ L:1544 D:1450 EF:44 EB:135 ET:0 EL:0 AF:3/1 ]
Fri May 29 15:03:43 2009 Local Options hash (VER=V4): '69109d17'
Fri May 29 15:03:43 2009 Expected Remote Options hash (VER=V4): 'c0103fa8'
Fri May 29 15:03:43 2009 Attempting to establish TCP connection with 192.168.1.222:1194
Fri May 29 15:03:43 2009 TCP connection established with 192.168.1.222:1194
Fri May 29 15:03:43 2009 TCPv4_CLIENT link local: [undef]
Fri May 29 15:03:43 2009 TCPv4_CLIENT link remote: 192.168.1.222:1194
Fri May 29 15:03:43 2009 TLS: Initial packet from 192.168.1.222:1194, sid=9e2dc9b0 29a67f10
Fri May 29 15:03:43 2009 VERIFY OK: depth=1, /C=CN/ST=GD/L=SZ/O=kemei/OU=kemei/CN=server/emailAddress=system-one@163.com
Fri May 29 15:03:43 2009 VERIFY OK: nsCertType=SERVER
Fri May 29 15:03:43 2009 VERIFY OK: depth=0, /C=CN/ST=GD/O=kemei/OU=kemei/CN=server/emailAddress=system-one@163.com
Fri May 29 15:03:43 2009 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri May 29 15:03:43 2009 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri May 29 15:03:43 2009 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri May 29 15:03:43 2009 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri May 29 15:03:43 2009 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Fri May 29 15:03:43 2009 [server] Peer Connection Initiated with 192.168.1.222:1194
Fri May 29 15:03:45 2009 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
Fri May 29 15:03:45 2009 PUSH: Received control message: 'PUSH_REPLY,dhcp-option DNS 10.8.0.1,route 10.8.0.0 255.255.255.0,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5'
Fri May 29 15:03:45 2009 OPTIONS IMPORT: timers and/or timeouts modified
Fri May 29 15:03:45 2009 OPTIONS IMPORT: --ifconfig/up options modified
Fri May 29 15:03:45 2009 OPTIONS IMPORT: route options modified
Fri May 29 15:03:45 2009 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Fri May 29 15:03:45 2009 There are no TAP-Win32 adapters on this system. You should be able to create a TAP-Win32 adapter by going to Start -> All Programs -> OpenVPN -> Add a new TAP-Win32 virtual ethernet adapter.
Fri May 29 15:03:45 2009 Exiting
XiaoHui 回复于 2009-05-30 00:05 :
>> Fri May 29 15:03:45 2009 There are no TAP-Win32 adapters on this system. You should be able to create a TAP-Win32 adapter by going to Start -> All Programs -> OpenVPN -> Add a new TAP-Win32 virtual ethernet adapter
看这句LOG, 貌似是你 TAP 的驱动没装上?

第 28 楼  luo 发表于 2009-05-30 12:21
上面那个问题我已经搞定了。原因是我下载了错误的for WIN版本导致虚拟网卡没有装上,但是现在又是有一问题就是我可以拔号上去了,但如何访问对方的局域网??目前这样我只能访问服务器那台,服务器或客户端还需要进行行怎么样的设置呢?

第 29 楼  xukai 发表于 2009-06-03 17:34
Wed Jun 03 13:40:30 2009 OpenVPN 2.0.5 Win32-MinGW [SSL] [LZO] built on Nov 2 2005
Wed Jun 03 13:40:30 2009 IMPORTANT: OpenVPN's default port number is now 1194, based on an official port number assignment by IANA. OpenVPN 2.0-beta16 and earlier used 5000 as the default port.
Wed Jun 03 13:40:30 2009 Cannot load certificate file xukai.crt: error:02001002:scd: error:20074002:BIO routines:FILE_CTRL:system lib: error:140AD002:SSL routines:SSL_CTX_use_certificate_file:system lib
Wed Jun 03 13:40:30 2009 Exiting
我按照楼主的做下来,连接的时候的报错,上面是log中的文件。
报错是connecting to client has failed.
XiaoHui 回复于 2009-06-03 18:10 :
证书的配置没有做对。

第 30 楼  xukai 发表于 2009-06-03 18:21
Wed Jun 03 16:10:32 2009 OpenVPN 2.0.5 Win32-MinGW [SSL] [LZO] built on Nov 2 2005
Wed Jun 03 16:10:32 2009 IMPORTANT: OpenVPN's default port number is now 1194, based on an official port number assignment by IANA. OpenVPN 2.0-beta16 and earlier used 5000 as the default port.
Wed Jun 03 16:10:32 2009 LZO compression initialized
Wed Jun 03 16:10:32 2009 Control Channel MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
Wed Jun 03 16:10:32 2009 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ]
Wed Jun 03 16:10:32 2009 Local Options hash (VER=V4): '41690919'
Wed Jun 03 16:10:32 2009 Expected Remote Options hash (VER=V4): '530fdded'
Wed Jun 03 16:10:32 2009 UDPv4 link local (bound): [undef]:1194
Wed Jun 03 16:10:32 2009 UDPv4 link remote: 192.168.242.144:1194
Wed Jun 03 16:10:32 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:34 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:37 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:38 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:40 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:42 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:45 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:47 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:50 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:52 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:55 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:56 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:10:58 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:01 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:03 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:06 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:08 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:11 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:13 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:15 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:17 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:19 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:21 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:24 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:25 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:27 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:29 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:31 2009 read UDPv4: Connection reset by peer (WSAECONNRESET) (code=10054)
Wed Jun 03 16:11:32 2009 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
Wed Jun 03 16:11:32 2009 TLS Error: TLS handshake failed
Wed Jun 03 16:11:32 2009 TCP/UDP: Closing socket
Wed Jun 03 16:11:32 2009 SIGUSR1[soft,tls-error] received, process restarting
Wed Jun 03 16:11:32 2009 Restart pause, 2 second(s)
上面的问题解决了,现在老这样了,请问怎么回事?
XiaoHui 回复于 2009-06-03 22:32 :

客户端与服务端的物理链接不通。确认 1194 端口是开的,客户端与服务端能够正常PING通。下面是 OPENVPN 官方解释,你自己对照排除一下:

You get the error message: TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity). This error indicates that the client was unable to establish a network connection with the server.

    Solutions:
  • Make sure the client is using the correct hostname/IP address and port number which will allow it to reach the OpenVPN server.
  • If the OpenVPN server machine is a single-NIC box inside a protected LAN, make sure you are using a correct port forward rule on the server's gateway firewall. For example, suppose your OpenVPN box is at 192.168.4.4 inside the firewall, listening for client connections on UDP port 1194. The NAT gateway servicing the 192.168.4.x subnet should have a port forward rule that says forward UDP port 1194 from my public IP address to 192.168.4.4.
  • Open up the server's firewall to allow incoming connections to UDP port 1194 (or whatever TCP/UDP port you have configured in the server config file).

第 31 楼  luo 发表于 2009-06-05 17:27
客户端连入服务端后。可以ping通服务端的lan wan tun ip,,但是连接服务端的lan同一交换下的电脑,有的可以连通,有的不行,,就比如127 77 5 212 这些IP都可以连通,其它IP又不能联通,不知道是什么原因,是因为路由的原因吗?获取的掩码是255.255.255.252,而且拔入后访问共享,比如访问77这台的默认共享c$,不需要提示输入用户和密码,直接就可以打开共享了,这我觉得有安全问题,这问xiaohui这是什么原因,怎么解决呀。
XiaoHui 回复于 2009-06-05 18:06 :
我装 VPN 只是为了穿墙,这种情况我不知道,没折腾过。不好意思。:)

共有评论 32 条, 显示 31 条。

发表你的评论
如果你想针对此文发表评论, 请填写下列表单:
姓名: * 必填
E-mail: 可选 (不会被公开)
网站 / Blog: 可选
反垃圾广告: 为了防止广告机器人自动发贴, 请计算下列表达式的值:
4 + 14 = * 必填
评论内容:
* 必填
你可以使用下列标签修饰文字:
[b] 文字 [/b]: 加粗文字
[quote] 文字 [/quote]: 引用文字

 

小辉程序员之路 建站于 1997 ◇ 做一名最好的开发者是我不变的理想……
Copyright(C) 1997-2009 XiaoHui.com   All rights reserved
声明:站内所有原创文字,未经许可,均可转载、复制。
转载时必须以链接形式注明作者和原始出处