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

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

[复制链接]

986

主题

92

回帖

5万

积分

管理员

积分
55255
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install2 C1 c/ q5 ~* H3 x
1.1. 下载安装
, @# K0 W. x, ]0 B) N1 O/ f! s
  1. # git clone https://github.com/guoew/openvpn-install.git
    ) W$ I+ h: X" s+ u% P0 S2 E
  2. # cd openvpn-install &&  bash openvpn-install.sh& L( H5 K- Z, u3 y2 U( N
  3. Welcome to this OpenVPN "road warrior" installer!/ P4 K/ _6 q$ s# }1 `7 I  n; H7 f

  4. $ @+ t3 I: g8 I5 u5 b! Y+ W% o
  5. I need to ask you a few questions before starting the setup.; |* k$ B; f4 q. V, J
  6. You can leave the default options and just press enter if you are ok with them.3 j4 i  g7 Z) K6 l  C6 \9 {/ i1 R
  7. 3 ]2 @4 m9 L' P  [% W! ?
  8. First, provide the IPv4 address of the network interface you want OpenVPN: ?+ B2 Y9 E/ |
  9. listening to.
    . X( J* `4 c8 d$ I& Q; J. U" ]
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车
    / `5 A6 ?8 H( @& ?* H6 h# k* A% r# H

  11. 0 U7 w: Y8 I- t; C
  12. This server is behind NAT. What is the public IPv4 address or hostname?, U  }' F4 H  C- ^; b
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip
    * x6 S* ]- h, V1 g9 @3 P0 q6 ]

  14. ) R. K6 d9 R+ @! m
  15. Which protocol do you want for OpenVPN connections?9 O4 e; d& P$ N$ n3 {
  16.    1) UDP (recommended)
    0 N& |4 `+ r) I" _8 B6 ~- {( j4 l
  17.    2) TCP
    4 e& A  I7 w' d% Q% N" g
  18. Protocol [1-2]: 1 #选择连接协议# @- e' }" _4 Z( t5 |/ j
  19. . W$ v/ W. U" o
  20. What port do you want OpenVPN listening to?
    3 |4 F% R; F. X* ^( g
  21. Port: 1194 #设置openvpn监听端口. H) x+ i5 Y% w2 k1 V
  22. 8 m+ k: d% J5 y) `, g" Z' b4 B
  23. Which DNS do you want to use with the VPN?% d8 `, R" k# b, p' Y$ P
  24.    1) Current system resolvers
    5 `& c4 j* Q4 Q7 G- C
  25.    2) 1.1.1.1# @' l* D! z9 m& g
  26.    3) Google
    8 V& B% O0 v5 j- Z! p7 s% |
  27.    4) OpenDNS
    7 z* y: q* _4 H: W0 O
  28.    5) Verisign- |* g5 e+ s3 T: I/ a4 h
  29. DNS [1-5]: 1 #选择DNS
    ) g; e9 r) ^& Z0 J; F

  30. - b! u& l" {# k* P. B1 c$ g
  31. Finally, tell me your name for the client certificate.) f. l8 r' m8 {3 |4 E0 g
  32. Please, use one word only, no special characters.
    # P* m  p, P7 \7 O" j6 X4 D9 \. ^
  33. Client name: client #设置客户端名称; H$ j" o( k. U% v7 A( U
  34. ' K) k0 t8 P1 G9 A4 l5 @
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now." H6 w9 T) e7 w, ^, T8 N/ ?
  36. Press any key to continue... #任意键继续
    7 i! l2 V, P6 S' o$ P* m3 f
  37. ...1 x7 Q6 J+ p2 @5 m+ H/ {
  38. An updated CRL has been created." y) X1 n: C# U  {& K3 t# o
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
    7 r4 ~# y- z; j& @6 L' u& Q% |

  40. 1 l, E# N& z5 _* M+ A
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.
    8 e4 R2 f$ \9 X5 w3 j& M1 ^: T
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.
    4 t) K2 w5 w- f5 r" j) J/ T
  43. 3 r2 V; c2 ]% B* r% I; d: c! `6 @
  44. Finished!  #最终看到Finished时表示安装完毕
    2 G% ?, w: k8 H5 d2 e+ Y
  45. ) X; k& h7 V6 z5 D+ Q
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
    9 h& A- w+ f0 \+ a- g( C* Y7 [
  47. If you want to add more clients, you simply need to run this script again!
    ) N) ?, c& K) B$ K
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用- K, Z( g, R  c% K4 b
1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开/ _6 w- Y5 }- W
  1. # cat /etc/openvpn/userfile.sh) l( q9 \! Q) ]# r% Y+ w* ]" e. f
  2. guoew guoew123# f. e2 T& x* W5 |5 j  e& L
  3. yakexi yakexi123
    + y, d( E* m4 @8 e. W5 Z- r& A
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)
6 A4 N) \6 D" a" O7 H) D5 ~二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。' F9 ?4 ^# r; I& f! H, }
2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录
1 J* H  F6 {  L( p$ ]* D& F' b: u
END
+ U* o8 W4 _/ B2 R! n. f附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
: w3 f9 G1 g/ g4 O1 h/ O' v& Y
  1. Looks like OpenVPN is already installed.2 E# X5 d5 O% q9 X" D; N
  2. ! T+ D  t" j8 G% K: v' g: S9 p
  3. What do you want to do?3 n! s- p- C, V) U
  4.    1) Add a new user0 t% a+ ^& t: R0 z* b! ?
  5.    2) Revoke an existing user
    7 X+ r4 W# t# T/ M+ g$ g5 w
  6.    3) Remove OpenVPN
    2 t% D  ^# o# ]( Z
  7.    4) Exit# }' O! G' i" q) p" G& f* O
  8. Select an option [1-4]:
    : s5 x* C4 v2 t. x4 U5 x; Y' |. {0 }
复制代码
. a5 ]& j" M- R6 i9 \
这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。# p$ |+ t8 s) _- m9 L, `
如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:/ ?, E# r: E4 c
https://github.com/Nyr/openvpn-install
' j& `6 M: X3 g: b
7 y& v! v+ a4 T; y: C
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

GMT+8, 2026-3-22 03:34 AM , Processed in 0.084081 second(s), 22 queries .

Powered by xyh-moon X3.5

© 2001-2025 Discuz! Team.

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