差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
zh:实际案例指导:如何搭建基于astercc系统的openvpn [2015/06/03 03:14] liuxlzh:实际案例指导:如何搭建基于astercc系统的openvpn [2016/01/18 02:08] (当前版本) – [第三步:创建服务端证书及key] liuxl
行 105: 行 105:
 再创建服务器端证书,输入Common Name: 再创建服务器端证书,输入Common Name:
 <code> ./easyrsa gen-req server nopass </code> <code> ./easyrsa gen-req server nopass </code>
-<code> [root@astercc1 easyrsa3]# ./easyrsa gen-req server nopass 
  
 +如下:
 +<code> [root@astercc1 easyrsa3]# ./easyrsa gen-req server nopass
 Note: using Easy-RSA configuration from: ./vars Note: using Easy-RSA configuration from: ./vars
 Generating a 2048 bit RSA private key Generating a 2048 bit RSA private key
行 130: 行 131:
 创建签约服务端证书: 创建签约服务端证书:
 <code> ./easyrsa sign server server </code> <code> ./easyrsa sign server server </code>
-<code> [root@astercc1 easyrsa3]# ./easyrsa sign server server 
  
 +如下:
 +<code> [root@astercc1 easyrsa3]# ./easyrsa sign server server
 Note: using Easy-RSA configuration from: ./vars Note: using Easy-RSA configuration from: ./vars
  
行 151: 行 153:
 Signature ok Signature ok
 The Subject's Distinguished Name is as follows The Subject's Distinguished Name is as follows
-commonName            :PRINTABLE:'server'+commonName           :PRINTABLE:'server'
 Certificate is to be certified until May 30 05:45:15 2025 GMT (3650 days) Certificate is to be certified until May 30 05:45:15 2025 GMT (3650 days)
  
行 165: 行 167:
 <code> ./easyrsa gen-dh </code> <code> ./easyrsa gen-dh </code>
  
 +如下:
 +<code> [root@astercc1 easyrsa3]# ./easyrsa gen-dh
 +Note: using Easy-RSA configuration from: ./vars
 +Generating DH parameters, 2048 bit long safe prime, generator 2
 +This is going to take a long time
 +............+...............................................
 +...........................................................................
 +.....................................................................................
 +..............................................................+............................
 +......................................+...............+.....................++*++*
 +
 +DH parameters of size 2048 created at /etc/openvpn/easy-rsa/easyrsa3/pki/dh.pem 
 +</code>
  
  
行 170: 行 185:
 =====第四步:创建客户端证书===== =====第四步:创建客户端证书=====
  
-首先,进入root目录新建client文件夹,文件夹可随意命名,然后拷贝前面解压得到的easy-ras文件夹到client文件夹,进入下列目录:+首先,进入root目录新建client文件夹,文件夹可随意命名,然后拷贝前面解压得到的easy-rsa文件夹到client文件夹,并进入到/root/client/easy-rsa/easyrsa3/ 目录:
 <code> cd /root/ <code> cd /root/
- mkdir client             //&& cd client+ mkdir client
  cp -R /etc/easy-rsa/ client/  cp -R /etc/easy-rsa/ client/
- cd client/easy-rsa/easyrsa3/ </code> + cd client/easy-rsa/easyrsa3/  
 +</code>
  
  
行 181: 行 196:
 <code> ./easyrsa init-pki </code> <code> ./easyrsa init-pki </code>
  
 +如下:
 +<code>
 +[root@astercc1 easyrsa3]# ./easyrsa  init-pki
  
 +init-pki complete; you may now create a CA or requests.
 +Your newly created PKI dir is: /root/client/easy-rsa/easyrsa3/pki 
 +</code>
  
 +再创建客户端key及生成证书(记住生成时自己输入的密码):
 +<code> ./easyrsa gen-req client1    //名字是自己定义的 </code>
  
-再创建客户端key及生成证书(记住生成是自己输入的密码): +如下: 
-<code> ./easyrsa gen-req andy  //名字是自己定义的 </code>+<code> [root@astercc1 easyrsa3]# ./easyrsa  gen-req  client1 
 +Generating a 2048 bit RSA private key 
 +...............+++ 
 +............................+++ 
 +writing new private key to '/root/client/easy-rsa/easyrsa3/pki/private/client1.key' 
 +Enter PEM pass phrase: 
 +Verifying - Enter PEM pass phrase: 
 +----- 
 +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. 
 +----- 
 +Common Name (eg: your user, host, or server name) [client1]:
  
 +Keypair and certificate request completed. Your files are:
 +req: /root/client/easy-rsa/easyrsa3/pki/reqs/client1.req
 +key: /root/client/easy-rsa/easyrsa3/pki/private/client1.key 
 +</code>
  
  
