|
|
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install2 C1 c/ q5 ~* H3 x
1.1. 下载安装
, @# K0 W. x, ]0 B) N1 O/ f! s- # git clone https://github.com/guoew/openvpn-install.git
) W$ I+ h: X" s+ u% P0 S2 E - # cd openvpn-install && bash openvpn-install.sh& L( H5 K- Z, u3 y2 U( N
- Welcome to this OpenVPN "road warrior" installer!/ P4 K/ _6 q$ s# }1 `7 I n; H7 f
$ @+ t3 I: g8 I5 u5 b! Y+ W% o- I need to ask you a few questions before starting the setup.; |* k$ B; f4 q. V, J
- 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
- 3 ]2 @4 m9 L' P [% W! ?
- First, provide the IPv4 address of the network interface you want OpenVPN: ?+ B2 Y9 E/ |
- listening to.
. X( J* `4 c8 d$ I& Q; J. U" ] - IP address: 172.27.0.2 #默认获取本机ip,直接回车
/ `5 A6 ?8 H( @& ?* H6 h# k* A% r# H
0 U7 w: Y8 I- t; C- This server is behind NAT. What is the public IPv4 address or hostname?, U }' F4 H C- ^; b
- Public IP address / hostname: 18.24.64.250 #输入主机公网ip
* x6 S* ]- h, V1 g9 @3 P0 q6 ]
) R. K6 d9 R+ @! m- Which protocol do you want for OpenVPN connections?9 O4 e; d& P$ N$ n3 {
- 1) UDP (recommended)
0 N& |4 `+ r) I" _8 B6 ~- {( j4 l - 2) TCP
4 e& A I7 w' d% Q% N" g - Protocol [1-2]: 1 #选择连接协议# @- e' }" _4 Z( t5 |/ j
- . W$ v/ W. U" o
- What port do you want OpenVPN listening to?
3 |4 F% R; F. X* ^( g - Port: 1194 #设置openvpn监听端口. H) x+ i5 Y% w2 k1 V
- 8 m+ k: d% J5 y) `, g" Z' b4 B
- Which DNS do you want to use with the VPN?% d8 `, R" k# b, p' Y$ P
- 1) Current system resolvers
5 `& c4 j* Q4 Q7 G- C - 2) 1.1.1.1# @' l* D! z9 m& g
- 3) Google
8 V& B% O0 v5 j- Z! p7 s% | - 4) OpenDNS
7 z* y: q* _4 H: W0 O - 5) Verisign- |* g5 e+ s3 T: I/ a4 h
- DNS [1-5]: 1 #选择DNS
) g; e9 r) ^& Z0 J; F
- b! u& l" {# k* P. B1 c$ g- Finally, tell me your name for the client certificate.) f. l8 r' m8 {3 |4 E0 g
- Please, use one word only, no special characters.
# P* m p, P7 \7 O" j6 X4 D9 \. ^ - Client name: client #设置客户端名称; H$ j" o( k. U% v7 A( U
- ' K) k0 t8 P1 G9 A4 l5 @
- Okay, that was all I needed. We are ready to set up your OpenVPN server now." H6 w9 T) e7 w, ^, T8 N/ ?
- Press any key to continue... #任意键继续
7 i! l2 V, P6 S' o$ P* m3 f - ...1 x7 Q6 J+ p2 @5 m+ H/ {
- An updated CRL has been created." y) X1 n: C# U {& K3 t# o
- CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
7 r4 ~# y- z; j& @6 L' u& Q% |
1 l, E# N& z5 _* M+ A- 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 - 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 - 3 r2 V; c2 ]% B* r% I; d: c! `6 @
- Finished! #最终看到Finished时表示安装完毕
2 G% ?, w: k8 H5 d2 e+ Y - ) X; k& h7 V6 z5 D+ Q
- Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
9 h& A- w+ f0 \+ a- g( C* Y7 [ - 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
- # cat /etc/openvpn/userfile.sh) l( q9 \! Q) ]# r% Y+ w* ]" e. f
- guoew guoew123# f. e2 T& x* W5 |5 j e& L
- 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- Looks like OpenVPN is already installed.2 E# X5 d5 O% q9 X" D; N
- ! T+ D t" j8 G% K: v' g: S9 p
- What do you want to do?3 n! s- p- C, V) U
- 1) Add a new user0 t% a+ ^& t: R0 z* b! ?
- 2) Revoke an existing user
7 X+ r4 W# t# T/ M+ g$ g5 w - 3) Remove OpenVPN
2 t% D ^# o# ]( Z - 4) Exit# }' O! G' i" q) p" G& f* O
- 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 |
|