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

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

[复制链接]

986

主题

92

回帖

5万

积分

管理员

积分
55255
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install7 A% S$ t' C+ H& h  X
1.1. 下载安装
3 ^: t6 v' E! G' l; k3 f! r
  1. # git clone https://github.com/guoew/openvpn-install.git
    " x) H7 }  W# Q5 }$ J
  2. # cd openvpn-install &&  bash openvpn-install.sh
    # E9 {& @$ [1 q) Y; x
  3. Welcome to this OpenVPN "road warrior" installer!+ ?2 F( T7 Y$ Q" ]0 x' X
  4. , o& N6 J: f" q+ w
  5. I need to ask you a few questions before starting the setup.5 D$ v2 b! K: m& c
  6. You can leave the default options and just press enter if you are ok with them.
    # p$ ^! r& R- ~8 T) K9 P

  7. ) O7 V$ i. j3 M( D2 @; u' f
  8. First, provide the IPv4 address of the network interface you want OpenVPN. s9 W0 |  n5 d
  9. listening to.
    8 E2 L8 ?+ S' d4 M2 H; M
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车
    5 G! ]' \- u1 Q/ v
  11. : A, w5 {2 N$ s! U0 B
  12. This server is behind NAT. What is the public IPv4 address or hostname?9 s3 @& A; r! Z) _( E# G& e, Z) S
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip
    ( D' A* |6 h6 e( M9 O7 n
  14. ; y0 b4 ]6 S7 p: c( E2 `
  15. Which protocol do you want for OpenVPN connections?( N) h* Q# _  x+ a
  16.    1) UDP (recommended)
    ( y& p9 S" [$ z' Z9 B: D0 L
  17.    2) TCP
    , R4 ]1 `$ \- U9 |
  18. Protocol [1-2]: 1 #选择连接协议
    / p4 e$ A) q5 e

  19. . ^( ]3 S, _- i# Y: B. _6 m
  20. What port do you want OpenVPN listening to?4 E* n; V) k/ T* s) F! S( o
  21. Port: 1194 #设置openvpn监听端口9 H; j5 X" N# m
  22. ( w* q" o' D0 @
  23. Which DNS do you want to use with the VPN?, C! ?( M% Z$ f1 }% f+ G
  24.    1) Current system resolvers3 o1 @4 _5 a( ^& \5 R
  25.    2) 1.1.1.1- Y$ F* Q' h- ?
  26.    3) Google+ |7 f- s& S3 _! u1 C4 T0 p
  27.    4) OpenDNS
    4 |/ Y/ w) f1 \* x1 `- ^. J9 X
  28.    5) Verisign  r: G) q0 c0 u5 C4 ]
  29. DNS [1-5]: 1 #选择DNS  k* V, P6 [0 [4 p; d

  30. 6 a3 x, [: t& l. g) Y) V' x5 a
  31. Finally, tell me your name for the client certificate.4 R5 Y" j. m- t$ `: w3 G
  32. Please, use one word only, no special characters.2 A! b9 {$ w0 g
  33. Client name: client #设置客户端名称
    0 I7 k% ]+ H& ^4 R, [5 h
  34. # j2 ~% `3 R% m, `
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now.. _# J0 Q8 F2 |- m& P
  36. Press any key to continue... #任意键继续; {6 |* s) T7 z+ z: Q$ O
  37. ...
    4 R2 P, Q( H$ a  w
  38. An updated CRL has been created./ @: T, p9 b' B
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
    9 c' e  h& M3 i$ X# }9 X# w, \

  40. 1 |  u' y% r, }+ s: u2 u
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.) {8 x- }  m* l7 F1 I( R- B- o5 o
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.
    0 z$ ^6 Z/ Z5 y' i3 o8 J( a

  43. 7 b$ H0 n. F, q  q. [" b, r
  44. Finished!  #最终看到Finished时表示安装完毕, N% r8 }, v. M. F7 \+ _

  45. $ {, A- n& O) \+ V. G
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
    4 d" q' n8 ]2 H; f
  47. If you want to add more clients, you simply need to run this script again!
    ' C* X  H. {% M0 u
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用
1 e' W0 h! B6 h7 n( W8 U1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开; P. }( K; M3 z) E
  1. # cat /etc/openvpn/userfile.sh* X* ?* {" h$ ]
  2. guoew guoew123, E& t8 R* d  E/ C- S/ K
  3. yakexi yakexi1233 K. c3 ^9 U& t5 ?7 U
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)
' |% w6 K2 r! [. Q6 w2 M二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
+ ]: p' N, d: P4 C+ p2 o( F. V" g% t2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录
* t* m) Q: M7 o% r
END* y4 A+ G6 Y, u  J2 n9 q( @! m8 |8 q
附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
+ d! \7 E  P8 e4 H7 R
  1. Looks like OpenVPN is already installed.6 h( Z) w$ X9 H8 d
  2. 7 Z, y( T5 i; x2 I# |& z1 Y
  3. What do you want to do?
    9 y! y8 P3 ]) S+ x# e- i
  4.    1) Add a new user* A8 `% d9 h+ V1 C* u- \) V
  5.    2) Revoke an existing user
    5 f# ]% g# o4 F/ [) {! J
  6.    3) Remove OpenVPN  ]- g/ l. o6 _: N
  7.    4) Exit( X# T6 U9 W, I6 k
  8. Select an option [1-4]:
    * [$ s6 L3 }" d- @3 T! o& _
复制代码
9 s. ~2 h# ^% T/ S0 E% Y
这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
4 G* W" m" y# {+ l) S% [) O如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:
# D/ X8 O. N, ohttps://github.com/Nyr/openvpn-install
2 j' O+ h' B2 q$ u& `2 \* A6 \6 g/ B$ ]% ?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

GMT+8, 2026-3-21 10:38 PM , Processed in 0.097103 second(s), 23 queries .

Powered by xyh-moon X3.5

© 2001-2025 Discuz! Team.

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