-然后再将得到的andy.req导入然后签约证书:+然后再将得到的client1.req导入然后签约证书:
  
 a.进入到/etc/openvpn/easy-rsa/easyrsa3/ a.进入到/etc/openvpn/easy-rsa/easyrsa3/
- +<code> cd /etc/openvpn/easy-rsa/easyrsa3/ </code>
-  <code> cd /etc/openvpn/easy-rsa/easyrsa3/ </code>+
  
 b.导入req b.导入req
 +<code> ./easyrsa import-req /root/client/easy-rsa/easyrsa3/pki/reqs/client1.req client1 </code>
  
-  <code> ./easyrsa import-req /root/client/easy-rsa/easyrsa3/pki/reqs/andy.req andy </code>+如下: 
 +<code> 
 +[root@astercc1 easyrsa3]# cd  /etc/openvpn/easy-rsa/easyrsa3/ 
 +[root@astercc1 easyrsa3]# 
 +[root@astercc1 easyrsa3]# 
 +[root@astercc1 easyrsa3]# ./easyrsa import-req /root/client/easy-rsa/easyrsa3/pki/reqs/client1.req client1 
 + 
 +Note: using Easy-RSA configuration from: ./vars 
 + 
 +The request has been successfully imported with a short name of: client1 
 +You may now use this name to perform signing operations on this request.  
 +</code>
  
 c.签约证书 c.签约证书
 +<code> ./easyrsa sign client client1 </code>
  
-  <code> ./easyrsa sign client andy </code>+如下: 
 +<code> [root@astercc1 easyrsa3]# ./easyrsa sign client client1
  
 +Note: using Easy-RSA configuration from: ./vars
  
 +You are about to sign the following certificate.
 +Please check over the details shown below for accuracy. Note that this request
 +has not been cryptographically verified. Please be sure it came from a trusted
 +source or that you have verified the request checksum with the sender.
  
-这里生成client,所以必须为client,andy要与之前导入名字一致。上面签约证书跟server类似,就不截图了,但是期间还是要输入CA的密。 +Request subject, to be signed as a client certificate for 3650 days:
  
 +subject=
 +    commonName              =  client1
  
-最后这一步很重要,现在说一下我们上面都生成了什么东西+Type the word 'yes' to continue, or any other input to abort. 
 +  Confirm request details: yes 
 +Using configuration from /etc/openvpn/easy-rsa/easyrsa3/openssl-1.0.cnf 
 +Enter pass phrase for /etc/openvpn/easy-rsa/easyrsa3/pki/private/ca.key: 
 +Check that the request matches the signature 
 +Signature ok 
 +The Subject's Distinguished Name is as follows 
 +commonName            :PRINTABLE:'client1' 
 +Certificate is to be certified until May 30 06:14:04 2025 GMT (3650 days)
  
-服务端:(/etc/openvpn/easy-rsa 文件夹)+Write out database with 1 new entries 
 +Data Base Updated
  
-    /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt +Certificate created at: /etc/openvpn/easy-rsa/easyrsa3/pki/issued/client1.crt  
-    /etc/openvpn/easy-rsa/easyrsa3/pki/reqs/server.req +</code>
-    /etc/openvpn/easy-rsa/easyrsa3/pki/reqs/andy.req +
-    /etc/openvpn/easy-rsa/easyrsa3/pki/private/ca.key +
-    /etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key +
-    /etc/openvpn/easy-rsa/easyrsa3/pki/issued/server.crt +
-    /etc/openvpn/easy-rsa/easyrsa3/pki/issued/andy.crt +
-    /etc/openvpn/easy-rsa/easyrsa3/pki/dh.pem+
  
-客户端:(/root/client/easy-rsa 文件夹) 
  
-    /root/client/easy-rsa/easyrsa3/pki/private/andy.key +里生成client,所以必须为client1,要与之前导入名字一致。上面签约证书跟server类似,但是期间还是要输入CA的密码。 
-    /root/client/easy-rsa/easyrsa3/pki/reqs/andy.req //个文件被我们导入到了服务端文件所以那里也有+
  
