|
|
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install
/ a* o5 C" ?& S+ `3 e) o- @1.1. 下载安装
3 h. [" r& ~% e- # git clone https://github.com/guoew/openvpn-install.git
. V H" Q( c. K" } - # cd openvpn-install && bash openvpn-install.sh" C% z8 M# \8 P. V
- Welcome to this OpenVPN "road warrior" installer!$ Q" W% C" I2 ?: v
- ' n0 F* c3 M* j7 |
- I need to ask you a few questions before starting the setup.2 c; s( y" c7 `( f6 G- r' U6 \
- You can leave the default options and just press enter if you are ok with them.
/ `+ g8 ~! p6 ]$ G! k. @3 D$ m$ b - : a) A4 L/ C9 s& v0 p; O
- First, provide the IPv4 address of the network interface you want OpenVPN" R5 f& i- c5 T# K- m: p; M
- listening to.' ~$ u |; o, s5 X: n7 y2 }' t
- IP address: 172.27.0.2 #默认获取本机ip,直接回车
$ V2 T( w" w# {% H! K - / h$ w2 [0 \% W2 W
- This server is behind NAT. What is the public IPv4 address or hostname?! s4 K- g# T% |' g* e& E
- Public IP address / hostname: 18.24.64.250 #输入主机公网ip7 V6 C- @) F; d5 n0 x6 X# o9 h. k
- & S# W& ?& S* I0 G- ?# @! O- o
- Which protocol do you want for OpenVPN connections?
* C& C: x" z+ z. i% ? - 1) UDP (recommended)
) B2 J. g1 M1 _' x6 \) ?. A - 2) TCP I: y3 W8 N- i) R: ^9 X# m/ g/ Y; s0 c
- Protocol [1-2]: 1 #选择连接协议
& y/ g4 J+ ], b% E- ^6 W9 b
! O8 R E) V8 K. K$ {2 ~1 ]- What port do you want OpenVPN listening to?
6 q% j% s/ n% ~! C; q" s0 H - Port: 1194 #设置openvpn监听端口
5 [5 U! t/ S, O - 4 s0 ]+ d& r: r4 r7 X& |1 V R
- Which DNS do you want to use with the VPN?
. P4 _( ]) V7 a$ _ Z/ F# X - 1) Current system resolvers1 G4 t7 Z! N6 J) i
- 2) 1.1.1.1- y Q" |$ s) m" w# ~ i0 s
- 3) Google& e& K ]0 p# {1 T) B& B E0 H& _+ }( A
- 4) OpenDNS V% S: V8 |* d `1 [! P
- 5) Verisign
) L2 ^) d. N: o3 L, R+ q+ K' _4 i - DNS [1-5]: 1 #选择DNS/ \2 w. [/ c; H+ j, |9 N
4 H, M% k/ }+ T7 C! A4 N! A- Finally, tell me your name for the client certificate.
6 I4 l8 L2 Q6 m% i3 Y' k- F - Please, use one word only, no special characters.8 f. C5 F# b' \) ]4 |- F
- Client name: client #设置客户端名称0 _- U. G+ D# D! X& ?+ y
8 ]* l# z! X8 ~7 q3 v, A1 I- Okay, that was all I needed. We are ready to set up your OpenVPN server now.
* P7 m6 r2 A) q3 H- M6 L - Press any key to continue... #任意键继续
/ [- l' {8 q& n( p. G - ...
( g4 z, t1 |3 O5 i" m3 i - An updated CRL has been created./ a; y/ }* |/ {+ q1 ]
- CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem8 X+ A, h. E' [) ?0 e9 i
! G' o6 k- {, j) k( }0 J- Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.
1 D' s$ U, y/ {! i& z, N - Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.9 Z C; b0 l: Q/ t! Q
! b: F2 z" B: I- Finished! #最终看到Finished时表示安装完毕
9 N1 X/ M* X8 |% c+ i: C
7 Z6 C0 V# ?/ v9 Q7 a& \ N# `- Your client configuration is available at: /root/client.ovpn #客户端配置文件路径# {' g# y: Q9 t; P; @. _
- If you want to add more clients, you simply need to run this script again!
" u# b) X8 `( I& @1 C
复制代码 将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用) E+ ~' B+ f' B( r7 W# v4 f) J% T
1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开# W" H7 I6 @7 h1 s" ^( O
- # cat /etc/openvpn/userfile.sh
: s {# e A6 _# ?! O! S4 b - guoew guoew123
8 q4 F; X; ^- B# s$ m - yakexi yakexi123, @2 J# @: o. R( T5 I- h& Z! E3 ^, |
复制代码 截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)3 R7 |) b8 S" m% y4 S1 N
二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
. S% _ }; z& @+ J7 X2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录2 A ?- P$ z( T1 p/ H5 g$ C: @+ \/ ~1 }" s
END
# [) p* Y" r8 `附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:# F: n" q, u, c3 t4 l! j5 h1 v3 l
- Looks like OpenVPN is already installed.
6 e4 I" y! Z& G7 D
. w0 s: l* v* m" p) l- What do you want to do?8 y, T' V$ l5 N
- 1) Add a new user. |. h& C1 |/ B- f. s& @+ ?
- 2) Revoke an existing user [+ k3 ?4 _+ Z
- 3) Remove OpenVPN1 }6 r* C ? \5 C" t9 l3 |3 ]% k. V
- 4) Exit* @( j& z$ q9 @6 x. [, [
- Select an option [1-4]:$ p" c& ?) Q1 K- X
复制代码 . S. ]5 O& i9 j$ f# G% g
这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
. g2 S3 ]! i% @" U9 h如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:# V- a! r: ~+ n( r# T+ V8 V1 L
https://github.com/Nyr/openvpn-install3 ]2 Y. O; E* e
: Y+ j1 S4 {% Q2 _! x, a
|
|