|
|
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install8 u3 Z; r6 l; }- V( t
1.1. 下载安装
" f; v+ b) h9 B) X" e+ F- # git clone https://github.com/guoew/openvpn-install.git
0 y: }1 j. q8 A' U - # cd openvpn-install && bash openvpn-install.sh( Z# c% \) T7 @& B% x
- Welcome to this OpenVPN "road warrior" installer!; C0 m7 Q$ d$ p3 x a
- ; }# e9 s- Z, B1 x
- I need to ask you a few questions before starting the setup.
7 J9 O: }& [* z/ Y* z3 A - You can leave the default options and just press enter if you are ok with them.
$ K1 ~. o! m, Q: x% f - 6 { L. x. N6 I9 U0 X0 M
- First, provide the IPv4 address of the network interface you want OpenVPN
+ b+ }1 t& g' h2 X - listening to.
% ^0 E+ ~" H3 u1 d* j - IP address: 172.27.0.2 #默认获取本机ip,直接回车: K/ R. c# r0 R, z$ t/ J, j
! _9 Z2 R0 A0 R4 k/ Z. c/ j1 `3 D/ }- This server is behind NAT. What is the public IPv4 address or hostname?- a2 [1 c/ g2 a/ X4 h* W3 A( Y
- Public IP address / hostname: 18.24.64.250 #输入主机公网ip. t6 m) d9 |& ^7 M8 i6 u
- ) p; U2 ]" X/ g& z
- Which protocol do you want for OpenVPN connections?
, P e+ X9 a5 i q- s - 1) UDP (recommended)
* W( I' E3 e1 p - 2) TCP
) X. e3 s% }( |0 _: W' I( O+ E - Protocol [1-2]: 1 #选择连接协议
; o3 u/ Y0 u! K) F$ d( s - 2 [ m y1 F, g: X! k4 e: y
- What port do you want OpenVPN listening to?
& p5 y5 u7 S8 R+ [9 f- G - Port: 1194 #设置openvpn监听端口' T% T, D* Q+ B3 n |
7 }; [# l B% q z _8 v- Which DNS do you want to use with the VPN?
6 B! R b/ s u( [, s, T9 { - 1) Current system resolvers' ]0 C) C* }1 N8 }/ S
- 2) 1.1.1.1: M7 s( I0 }' b
- 3) Google
* V& g; K" H4 P% e$ t - 4) OpenDNS
5 x) c: X0 i( E$ f, p1 e- ]9 {* g - 5) Verisign7 A1 D" C- i% O$ p* _ E/ _- J3 D
- DNS [1-5]: 1 #选择DNS; s/ k4 |7 a4 j- |5 a9 c: i
+ p) `! e a. D- Finally, tell me your name for the client certificate.
: h4 R/ |4 J4 [; o - Please, use one word only, no special characters.
8 { U3 \+ {. G2 B/ M0 u$ q - Client name: client #设置客户端名称
- V% c" d+ A) I7 Z. c2 H( e - ! p6 G' L, H* p& P$ ]9 C
- Okay, that was all I needed. We are ready to set up your OpenVPN server now.
) L) Z- l' k! E X - Press any key to continue... #任意键继续% P$ \6 ?5 H, n$ ~2 x
- ...- r6 T0 l6 c3 j ~6 H! Q5 [
- An updated CRL has been created.7 @4 v4 o* } V! L9 L: ]
- CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
7 N1 J2 D' f( L9 G# n - 1 a' W$ X, t& d' w$ s$ j/ |3 [( e' n; y
- Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.3 Z D2 N9 L1 i- X6 E4 [
- Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.5 C S, o* T8 r8 ~" v
" l' r3 X: Q5 h# y- Finished! #最终看到Finished时表示安装完毕; s* j2 @/ n& u: T
+ ~5 r3 j# D7 e, }: Y# V. Y/ Y- Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
! V7 X. T1 s0 y- `! w) C0 |4 @ - If you want to add more clients, you simply need to run this script again! * O+ h0 ~- G+ u- d* O4 o+ ]
复制代码 将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用
- Y9 ?$ ]& n, n1 N) Y1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开! {3 E* Z, b- T- X
- # cat /etc/openvpn/userfile.sh
4 z, b( N& Z D+ a - guoew guoew123
: k( i* I2 A. \ } - yakexi yakexi1231 L+ U" f/ o0 ~* y1 f F
复制代码 截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)
; I3 g! e8 ^! J1 _, y7 z二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
0 P0 }& i8 Z9 E4 F2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录( [5 t& Z, b( ]! R1 O) _
END$ m1 v+ Z& K$ Q8 ]0 P
附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
5 Y0 [# L# m6 O, W$ ~" x- Looks like OpenVPN is already installed.- H1 m- o7 k/ l! W3 }
- 9 {' i9 c% b. \; N: V* c/ Q6 u
- What do you want to do?
* D/ m) u3 a* | - 1) Add a new user
" v) T8 t+ h0 Z! P8 L H2 _ - 2) Revoke an existing user
, F$ j z+ i1 U. ?8 I! H - 3) Remove OpenVPN& \* i3 s! u( Q( r. v
- 4) Exit
( {% ]' P5 d$ {- W( ] - Select an option [1-4]:
+ j6 ?8 p; m! e$ Q+ v) o
复制代码
& @% i; u8 B& P) Q. }: j% w G# M这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。, p% U8 s2 l( M/ h. I$ k$ w
如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:! P$ ?- u* }/ @/ ^+ K& b& F
https://github.com/Nyr/openvpn-install
: n! z& ^/ P) r N" s
4 @6 z$ _& t0 k" B1 c: y1 j4 Q8 _ |
|