-a.这一步就是拷贝这些文件放入到相应位置。将下列文件放到/etc/openvpn/目录执行命令:+ 
 +最后看一下上面都生成了什么东西: 
 + 
 +服务端:(/etc/openvpn/easy-rsa/easyrsa3/ 文件夹) 
 + 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/reqs/server.req 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/reqs/client1.req 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/private/ca.key 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/issued/server.crt 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/issued/client1.crt 
 +  /etc/openvpn/easy-rsa/easyrsa3/pki/dh.pem 
 + 
 +客户端:(/root/client/easy-rsa/easyrsa3/ 文件夹) 
 + 
 +  /root/client/easy-rsa/easyrsa3/pki/private/andy.key 
 +  /root/client/easy-rsa/easyrsa3/pki/reqs/andy.req          //这个文件被我们导入到了服务端文件所以那里也有 
 + 
 +a.这一步就是拷贝这些文件放入到相应位置。将下列文件放到/etc/openvpn/ 目录下,执行命令:
  
 <code> cp /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /etc/openvpn <code> cp /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /etc/openvpn
  cp /etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key /etc/openvpn  cp /etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key /etc/openvpn
  cp /etc/openvpn/easy-rsa/easyrsa3/pki/issued/server.crt /etc/openvpn  cp /etc/openvpn/easy-rsa/easyrsa3/pki/issued/server.crt /etc/openvpn
- cp /etc/openvpn/easy-rsa/easyrsa3/pki/dh.pem /etc/openvpn </code>+ cp /etc/openvpn/easy-rsa/easyrsa3/pki/dh.pem /etc/openvpn  
 +</code>
  
 这样就将上述四个文件放入到了/etc/openvpn目录下。 这样就将上述四个文件放入到了/etc/openvpn目录下。
  
-b.这一步将下列文件放到/root/client目录下执行命令:+b.这一步将下列文件放到/root/client目录下执行命令:
  
-<code> cp /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /root/client+<code> 
 + cp /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /root/client
  cp /etc/openvpn/easy-rsa/easyrsa3/pki/issued/andy.crt /root/client  cp /etc/openvpn/easy-rsa/easyrsa3/pki/issued/andy.crt /root/client
- cp /root/client/easy-rsa/easyrsa3/pki/private/andy.key /root/client </code> + cp /root/client/easy-rsa/easyrsa3/pki/private/andy.key /root/client  
- +</code>
-这样就将上述三个文件复制到了/root/client目录,包括:ca.crt、andy.crt、andy.key +
- +
  
 +这样就将上述三个文件复制到了/root/client目录下,包括:ca.crt、andy.crt、andy.key
  
  
行 251: 行 333:
  
 当你安装好了openvpn时候,他会提供一个server配置的文件例子,在 /usr/share/doc/openvpn-2.3.6/sample/sample-config-files 下会有一个server.conf文件,我们将这个文件复制到/etc/openvpn 当你安装好了openvpn时候,他会提供一个server配置的文件例子,在 /usr/share/doc/openvpn-2.3.6/sample/sample-config-files 下会有一个server.conf文件,我们将这个文件复制到/etc/openvpn
- 
 <code> cp /usr/share/doc/openvpn-2.3.6/sample/sample-config-files/server.conf /etc/openvpn </code> <code> cp /usr/share/doc/openvpn-2.3.6/sample/sample-config-files/server.conf /etc/openvpn </code>
  
-然后修改配置 vi server.conf,如下: +然后修改配置 vi server.conf
-<code> local 192.168.1.178(跟自己vps IP一致) +
- port 1194 +
- dev tun +
- proto udp +
- ca /etc/openvpn/ca.crt +
- cert /etc/openvpn/server.crt +
- key /etc/openvpn/server.key   # This file should be kept secret +
- dh /etc/openvpn/dh.pem +
- server 10.8.0.0 255.255.255.0   ?????   #假如不行,改写成服务端的192.168.1.219地址试一下 +
- ifconfig-pool-persist ipp.txt +
- push "redirect-gateway def1 bypass-dhcp"   #网关重定向 +
- push "dhcp-option DNS 8.8.8.8" +
- keepalive 10 120 +
- comp-lzo +
- max-clients 100 +
- persist-key +
- persist-tun +
- status openvpn-status.log +
- verb 3 </code>+
  
