|
|
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install5 L" V5 P5 t) y! P, f' B
1.1. 下载安装
6 ~5 `* q, F! Z) C! g( `" h" P- # git clone https://github.com/guoew/openvpn-install.git% J( T: ]8 Q) _
- # cd openvpn-install && bash openvpn-install.sh/ l) g6 U' Z" Y, `: x( x) ?
- Welcome to this OpenVPN "road warrior" installer!" G$ j- G/ {# ?2 `
' q+ i8 z1 o3 m/ L- ~- I need to ask you a few questions before starting the setup./ O7 B! K, ~1 c" K Z2 V7 I. k1 L) O
- You can leave the default options and just press enter if you are ok with them.
; {$ f* f0 o( M2 c4 U9 _: }; @
/ D) l) `5 |- m: O- First, provide the IPv4 address of the network interface you want OpenVPN
* C* j. A# T' l- R& K. @ - listening to.- {2 x- Z& L# e2 n1 M5 t5 c4 n
- IP address: 172.27.0.2 #默认获取本机ip,直接回车
: V: N2 U( X3 O2 w# J - % P& J7 W# _3 X6 F3 q1 n
- This server is behind NAT. What is the public IPv4 address or hostname?
4 L9 y6 E& t o, f - Public IP address / hostname: 18.24.64.250 #输入主机公网ip
! ~* @3 c5 p0 d0 q6 L - * G, o: a2 k% T. [! R% [) m
- Which protocol do you want for OpenVPN connections?! }9 z/ V& }' k+ J
- 1) UDP (recommended)
2 e7 j, P7 h' u# R8 Z - 2) TCP
; b3 I9 k* h; i) Z Z - Protocol [1-2]: 1 #选择连接协议
# }8 e1 T3 ?- ~4 a2 l2 y7 S6 G
2 N6 @8 ^/ x# L1 ?- What port do you want OpenVPN listening to?
, ~5 O8 A8 ~( K9 Y - Port: 1194 #设置openvpn监听端口: F) S* o4 j/ s$ ?. x
' D6 m8 r! s* B8 a' i- Which DNS do you want to use with the VPN?4 R. a' j5 b$ |3 D4 Z
- 1) Current system resolvers
. x6 Q' ]3 Z" l7 i - 2) 1.1.1.1, W0 K/ W6 ~5 R H
- 3) Google
5 [. J# D" S5 D7 F - 4) OpenDNS
% C- S2 T$ c; K: {" O6 n0 c - 5) Verisign' J) l* ]2 g t4 R R3 E7 O0 [
- DNS [1-5]: 1 #选择DNS
8 c1 R$ c! h: ?& o# d7 z
, U; G2 h; I8 y+ o8 [6 `) F7 T; m- Finally, tell me your name for the client certificate.0 P e. x0 @. ?: D0 D
- Please, use one word only, no special characters.% k F6 [ R* S
- Client name: client #设置客户端名称 `$ J# Y2 C& E/ C# S4 }! _; U/ ~+ D* ?; L
- " S* ~$ N2 c, I. u; d) s
- Okay, that was all I needed. We are ready to set up your OpenVPN server now.$ x8 l4 C" @- S4 b, {7 r! S( }
- Press any key to continue... #任意键继续+ Q, f% T C, c1 @$ G: S
- ...
9 b. |* O$ y: t. Z/ W8 y - An updated CRL has been created.7 I. H0 i0 z" d
- CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem3 t, K; m+ C, @% {1 }
" }& r S% G/ a9 x* @- Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.+ ]8 }. x( R: B
- Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.
3 ^1 o9 `6 L( |! r* U - 2 H0 Q) R9 X2 m( L, T' P
- Finished! #最终看到Finished时表示安装完毕
" B( r' j, ~/ w - 3 h. B" R8 ^! S# Z6 I5 _
- Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
% O: J- n2 A- O( j - If you want to add more clients, you simply need to run this script again!
$ c; ]) N) Y0 ?9 u4 l
复制代码 将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用/ U" P# {" `" B+ J% ~
1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开
Z# h0 W0 c4 X- ^! g- # cat /etc/openvpn/userfile.sh
5 S# O6 L N4 `+ T3 O6 K - guoew guoew123
" W( _3 U0 n% x# W9 g9 Q% K& R0 [ - yakexi yakexi123) I% b; b6 \: W" m* L$ b3 k& I
复制代码 截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)$ Z3 ] t' \- s) [8 ~# \* w, h) H
二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
U- Q; x& u; z1 D. `2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录1 Y- ~4 Y. |: ~9 n& e, Y
END
3 f& w8 H" [5 z5 t+ ]* i附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:: `7 H! I7 s! R4 H; ~" M% E! z
- Looks like OpenVPN is already installed.5 p! ?) c9 U! h
- % W5 o, p, [5 S2 j3 M
- What do you want to do?
8 l8 f% C: G. d m% V* p# s - 1) Add a new user9 x8 l! w \( Y* w) J0 G4 v
- 2) Revoke an existing user' D' @! K/ S- X1 O, W
- 3) Remove OpenVPN
* p7 g& `1 |7 n; B1 I1 Z; n$ f1 k" p - 4) Exit
& I! x- n2 G5 U1 {, [6 o - Select an option [1-4]:, t% A( B# c/ g
复制代码
0 A) i, A) X9 A: ]% L& i, Q, P& W这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
7 u( X" g& K, Q0 g. Z- R, H& G如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:
A5 F H: t' b( V Q( g2 \ whttps://github.com/Nyr/openvpn-install
' T: L2 ]: i/ L' G& e1 d
7 g+ @% r) Q) u6 z* V |
|