找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 102|回复: 0

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

[复制链接]

983

主题

83

回帖

5万

积分

管理员

积分
53122
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install
" e6 r5 c: N! a# s1.1. 下载安装0 Z5 M7 A4 h; G: ^  u
  1. # git clone https://github.com/guoew/openvpn-install.git' X+ @& M+ t0 D7 V  p  \5 k: Y% g
  2. # cd openvpn-install &&  bash openvpn-install.sh
    % ?- Z. C) m$ `9 y' R2 \' m
  3. Welcome to this OpenVPN "road warrior" installer!
    , u7 ^6 [/ r$ Q% |# Y

  4. 3 N9 n5 E( X6 B$ d6 d& u
  5. I need to ask you a few questions before starting the setup.
    7 i1 B  c* ?' H) S
  6. You can leave the default options and just press enter if you are ok with them.2 G5 N* P& c$ ?( E
  7. 7 m$ a' V1 r* J1 `4 q; p7 F: `
  8. First, provide the IPv4 address of the network interface you want OpenVPN
    + D7 ?/ j- z+ l9 |
  9. listening to.& c7 v) _- k# M; A0 n) E
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车" z' ^; w+ p: D# D% ^% t

  11. ( N" {4 s! i5 c* J
  12. This server is behind NAT. What is the public IPv4 address or hostname?
    9 J  b' V$ O& O  L3 d  q. M
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip
    1 H$ ]% c1 k! {. S( ~2 w/ J

  14. 4 ^' d/ _5 Y" {5 D
  15. Which protocol do you want for OpenVPN connections?8 |* j. [6 A6 x; O
  16.    1) UDP (recommended)% s3 u7 B: R9 Q  o5 k/ E6 M4 T
  17.    2) TCP, ]/ z( Z* c! v# e0 x0 F# s" I
  18. Protocol [1-2]: 1 #选择连接协议
    - Z3 ]! Q; P; X) t

  19. 7 F, P; v4 G( i; g3 y& B! O
  20. What port do you want OpenVPN listening to?
    ' ]7 @& @$ H# f+ l
  21. Port: 1194 #设置openvpn监听端口6 h/ _( v5 j9 \) e/ ~

  22. / o% |, J- A& c8 C3 f
  23. Which DNS do you want to use with the VPN?
    ( {& b# E( n3 T% w& p- u  [% ]* Z
  24.    1) Current system resolvers# W4 T8 a* Z2 z/ R, U% h& j) ]
  25.    2) 1.1.1.1  r) w8 A9 }( h9 [" A1 N2 D) j7 H
  26.    3) Google4 I- {3 T5 {+ h5 T2 a3 s
  27.    4) OpenDNS
    ( H# b; {* q' n+ R3 S+ M
  28.    5) Verisign
    8 _" Y' p6 C3 G+ p7 S( a8 L
  29. DNS [1-5]: 1 #选择DNS
    + q, E# u0 z. ?
  30. 7 Z% d4 Z! g1 o* Z" B# n" G
  31. Finally, tell me your name for the client certificate.
    8 D! n( R1 \) X* L: v+ H, F
  32. Please, use one word only, no special characters.
    # z( f- _- o. \  c1 P1 ]
  33. Client name: client #设置客户端名称
    ( _  o" `, b. }5 o; `+ O
  34. - L0 J7 Q9 p& f& z9 \" v* ~
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now.4 ^" C" L6 w5 q
  36. Press any key to continue... #任意键继续
    ! |9 H  r/ J! e) l9 {3 t; l6 ^
  37. ...
    0 b: \7 D# S$ j: r0 S0 ^
  38. An updated CRL has been created.
      G# ?% _/ W" G9 T1 N" v7 X; B
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
    # a* M9 L' ?0 L4 g, _: g4 _% N

  40. 5 S1 h; J1 D2 b: M
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.
    $ q/ T$ f- O2 N& L/ T) G
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.5 z: A0 E3 t4 e- v3 Q5 ]
  43. 4 r* `& F0 }$ v
  44. Finished!  #最终看到Finished时表示安装完毕7 s. w: ^6 a5 Y3 q1 e8 y( }

  45. . a3 c( J6 r4 A+ R! s! J
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径# y3 a" Y+ f4 F$ W& P% |& l0 c
  47. If you want to add more clients, you simply need to run this script again! & ~/ ^) j) {3 E8 C  P9 k
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用
* j. F5 F5 j4 m: l8 G8 v  E1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开
5 f7 p) i% ~) |
  1. # cat /etc/openvpn/userfile.sh
    & `3 ~8 Y/ r4 L
  2. guoew guoew123
    3 D' w. w; I, z0 t
  3. yakexi yakexi123/ y  u9 y8 p; l/ f5 B
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例): m6 m9 J  W; f5 w
二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
& t2 _$ O6 J- c2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录
8 s$ B; _3 O, L+ i" D
END! L& P+ A  [. ~7 _. B" }% h
附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
# k4 @) M: f. j6 }
  1. Looks like OpenVPN is already installed.0 ~, u/ L3 d% O. Q8 `6 t- B
  2. % F' u' N( R# r: ~" z9 Z
  3. What do you want to do?
    9 V! E* W7 o4 L! M: b& X3 S
  4.    1) Add a new user" d: U0 ]& S8 [" `! @8 [' ^
  5.    2) Revoke an existing user4 t& C0 P% ]8 L7 D4 p6 |
  6.    3) Remove OpenVPN* J. h* K$ G- @8 i
  7.    4) Exit
    $ e/ u. f3 q% P
  8. Select an option [1-4]:
    1 C8 Y5 q/ y# s" L& X' E5 ~! g7 p9 \
复制代码
; p% M. h9 c! M: I2 p
这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
% W# o9 Y1 K6 |7 S( `如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:
3 E. N- C5 z0 V7 Ehttps://github.com/Nyr/openvpn-install( ^  {& R( F' N! A0 i8 p& Y
/ F( _; I( \$ ~! G' j! H; y
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|返回首页

GMT+8, 2024-12-24 00:56 , Processed in 0.112799 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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