|
|
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install
6 W: n+ P; g# c; X1.1. 下载安装; G: |3 ]: o5 i& U$ ^
- # git clone https://github.com/guoew/openvpn-install.git
6 J2 z* S Y+ `) t# X# r - # cd openvpn-install && bash openvpn-install.sh! B. e5 Q% y3 m+ _
- Welcome to this OpenVPN "road warrior" installer!
, z; Z- [$ t H- Z; z - 8 C* Z7 b% U2 Z4 m% o. L' u. A' D) n
- I need to ask you a few questions before starting the setup.+ G; ]9 |5 s- \2 j7 W
- You can leave the default options and just press enter if you are ok with them.
1 k% x+ O' ]" T" C) f t
3 R2 j/ I% p1 `- First, provide the IPv4 address of the network interface you want OpenVPN6 G% Z( S) v. V9 ~
- listening to.
+ @. r$ N; C% p+ c& C - IP address: 172.27.0.2 #默认获取本机ip,直接回车 |6 j7 p( v, z7 r k$ \( _
: D, ^* [% z l/ ?" x! t) i' t6 k$ u- This server is behind NAT. What is the public IPv4 address or hostname?
3 B8 t2 a) ]( _5 R2 ? \! }7 R - Public IP address / hostname: 18.24.64.250 #输入主机公网ip
6 S& O/ u. H! u: l' q# c# D
/ ~5 R. I% o; H4 i- [% b2 I- Which protocol do you want for OpenVPN connections?
' f+ ^. g) z( C+ U+ T% Z - 1) UDP (recommended)
/ K# W, q* h, Y2 s2 o# d8 ^8 u - 2) TCP6 C+ w' B+ i- ?+ u. n' v. R
- Protocol [1-2]: 1 #选择连接协议
1 }& D# O: g3 m& k/ l5 R
$ T( y$ O9 V5 {* V- What port do you want OpenVPN listening to?* K/ K8 _7 z1 X+ a# E
- Port: 1194 #设置openvpn监听端口
/ @6 d# f; z/ U
* V2 r3 }4 X9 `- Which DNS do you want to use with the VPN?
" N$ ]9 v- ]" e; C3 j - 1) Current system resolvers7 ?; a ]& S b0 ~
- 2) 1.1.1.1
* R0 {0 j: ^0 i* p) D i - 3) Google2 b0 S) Y6 G; w1 c$ {8 W
- 4) OpenDNS
; E3 j! O) P: C - 5) Verisign
Y4 G- t0 ?3 r1 B - DNS [1-5]: 1 #选择DNS
( @. e C! O8 q" W9 @: x6 a - & V/ r( T1 I' C7 ~
- Finally, tell me your name for the client certificate./ N# }$ ^+ v( ?0 P4 s
- Please, use one word only, no special characters." {: }; b8 f% E/ W5 k
- Client name: client #设置客户端名称3 o) @4 B8 }. I: s* R& E
- ) W8 x* R0 h7 |9 X1 r& Y
- Okay, that was all I needed. We are ready to set up your OpenVPN server now.
& `. q" d9 F8 G, l1 e - Press any key to continue... #任意键继续+ X; ]9 `+ b. E; C' W
- ...2 x4 h, Y/ V" O) L/ `$ n' [) m# R
- An updated CRL has been created.6 G9 ^. e. Z$ H6 F. ~* u9 ?
- CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
8 B3 M* \. i [/ F# q' f) ]
9 y( Q& f4 S6 B; \8 C- Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.
) T4 D/ q) O# S- U9 r9 @% r+ V9 Q3 I - Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.
* o6 d, p( |" h% ]3 l# }2 L6 w - / B$ Q) s2 {' B7 Q$ ]+ s: v
- Finished! #最终看到Finished时表示安装完毕1 B8 k- H0 M9 h7 m/ T% _
- * ?" P; y; b" g& w0 ]
- Your client configuration is available at: /root/client.ovpn #客户端配置文件路径- x. @9 R% d: t5 b
- If you want to add more clients, you simply need to run this script again!
: e, ^% x+ t" X# w- m" q6 |; d2 L
复制代码 将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用- ~5 p! K5 o7 M+ a& S8 @2 T5 K/ ]) K
1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开
$ L3 E4 w; ?# f0 e0 Q5 W1 c- # cat /etc/openvpn/userfile.sh3 L6 u! g. X" q# p
- guoew guoew123% j9 V! r8 }& i1 S
- yakexi yakexi123. `8 L7 o% l- q; h# A, ^7 b
复制代码 截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)& j& K( d# M8 l5 J$ Q. Y7 D* }+ f& ?7 S
二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
+ x1 I% p# x( Q* z: d2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录& ~& t/ [1 m% k- j4 m" z) f
END+ H7 s% p/ s+ L* L5 ?
附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
% [3 o7 ^- Z; Z- h# K9 y. z- Looks like OpenVPN is already installed.
+ B4 F7 d( S. E1 C7 f- S m
* D, s$ ]7 V" X. N9 Q- What do you want to do?
, J7 S y6 o5 E4 ] - 1) Add a new user
% `& d+ Q$ S ~/ T - 2) Revoke an existing user( T. O2 f4 @. Z* b) u' Y
- 3) Remove OpenVPN" Q' z2 ?! T/ v
- 4) Exit
4 i& D0 V+ j2 r - Select an option [1-4]:
C3 T$ P6 y, f. V& w
复制代码
! T9 c9 L! D( M1 y% {! k9 N, {* W这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
: M% N# L3 l% s% Y9 v2 B如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:% g; x8 d+ e* q6 l# C. |
https://github.com/Nyr/openvpn-install7 y" u8 b" t7 C4 W4 N; O( Q9 X: w$ H9 D
1 x9 o# C* H+ Z* ~. a9 l1 f |
|