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

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

[复制链接]

989

主题

92

回帖

5万

积分

管理员

积分
55362
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install
, D/ m* X9 d) g1.1. 下载安装
; i% L& J* p# U
  1. # git clone https://github.com/guoew/openvpn-install.git, W1 D- O- q% e; Y, j. d
  2. # cd openvpn-install &&  bash openvpn-install.sh
    2 S! m/ E9 y8 u6 e  K% N
  3. Welcome to this OpenVPN "road warrior" installer!- e$ z1 v6 W1 f

  4. 8 m5 ?' \; `1 ]. M8 y
  5. I need to ask you a few questions before starting the setup.. @* ^1 k" m8 X+ w, v* x
  6. You can leave the default options and just press enter if you are ok with them.5 B) U0 N. m( G. o" W

  7. 1 X( L( f0 H% a& w9 s2 d6 y& l: G
  8. First, provide the IPv4 address of the network interface you want OpenVPN/ x3 B9 }) _  A
  9. listening to.
    * [. E* Z. S, u( N: R$ k/ ?
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车( W9 i- v4 a7 D; u7 d

  11. & Q& w- L! j. w: Z0 Z
  12. This server is behind NAT. What is the public IPv4 address or hostname?' m) {* r. R! k
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip9 e5 a, Z% x, t1 G$ ^6 q. D1 o5 ^7 X
  14. 1 q& m/ `- ~) N- m+ Z
  15. Which protocol do you want for OpenVPN connections?
    ! I$ b$ e* f1 M5 {$ h
  16.    1) UDP (recommended); b8 e! l, D( h6 D' y+ v
  17.    2) TCP
    3 f# O8 T3 Q% G  N' G+ {& [
  18. Protocol [1-2]: 1 #选择连接协议
    & i" j) R2 w$ u3 @4 ^

  19. : S! l) q9 x! [
  20. What port do you want OpenVPN listening to?8 s& \4 i& h3 y# C& W" c" V
  21. Port: 1194 #设置openvpn监听端口' \3 L0 ]* P  A9 z9 O) W$ ]; p$ y
  22. ( B; q+ _* ~7 @$ m
  23. Which DNS do you want to use with the VPN?/ B1 \: p, F! a
  24.    1) Current system resolvers
    7 k9 c& z1 l' j/ w0 c' P. o( b
  25.    2) 1.1.1.16 L4 A/ u: I( b
  26.    3) Google5 H. u  h6 f* K- \' M4 u' t
  27.    4) OpenDNS
    7 L& d: J" B7 @: k; O3 m  `
  28.    5) Verisign- g# I' F" @9 x9 u3 T9 @6 i
  29. DNS [1-5]: 1 #选择DNS
      l$ W) W$ c3 u3 b* ?
  30. 7 J* `  Z8 _1 _( B- s; C- o: e
  31. Finally, tell me your name for the client certificate.
    1 L# ?2 b" g* Z0 u: Y! ^
  32. Please, use one word only, no special characters.
    % J* P$ {; x2 {  G
  33. Client name: client #设置客户端名称
    & o3 [0 }$ `+ v' @2 _

  34. " K* n! K5 f  [9 x
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now.
      L4 \9 ~8 b& \5 v! ~3 i9 I. ?' Q
  36. Press any key to continue... #任意键继续6 v7 A; |" ]/ `7 w6 L
  37. ...- W5 e9 S2 L; \7 ]
  38. An updated CRL has been created.
    + B- F4 Q4 Q6 l- v
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem( S5 \  E5 ]3 s! C: _7 D# V
  40. " q3 i$ P1 C5 }2 g
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.* j+ @/ V  ?$ Z" u0 `
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.
    + m2 V% ?1 Q  |! |( t2 V1 O/ i; T
  43. ! d; T5 a( O6 v2 G% |
  44. Finished!  #最终看到Finished时表示安装完毕" d+ P4 f' V3 t. J6 }. j8 Q. d& Z. N1 b
  45. % a) \) `& ?4 j: i5 V% T' \
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
    1 U3 a" j. O/ t' n$ Y' a, h
  47. If you want to add more clients, you simply need to run this script again! " _. Z  q1 A, W) Q
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用
$ z  H5 h. Y& O- B5 b1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开
* [* {# H- v7 @( J
  1. # cat /etc/openvpn/userfile.sh
    ( I+ n* |$ E- J  s- G6 X  ?
  2. guoew guoew1231 v+ U' c+ B( [/ J7 p, p; V/ ?
  3. yakexi yakexi123* w( @/ C7 m% J- f, a
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)- r% w: l& p. f# D. c" Y; l9 I
二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
: s7 d+ |" i* m; c$ C2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录
3 z2 }- ]& g5 G' c3 e. r
END7 V; Z4 x  P* O5 ~0 w
附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:/ B9 Y$ m7 Q+ {- Y
  1. Looks like OpenVPN is already installed.# H5 S$ o! Y: f, ]

  2. . d$ S8 z) g" M; k5 k# H- F" N3 ~& S
  3. What do you want to do?
    8 R' }3 N9 M7 K, t; q5 ]
  4.    1) Add a new user
    - b7 e4 O& E( y& ]7 p
  5.    2) Revoke an existing user$ k+ G' J: J( b4 u
  6.    3) Remove OpenVPN
    2 ]9 B* u; X) J  v; [
  7.    4) Exit
    + I2 ]& v5 d0 ^% v7 h% a9 A
  8. Select an option [1-4]:# o8 I6 o( w/ I/ V4 y
复制代码

0 @) L2 m$ s) |+ x3 P这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
# A" @% S& u5 V9 J( S1 m如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:1 e$ l: a& u" Z0 n/ W
https://github.com/Nyr/openvpn-install
, v7 m5 M* K' B9 R
" S2 O/ [4 }0 Y4 C. A7 |
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

GMT+8, 2026-5-6 12:39 PM , Processed in 0.120118 second(s), 23 queries .

Powered by xyh-moon X3.5

© 2001-2025 Discuz! Team.

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