-每个项目都会由一大堆介绍。上述修改,openvpn提供的server.conf已经全部提供,我们只需要去掉前面的注释 #(或;),然后修改我们自己的有关配置。+如下:
  
 +<code> 
 +local  a.b.c.d   (可不写)
 +port 1194  (端口号,可以自行定义,但定义完要在centos的 /etc/sysconfig/iptables 中加入端口语句,如:-A INPUT -p udp --dport 1194 -j ACCEPT,或者执行一条开启命令,但不加到iptables文件中:iptables -A INPUT -p udp --dport 1194 -j ACCEPT)
 +proto udp       # 服务器端 和 客户端的设置要一致    
 +dev tun       # 服务器端 和 客户端的设置要一致
 +ca /etc/openvpn/ca.crt
 +cert /etc/openvpn/server.crt
 +key /etc/openvpn/server.key       # This file should be kept secret
 +dh /etc/openvpn/dh.pem      # 以上4个均使用绝对路径
 +server 10.8.0.0 255.255.255.0     # 虚拟出来一个内部网段,用来VPN的
 +ifconfig-pool-persist ipp.txt
 +push "redirect-gateway def1 bypass-dhcp"    # 网关重定向
 +push "dhcp-option DNS 8.8.8.8"
 +keepalive 10 120
 +comp-lzo    # 对数据传输进行压缩的参数,两端配置要一致
 +max-clients 100  # 最大客户端数,可以不写
 +persist-key
 +persist-tun
 +status /etc/openvpn/openvpn-status.log
 +log /etc/openvpn/openvpn.log
 +log-append  /etc/openvpn/openvpn.log
 +verb 4 
 +</code>
 +每个项目都会由一大堆介绍。上述修改,openvpn提供的server.conf已经全部提供,我们只需要去掉前面的注释 #(或;),然后修改成我们自己的有关配置。
  
-??开启系统转发功能?? +开启 IP转发 和 NAT转发 功能: 
- +<code> vim /etc/sysctl.conf </code> 
-[root@vpn ~]# vim /etc/sysctl.conf net.ipv4.ip_forward = 0 改成 net.ipv4.ip_forward = 1  +net.ipv4.ip_forward = 0 改成 net.ipv4.ip_forward = 1  
-[root@vpn ~]# sysctl -p  +<code> sysctl -p </code> 
-[root@vpn ~]# sysctl -a | grep net.ipv4.ip_forward net.ipv4.ip_forward = 1 +<code> iptables -t nat -A  POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to 8.38.33.10 </code>
- +
-??封装出去的数据包(eth0是你的vps外网的网卡)??: +
- +
-/sbin/iptables -t nat -POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth0 -j MASQUERADE+
  
- 
- 
- 
- 
- 
- 
  
 =====第六步:下载openvpn客户端,并进行配置===== =====第六步:下载openvpn客户端,并进行配置=====
 +首先,将VPS生成的 客户端证书和key文件(即:ca.crt  client1.crt  client1.key)下载到客户端电脑:
 +其次,去官网 https://openvpn.net/,下载并安装openvpn-2.3.6客户端。在安装目录 D:\Program Files\OpenVPN\sample-config 中找到 client.ovpn 文件,并将其复制到D:\Program Files\OpenVPN\config 下面
 +然后,对客户端进行配置,编辑 client.ovpn 文件。
  
- +如下: 
- +<code> client 
- +dev tun            # 服务器端 和 客户端的设置要一致 
 +proto udp          # 服务器端 和 客户端的设置要一致 
 +remote 8.38.33.10  1194         # 这里IP是VPS的外网IP 和端口号 
 +resolv-retry infinite 
 +nobind 
 +persist-key 
 +persist-tun 
 +ca ca.crt             # 这里需要生成的CA证书,也可以注释掉这一行,用<ca>  </ca>将ca文件的内容全部嵌入进来 
 +cert client1.crt 
 +key client1.key 
 +comp-lzo 
 +verb 3 </code>
  
  
 =====第七步:测试排错===== =====第七步:测试排错=====
  
 +a.启动VPS上的OpenVPN服务,执行以下命令:
 +<code> service openvpn start </code>
 +如果出现:service start failed!! 运行 openvpn /etc/openvpn/server.conf 又可以运行,那么请试图删除/etc/openvpn/下的ipp.txt 和 openvpn-status.log后,再重新启动OpenVPN。
  
- +b.启动客户端 
- +以管理员身份来运行OpenVPN-GUI启动,注意在启动后需要输入创建client1.key时候密码,然后进入连接的界面。假如连接失败,请先把VPS的iptables停掉,执行如下命令,然后再连接: 
-{{:zh:实际案例指导:win7上openvpn.jpg?700|}} +<code> service iptables stop </code>
- +
- +
- +
- +
- +
-<code>  </code> +
- +
- +
- +
- +
- +
  
  
zh/实际案例指导/如何搭建基于astercc系统的openvpn.1433301271.txt.gz · 最后更改: (外部编辑)
Recent changes RSS feed Debian Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki