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

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

[复制链接]
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install& U2 |. Z4 @. @" ~
1.1. 下载安装/ k; W: y* `/ D: i$ o$ s. l
  1. # git clone https://github.com/guoew/openvpn-install.git3 d7 Y/ R8 j+ x- S9 ]$ [  Q/ N; \
  2. # cd openvpn-install &&  bash openvpn-install.sh4 `5 L" r" P) O1 h
  3. Welcome to this OpenVPN "road warrior" installer!( z+ d, C1 D1 F! L4 B7 e" i0 i; U
  4. + y- E2 S% t' I& t7 U% Z2 p
  5. I need to ask you a few questions before starting the setup.
    ; Y/ |0 c% m/ c9 t2 }  z! R
  6. You can leave the default options and just press enter if you are ok with them.# w# L$ B# q5 L+ n4 h; W6 V+ f

  7. $ L  X1 |1 b* O5 ~1 p7 Q
  8. First, provide the IPv4 address of the network interface you want OpenVPN5 w9 r+ O8 _3 {9 R5 Y# G
  9. listening to.
    + x/ K2 ~# h' B, F  e$ n
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车+ v) Z, n) I4 ~( @

  11. 3 Z0 o. ~9 Y& J$ k8 L6 L" R- K6 Z
  12. This server is behind NAT. What is the public IPv4 address or hostname?# W. D1 ?0 A4 m" B
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip
    - i# J+ s2 X7 G' l
  14. * ^' x4 c, Q' d& S( P% V
  15. Which protocol do you want for OpenVPN connections?
    % v) U/ {: i7 y; ?# D
  16.    1) UDP (recommended)
    5 H& B7 S& s3 g% L. Y
  17.    2) TCP  \9 ]' l3 d! y% L: e
  18. Protocol [1-2]: 1 #选择连接协议# k* B+ G8 t. q

  19. : d# t7 u5 G8 \& g- S, L1 Q. F
  20. What port do you want OpenVPN listening to?
    , d' E+ t2 H/ [/ b$ O) ~
  21. Port: 1194 #设置openvpn监听端口, N! j# M) ~% B; m1 M

  22. 4 u# ?" R  y$ P6 m# v5 B
  23. Which DNS do you want to use with the VPN?
    . Q+ a2 @- {! z
  24.    1) Current system resolvers
    5 L# U3 X  M4 K4 P) g6 E
  25.    2) 1.1.1.1) p" z" ~4 I3 T
  26.    3) Google
    ; {; V: z0 p5 g
  27.    4) OpenDNS+ o9 e% `3 Z( Y0 s8 l
  28.    5) Verisign
    8 t9 _1 I7 D! S# t
  29. DNS [1-5]: 1 #选择DNS
    # p, T% ~$ Z+ s2 A! w) Y& w
  30. ; ~0 Z$ V6 X6 W4 G/ N
  31. Finally, tell me your name for the client certificate.
    & b( p- D% g4 x. D9 j7 J5 A
  32. Please, use one word only, no special characters.
    3 K8 O6 F& ?- |. ^$ L# @
  33. Client name: client #设置客户端名称  Z7 U( r/ X# x# ~

  34. " ^8 ^* p: \! G# u. z6 {' O
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now.' J! i: F# N0 [2 T
  36. Press any key to continue... #任意键继续- U' T3 ^$ `* \
  37. ...- l4 |, ~$ u4 K! A; j
  38. An updated CRL has been created.
    7 p+ A% U: y' n, h+ r
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
    8 R0 U& ~8 c+ h  y; Z7 e7 Y

  40. ) M) X6 c1 @% V) n8 I
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service./ A6 r! l6 o6 m8 e% n
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.
    1 p4 T- {/ \& l6 K! b& j
  43. 0 G+ r0 r' Y, j0 \
  44. Finished!  #最终看到Finished时表示安装完毕
    $ l' J8 I% v2 X( Q
  45. & ]: `. @. h1 o" ~
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径9 a, {$ X! \% O/ u+ T2 D9 V0 t
  47. If you want to add more clients, you simply need to run this script again! ' i( J) ~9 W6 v; e
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用
5 M( n/ I6 N& Y8 l5 i1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开
% K: M( R( O( g
  1. # cat /etc/openvpn/userfile.sh. C$ X% w' m' C3 g5 {
  2. guoew guoew123. P- W5 m2 [$ J& z
  3. yakexi yakexi123
    ) Y4 b" L$ T* d- C
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)
* ]8 P5 u: v( e, T二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
, l5 k. a8 }6 ]7 [  x2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录
$ o" e& m; h" p5 J, p! q+ w1 r4 [
END$ _+ \- J4 V1 K8 {' |, s5 U
附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
* y, g$ R$ L( m& D0 \9 X  @
  1. Looks like OpenVPN is already installed.
    5 K2 n% f+ F5 h' `0 s% m0 Z( @; [1 Y

  2. 1 D6 I/ p% ^% A- U
  3. What do you want to do?
    ; c/ X6 l/ e: l" c. [
  4.    1) Add a new user
    . c+ d4 h! i! R; [5 y1 I
  5.    2) Revoke an existing user, b$ m7 U( O8 y2 Z. F; |
  6.    3) Remove OpenVPN; c0 ^: A' [& B: N
  7.    4) Exit* D; I) G, _  o  t; A! Q1 E4 t4 z, ]
  8. Select an option [1-4]:
    # |, [$ m1 C8 U, r6 j; c' d
复制代码
. ^) t; T6 G9 A% k. o1 r, E
这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
; s4 z6 T5 [5 ]$ N% ^3 }如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:1 Q  q# N) j& Q9 ^& I7 [
https://github.com/Nyr/openvpn-install. d' S1 Q0 G0 w* z$ D8 S- }+ y& S

) I9 Z" B# i- k; |# \
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

GMT+8, 2026-11-2 10:54 PM , Processed in 0.100680 second(s), 23 queries .

Powered by xyh-moon X3.5

© 2001-2026 Discuz! Team.

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