找回密码
 立即注册
搜索
查看: 240|回复: 0

一键部署超级简单易用的openvpn服务器,支持多证书+多账号...

[复制链接]

991

主题

92

回帖

5万

积分

管理员

积分
55422
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址: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
  1. # git clone https://github.com/guoew/openvpn-install.git% J( T: ]8 Q) _
  2. # cd openvpn-install &&  bash openvpn-install.sh/ l) g6 U' Z" Y, `: x( x) ?
  3. Welcome to this OpenVPN "road warrior" installer!" G$ j- G/ {# ?2 `

  4. ' q+ i8 z1 o3 m/ L- ~
  5. I need to ask you a few questions before starting the setup./ O7 B! K, ~1 c" K  Z2 V7 I. k1 L) O
  6. You can leave the default options and just press enter if you are ok with them.
    ; {$ f* f0 o( M2 c4 U9 _: }; @

  7. / D) l) `5 |- m: O
  8. First, provide the IPv4 address of the network interface you want OpenVPN
    * C* j. A# T' l- R& K. @
  9. listening to.- {2 x- Z& L# e2 n1 M5 t5 c4 n
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车
    : V: N2 U( X3 O2 w# J
  11. % P& J7 W# _3 X6 F3 q1 n
  12. This server is behind NAT. What is the public IPv4 address or hostname?
    4 L9 y6 E& t  o, f
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip
    ! ~* @3 c5 p0 d0 q6 L
  14. * G, o: a2 k% T. [! R% [) m
  15. Which protocol do you want for OpenVPN connections?! }9 z/ V& }' k+ J
  16.    1) UDP (recommended)
    2 e7 j, P7 h' u# R8 Z
  17.    2) TCP
    ; b3 I9 k* h; i) Z  Z
  18. Protocol [1-2]: 1 #选择连接协议
    # }8 e1 T3 ?- ~4 a2 l2 y7 S6 G

  19. 2 N6 @8 ^/ x# L1 ?
  20. What port do you want OpenVPN listening to?
    , ~5 O8 A8 ~( K9 Y
  21. Port: 1194 #设置openvpn监听端口: F) S* o4 j/ s$ ?. x

  22. ' D6 m8 r! s* B8 a' i
  23. Which DNS do you want to use with the VPN?4 R. a' j5 b$ |3 D4 Z
  24.    1) Current system resolvers
    . x6 Q' ]3 Z" l7 i
  25.    2) 1.1.1.1, W0 K/ W6 ~5 R  H
  26.    3) Google
    5 [. J# D" S5 D7 F
  27.    4) OpenDNS
    % C- S2 T$ c; K: {" O6 n0 c
  28.    5) Verisign' J) l* ]2 g  t4 R  R3 E7 O0 [
  29. DNS [1-5]: 1 #选择DNS
    8 c1 R$ c! h: ?& o# d7 z

  30. , U; G2 h; I8 y+ o8 [6 `) F7 T; m
  31. Finally, tell me your name for the client certificate.0 P  e. x0 @. ?: D0 D
  32. Please, use one word only, no special characters.% k  F6 [  R* S
  33. Client name: client #设置客户端名称  `$ J# Y2 C& E/ C# S4 }! _; U/ ~+ D* ?; L
  34. " S* ~$ N2 c, I. u; d) s
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now.$ x8 l4 C" @- S4 b, {7 r! S( }
  36. Press any key to continue... #任意键继续+ Q, f% T  C, c1 @$ G: S
  37. ...
    9 b. |* O$ y: t. Z/ W8 y
  38. An updated CRL has been created.7 I. H0 i0 z" d
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem3 t, K; m+ C, @% {1 }

  40. " }& r  S% G/ a9 x* @
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.+ ]8 }. x( R: B
  42. 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
  43. 2 H0 Q) R9 X2 m( L, T' P
  44. Finished!  #最终看到Finished时表示安装完毕
    " B( r' j, ~/ w
  45. 3 h. B" R8 ^! S# Z6 I5 _
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
    % O: J- n2 A- O( j
  47. 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
  1. # cat /etc/openvpn/userfile.sh
    5 S# O6 L  N4 `+ T3 O6 K
  2. guoew guoew123
    " W( _3 U0 n% x# W9 g9 Q% K& R0 [
  3. 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
  1. Looks like OpenVPN is already installed.5 p! ?) c9 U! h
  2. % W5 o, p, [5 S2 j3 M
  3. What do you want to do?
    8 l8 f% C: G. d  m% V* p# s
  4.    1) Add a new user9 x8 l! w  \( Y* w) J0 G4 v
  5.    2) Revoke an existing user' D' @! K/ S- X1 O, W
  6.    3) Remove OpenVPN
    * p7 g& `1 |7 n; B1 I1 Z; n$ f1 k" p
  7.    4) Exit
    & I! x- n2 G5 U1 {, [6 o
  8. 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
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

GMT+8, 2026-6-20 05:57 AM , Processed in 0.080874 second(s), 23 queries .

Powered by xyh-moon X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表