易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 381|回复: 6
收起左侧

Centos8.5系统安装OpenVPN-超详细

[复制链接]
发表于 2026-1-17 13:18:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
Centos8.5系统安装OpenVPN-超详细
( X7 l' W8 i* N- O) h# J3 Z
9 m0 E: Q3 v% B" q$ z/ x需求:公司外部员工需要访问内部办公网服务器,所以需要搭建一个vpn提供外部员工使用。2 a- D  u: g( A! Q  B+ ]: y

! H  d# L/ {; X! Z- N. y0 j2 N1: 环境+ b8 {/ f+ W5 H- N6 F: v) d
服务器系统:CentOS Linux release 8.5.21114 O7 j9 n. _' c% {4 L
服务器配置:不重要
2 o( e- ~; u& r* F服务器IP:
' K1 j* t% M+ q$ d4 r) y" Y& l) gOpenvpn服务器:: r/ I" v, _+ N6 X$ f) R7 h
外网:5 g  ]* |( l) P8 B
内网:
! R" {9 c. A3 n, U- e. \( B0 t内网测试服务器:  @/ K- X* s- K4 C3 {- T
openvpn客户端服务器网段:10.10.10.0/22  Y# c; \) L8 U7 u
OpenVpn版本:openvpn-2.6.17
" A4 M- E9 U1 P$ beasy-rsa版本:3.0.88 ~& Z$ T: S( T; `

( y2 E, Q1 p4 p安装包存放的路径:/usr/src/install/
( p, C( w8 _0 M9 c2 x( b程序安装目录:/data/openvpn& @$ B6 i1 v& F4 ^" l

( r' L. a& t. I. c& ?备注:/ x3 v2 P% I; g1 _( f( @1 ~
root# 代表在root用户下执行的命令! W$ e7 k5 Q2 e9 U! ?
$ 代表是在普通用户下执行的命令$ i9 l! f2 w. S: _6 V: l
# 单个#号代表注释
! d/ S" \! M. A) M9 e' }* Z4 m5 h
$ m( I5 h* t: ?* ?' f0 x7 K5 p) }7 G3 h* \! U6 Q# E+ g+ f3 D
2:安装步骤
; p% S! R. O2 E2 a* U: O) _) ]2 x2.1 准备工作
' ?' [6 B( H: ^" C8 {(以下所有操作均在Openvpn服务器操作)
3 ~' g  X1 E2 y0 s8 e) `, a# 关闭防火墙
' s* E% g/ f8 N9 Y% j, B1 Froot# systemctl stop firewalld
8 M" f( l# v# _. M3 ?0 c3 S% kroot# systemctl disable firewalld+ M/ A. z0 t$ D) L2 d; c  J

6 \6 |( P, E, ~+ M9 j0 e& A4 {# 关闭selinux" J7 q0 r: M6 Z
root# sed -i 's/enforcing/disabled/' /etc/selinux/config
2 \$ N- N  S2 Z6 W/ Lroot# setenforce 0
% ?  _/ ]! _1 R- d9 f- {" i
) H- v2 N+ X6 q! H0 h; M4 q0 a# 安装依赖
8 M7 @8 @, f2 T- x8 p+ rroot# yum install -y vim wget lrzsz gcc-c++ openssl openssl-devel net-tools lzo lzo-devel pam pam-devel
! R" c$ s  x" w# m3 {9 h" Z! t$ _" ?# ^5 {5 E
# 下载安装包1 c* Y" v/ H. E  ^3 b
root# mkdir /tmp/install
  c  o6 e% {( nroot# cd /tmp/install* ^( ^6 @3 o/ r( `& `. m' u, b  R
root# wget https://swupdate.openvpn.org/com ... penvpn-2.5.6.tar.gz
+ v4 T1 Z1 W8 _root# wget https://github.com/OpenVPN/easy- ... 8/EasyRSA-3.0.8.tgz' a1 J1 p" B; A5 C

( q2 }. a2 h" M% D
+ s1 m! l2 u. \* p2.2 安装OpenVpn和EasyRSA5 d4 V! d3 A1 u! Q; Z; Z9 f$ c
#1)安装OpenVpn
; ]% g! Y( h9 j' O# oroot# cd /tmp/install$ O3 I! |2 S  e

9 _/ }5 p: l; k6 A4 a#创建目录
% M, D* L! D* P4 g3 R: Z$ h, Aroot# mkdir /data
% j; x% \$ ?* @: `' R
6 r& N( a% k, N1 {#解压缩. H" `6 ^% L6 O: z7 z
root# tar -zxvf openvpn-2.6.17.tar.gz
# J+ }: u! o& Q2 E" C* C+ h! L+ y* b6 N8 V7 N. L6 x
' L1 _- T* i9 M9 h/ m1 d2 B8 q; l
dnf install -y   autoconf   automake libtool  pkgconfig  gcc  gcc-c++  make  openssl-devel  lzo-devel   pam-devel  iproute lz4-devel python3-docutils libnl3-devel  pkgconf-pkg-config libcap-ng-devel
/ e3 F6 Z9 N) K2 V7 ?! M. |5 @0 P! c. N  A: p
root# cd openvpn-2.6.17
+ M8 x8 ?) t$ Z- F4 }9 U' b
! j! \8 \  h( K% c! h9 S: L7 i
9 n- {1 c+ d! \& V( D; O2 e生成configure文件:# z4 O# g  _3 v* D5 X2 D
1 J/ R6 }& G& [+ O& Z$ d
# autoreconf -fi. v# A+ w, c% I4 t
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, '.'.) T) h7 k4 f6 Q8 n" B& T
libtoolize: copying file './ltmain.sh'
7 }# D/ I5 L1 f% o. vlibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.; C! F5 C% b) x. A
libtoolize: copying file 'm4/libtool.m4'
5 U% l3 L+ h  t' p& U+ Rlibtoolize: copying file 'm4/ltoptions.m4'3 G& F4 ?6 N7 ?6 G- Z
libtoolize: copying file 'm4/ltsugar.m4'0 Q) o* @. r; o- f
libtoolize: copying file 'm4/ltversion.m4'
' f7 V  |, a! z9 O/ ~( n+ [libtoolize: copying file 'm4/lt~obsolete.m4'" l% z3 W, @1 R  Z- ]$ D3 f" H# Z
libtoolize: Remember to add 'LT_INIT' to configure.ac.3 c2 _5 t: r# G2 z# V
configure.ac:74: installing './compile'
0 B3 V) e, \5 Z1 v9 q* u6 |configure.ac:73: installing './config.guess'
# G, u. w- J7 ]6 h* e& V5 oconfigure.ac:73: installing './config.sub'2 ~& Y8 e5 t! p9 g
configure.ac:72: installing './install-sh'
( X) _* ?! k7 V; d; W. Fconfigure.ac:72: installing './missing'
4 K: _+ Z# d5 Z9 W" ]" p4 r2 dsrc/compat/Makefile.am: installing './depcomp'. T+ b5 P' W& y; @( e" i

) }  t4 Z8 ~( k9 x6 X2 R  q$ w) v7 E, X) e+ _* y
dnf install -y libnl-3-dev  pkgconf-pkg-config
# `9 k$ t2 V. Y, l, N5 v3 Z5 ^, m4 R" ]1 d  ~# O. \
#--prefix= 后面路径是安装openvpn到那个文件路径下* K  D& ~3 Y0 y3 k4 [5 T& e. ^
root# ./configure --prefix=/data/openvpn/
) P$ X+ G% X9 B' b4 M' d. u" ?
& g0 c# _+ n+ e3 d6 B9 M#编译& B1 l! t3 w$ ]3 {, K% J
root# make && make install
! E) u4 O9 L* c2 V# r/ U& n3 `+ }. x) v) _$ j- A6 b$ d. F
#添加openvpn的环境变量1 O6 j5 m3 A8 J" _+ K
root# echo -e "PATH=\$PATH:/data/openvpn/sbin" >/etc/profile.d/openvpn256.sh- {( j4 j" b6 C; l; I. F
) b$ O: J7 ]4 E* c
#加载环境变量
5 v. X1 R/ @  p  E9 p5 Eroot# source /etc/profile5 B8 b7 i; b" [
/ z2 |& c) I! Z7 L$ m5 x6 q7 l4 [
#执行下面的命令看看是否成功,出现以下内容表示成功' o  ^! l% _1 c( D% X* ~: V3 D2 d

: h! ?& g  k9 x: V) p0 Y# openvpn --version. [$ ]6 M2 B+ ^. O5 L% H
OpenVPN 2.6.17 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] [DCO]9 H" {$ O- ^0 w4 b) j3 z  y
library versions: OpenSSL 1.1.1k  FIPS 25 Mar 2021, LZO 2.08, `. Q4 I$ D' g6 f
DCO version: N/A4 h# l. j1 w/ O. h; H: i  A; o
Originally developed by James Yonan
1 i( H3 U5 X& G6 }9 d  nCopyright (C) 2002-2024 OpenVPN Inc <sales@openvpn.net>
6 a- U: P3 b+ J0 `, V3 R0 B' Q! ~Compile time defines: enable_async_push=no enable_comp_stub=no enable_crypto_ofb_cfb=yes enable_dco=auto enable_dco_arg=auto enable_debug=yes enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown enable_fast_install=yes enable_fragment=yes enable_iproute2=no enable_libtool_lock=yes enable_lz4=yes enable_lzo=yes enable_management=yes enable_pam_dlopen=no enable_pedantic=no enable_pkcs11=no enable_plugin_auth_pam=yes enable_plugin_down_root=yes enable_plugins=yes enable_port_share=yes enable_selinux=no enable_shared=yes enable_shared_with_static_runtimes=no enable_small=no enable_static=yes enable_strict=no enable_strict_options=no enable_systemd=no enable_werror=no enable_win32_dll=yes enable_wolfssl_options_h=yes enable_x509_alt_username=no with_aix_soname=aix with_crypto_library=openssl with_gnu_ld=yes with_mem_check=no with_openssl_engine=auto with_sysroot=no- b2 c6 x# }; m8 {
/ g9 F: P+ E* o, ~8 r2 c- R" V
#2)安装EasyRSA
% f  W7 i, Y1 A3 q' Iroot# cd /tmp/install( I. c# R5 T! f: w) s6 P+ M
root# tar -zxvf easy-rsa-3.2.2.tar.gz5 [) d5 k. `4 A! B& ^6 K, N
# cp -r easy-rsa-3.2.2 /data/easyRSA-3.3.2
, B% @  l2 R. M9 R* b; R1 Q- f, t- n# S) C7 J

" D& l8 l% U) F: Z0 ^( u2.3 服务端配置& Z0 n4 x! l5 v- s8 y
2.3.1 准备CA签发机构环境2 \( y5 g0 r0 S2 E" l
#拷贝EasyRSA
3 `" j/ q& d- f' d8 s6 u$ W! Zroot# cp -r /data/EasyRSA /data/openvpn/easy-rsa-server
8 w5 X8 x5 }3 O  vcp -r /data/easyRSA-3.3.2/ /data/openvpn/easy-rsa-server
9 \. z6 z, C$ r  P4 x6 w. M' j3 t
% X* c6 y- B% C3 F
; f5 ~8 Q' `0 Broot# cd /data/openvpn/easy-rsa-server
# k$ u9 [; L1 T5 X: {cd /data/openvpn/easy-rsa-server/easyrsa3
  x1 k. b, X- K3 ^( d; H* r
6 z! Z& S; |4 j9 D#准备签发证书的默认变量文件
' C) k9 W& [6 D( q8 Lroot# egrep -v "^$|^#" vars.example >vars
3 e6 H  y& |$ o4 }* ^6 _5 k! S8 ^7 X( [$ v' O: d% w
[root@openvpn easyrsa3]# egrep -v "^$|^#" vars.example > vars
. b1 e% @. p! f9 Q7 R1 i1 e[root@openvpn easyrsa3]# cat vars8 d0 t# {) G3 \9 I9 l6 d
if [ -z "$EASYRSA_CALLER" ]; then# u4 v+ @/ @: ]8 [  t6 F% O8 g
        echo "You appear to be sourcing an Easy-RSA *vars* file. This is" >&2
" P( ?0 Y1 {2 c7 H3 d- n        echo "no longer necessary and is disallowed. See the section called" >&24 k8 _" v: q7 c* v, C* F0 x' [
        echo "*How to use this file* near the top comments for more details." >&2
: W: C3 o1 M& a& H6 W1 h9 D  j5 L        return 1
7 f+ _7 ^1 P# k$ k5 _! ]/ k4 dfi0 X2 q" v5 [, P
0 k- r$ ?1 S; o( C2 m
4 \4 ~9 q8 ^2 x' ]& R$ f
% I; w2 j6 F0 \7 u! a2 c6 {
#编辑vars文件,在最后一行增加以下内容
0 z1 |# M7 j4 N% u* j! p% Droot# vim vars
- w7 `0 `9 V) T8 U5 k- ~#添加参数,设置CA证书有效期为100年(日期可以你自己决定设置多长)
9 L5 W* @" i, c3 yset_var EASYRSA_CA_EXPIRE 36500+ n$ T* `1 l: g$ T: R1 k
#添加参数,设置服务器证书为10年1 T8 b" B' z0 t5 `9 U! T. _( d
set_var EASYRSA_CERT_EXPIRE 3650
: h" V) H) M+ G$ S* I. u: \9 e5 U) s( c6 y% ?% V) P* j0 D

, [' }* b1 ?" U7 ?; o4 V. Z查看配置vars的内容:* `/ J5 R! O! C

0 p$ [: H: O; e1 H. S! \- W. A  F. ?1 r, i) l9 M- M
if [ -z "$EASYRSA_CALLER" ]; then1 p. m& a: {; u5 U- M# m
        echo "You appear to be sourcing an Easy-RSA 'vars' file." >&2" C# n% o, q2 T( W: b
        echo "This is no longer necessary and is disallowed. See the section called" >&2, C7 D- A8 |2 w! y4 O" q, c
        echo "'How to use this file' near the top comments for more details." >&2
3 w2 a* a; t& }6 _: e        return 1
3 x6 V# y6 O& \1 S- X( l/ g4 afi
9 v2 b7 z1 ?7 I. q. t8 T* r, Kset_var EASYRSA_CA_EXPIRE 36500
8 f1 U% L# R0 h( T1 d: Q) M2 qset_var EASYRSA_CERT_EXPIRE 7300
+ V; k0 x% T6 w3 M9 H
% w  }' ~5 F) }8 N) G3 Y* q  p% T2 p% V6 b* h
2.3.2 创建CA机构与服务器证书5 I. _, A" A, D, C' s* }5 D
#1)创建CA机构
0 A: x4 ?; p6 a- Lroot# cd /data/openvpn/easy-rsa-server
9 {/ V  K0 h5 C' A1 r9 rcd /data/openvpn/easy-rsa-server/easyrsa3# }& R% H  v1 o
' X8 W: A. q3 W
#初始化,执行此命令会生成pki目录: a! ^3 [. _  h2 {3 \6 b8 f

( f0 @1 I$ w0 g' {7 L. T( T[root@openvpn easyrsa3]# ls
! C; s8 O8 |- _: K: |easyrsa  openssl-easyrsa.cnf  vars  vars.example  x509-types
/ x$ U" O9 z# I9 A" m[root@openvpn easyrsa3]# ./easyrsa init-pki% [- _2 V# W  T! v+ L3 Q  w6 X. ~  ~
Using Easy-RSA 'vars' configuration:
2 z8 {$ N9 A9 Q  \, Y, {1 s* /data/openvpn/easy-rsa-server/easyrsa3/vars( f5 E, q" p& m% L9 `3 j
* j8 S4 s4 _; a4 q) _% j# U7 @
Notice
% S' r5 g* d; W& ~' @* L  j------
7 K. m! i: u# q, f3 r5 ]'init-pki' complete; you may now create a CA or requests.; g/ k' V& Q; Y3 h, X5 E) t0 M
0 S- D8 Y3 k7 S& u) q5 s
Your newly created PKI dir is:
4 K; s* U% }6 C7 t, C* /data/openvpn/easy-rsa-server/easyrsa3/pki/ E; h% d" b, W& U: T: u
3 F: p2 ]& b7 h6 f  S, w
Using Easy-RSA configuration:
5 w; r6 G5 `( V# g0 _, W* /data/openvpn/easy-rsa-server/easyrsa3/vars
( Y3 z3 ^8 D- y3 y, w[root@openvpn easyrsa3]# ls6 ]8 g! O" C0 l9 P" X6 Q4 L
easyrsa  openssl-easyrsa.cnf  pki  vars  vars.example  x509-types! C5 F, P8 Z" f, V- u0 v  W: k

6 i7 i3 T  \" E; F0 ^3 B5 a% I9 U6 y; G6 `3 J) C
) P" W9 V- a2 v& Y2 d
#创建CA机构,nopass代表不需要密码的意思2 x# ~0 Y7 C7 U' f8 W( O7 G
root# ./easyrsa build-ca nopass
: c4 [1 d* r( w" _
7 b1 y4 w# A6 ~+ Q& ^
# ^4 b" L7 B# x. @8 P) y" X( Q4 g: v* R4 I6 W# b
[root@openvpn easyrsa3]# ./easyrsa build-ca nopass
4 S4 ~+ X5 z- Y- xUsing Easy-RSA 'vars' configuration:( u. X$ C  r: z/ R
* /data/openvpn/easy-rsa-server/easyrsa3/vars* k: ], V0 \8 Q# t1 q
..+++++
3 T8 X% j8 h  L, g( g! I8 e- D.........+++++
- X  F- n+ v; Q; I; [You are about to be asked to enter information that will be incorporated
3 W9 ^* f0 X5 w3 p4 q/ h3 ~9 G9 r- Linto your certificate request.
1 o' u- d: T. ^What you are about to enter is what is called a Distinguished Name or a DN.
" ?- j0 r" {* M7 QThere are quite a few fields but you can leave some blank
6 G! T+ u) a3 d: J, W& y  SFor some fields there will be a default value,' G- t# ^1 @" S9 U/ h3 n. H1 F6 h
If you enter '.', the field will be left blank.
2 I2 ?' o& C7 |, t4 V' A* }+ }/ L-----
' P0 E) r, f2 N/ `9 J% E, TCommon Name (eg: your user, host, or server name) [Easy-RSA CA]:jckj
& f  q  w# ?. N$ A
6 x( {$ O5 _) k" L1 I) pNotice3 R' f+ c! V0 D6 m' T
------
0 N, G2 E9 Z9 j6 {$ gCA creation complete. Your new CA certificate is at:
+ X4 k% k3 e& B/ m) c; x9 R. C* /data/openvpn/easy-rsa-server/easyrsa3/pki/ca.crt
9 j% w9 W& V( d) J. X
# l* ?8 {1 L$ z: S- Q! XCreate an OpenVPN TLS-AUTH|TLS-CRYPT-V1 key now: See 'help gen-tls'
! _0 h1 ?! o# }7 Y8 o( c: \: C+ d# b0 X' L8 P
Build-ca completed successfully.
8 R  i  r  m+ h4 K) ^3 l: i# L6 r( K
+ @3 \' b( N9 A- Y' X
0 q7 V! ~  I; b$ W& R2 ^3 W% g' K9 d
#执行创建ca机构成功的话,会出现下面的这个ca.crt文件& A4 x6 x3 b# ]2 S
Your new CA certificate file for publishing is at:
' M( Z  O- t4 G/ {/data/openvpn/easy-rsa-server/pki/ca.crt+ p4 J% [3 F" B& a% N1 Z

" I/ V& v; D" K0 C7 V0 a#CA证书文件
* [& W( d( w$ X9 J7 c3 a+ i; a6 |8 u
[root@openvpn easyrsa3]# ls -l /data/openvpn/easy-rsa-server/easyrsa3/pki/ca.crt 0 V, r5 m. y/ {" G" i2 L
-rw-------. 1 root root 1176 Jan 17 12:19 /data/openvpn/easy-rsa-server/easyrsa3/pki/ca.crt
9 @8 }, ?& C3 L9 M
- f' \9 f: ^% [
. v/ r0 V4 Y+ F#CA秘钥文件* q  {$ I' _2 v2 R( S

8 d  Q3 ~- l  ?  h' S' Z0 G5 Q[root@openvpn easyrsa3]# ls -l /data/openvpn/easy-rsa-server/easyrsa3/pki/private/ca.key 1 H+ F3 a% ~7 r/ K
-rw-------. 1 root root 1704 Jan 17 12:17 /data/openvpn/easy-rsa-server/easyrsa3/pki/private/ca.key
5 q; b' L! K4 M" R9 [
( c" y) E+ e9 |* b5 `5 q( d* ?$ P& p7 I) {. B4 L3 q7 Z; b9 S
#2)创建服务端证书
) T; _/ _0 ]  J. Vroot# cd /data/openvpn/easy-rsa-server) }2 R. Q& w* I0 _: r
cd /data/openvpn/easy-rsa-server/easyrsa39 d+ r5 v/ @( c+ Z
#创建服务端证书申请文件,openvpnserver为了区别参数标识,我这里设置为openvpnserver,如果你自己安装的话可以使用默认的server 这个名称
! a, M* e' k9 m$ ^9 Yroot# ./easyrsa gen-req openvpnserver nopass2 n* d7 w! v2 H, L9 \9 E, l1 \% h2 O
" _: N) H/ F$ `9 o4 h9 |; U. T
2 Y6 K- A; k( e& i! i# {7 Z3 |
0 y" o; g6 O: w

$ l- j& V8 B2 T8 ]7 ?[root@openvpn easyrsa3]# ./easyrsa gen-req openvpnserver nopass
9 K" _1 `$ u' lUsing Easy-RSA 'vars' configuration:
4 b% y% k5 t1 A, z3 W  F5 E* /data/openvpn/easy-rsa-server/easyrsa3/vars: k6 I6 U) ~" T
Generating a RSA private key% Z* G7 E: ?/ P2 l+ C
.............................+++++; U8 K/ j9 W, g$ @1 h2 J- ~
.................................................................+++++& o* t4 W. L9 k0 k  X0 ?
writing new private key to '/data/openvpn/easy-rsa-server/easyrsa3/pki/253f5ec5/temp.2.1'
6 X& G# Z0 r# h' ?-----
. O) I' \- V. C- L7 z% uYou are about to be asked to enter information that will be incorporated
* G4 z; X+ h4 D0 W% f0 c; h8 Ointo your certificate request.5 q( ?; P4 W2 r, H
What you are about to enter is what is called a Distinguished Name or a DN.) C* r5 z, ~. G: b  d1 @; @
There are quite a few fields but you can leave some blank
" Q3 P5 U! e4 nFor some fields there will be a default value,
' _) r2 {0 @5 e* ~9 EIf you enter '.', the field will be left blank.1 e$ ^" ?  z* {! ~2 P6 k0 ?" j
-----
: W. X3 p9 o' p! GCommon Name (eg: your user, host, or server name) [openvpnserver]: 回车/ I! k# c- a- c3 }* n& C% Q- v* {

8 t; ]' _& k+ D- F$ hNotice: \4 x/ a: _* }' J! i2 E
------
6 E& M( p8 \" y. Q( N$ i1 L) qPrivate-Key and Public-Certificate-Request files created." V. h' L# s2 y) T
Your files are:
# S; h$ g5 q% m# _* O0 v* req: /data/openvpn/easy-rsa-server/easyrsa3/pki/reqs/openvpnserver.req9 k8 ?, `8 m6 t
* key: /data/openvpn/easy-rsa-server/easyrsa3/pki/private/openvpnserver.key6 b- e+ N8 E# ?" U  }% G
- ]( h3 h/ x/ \" D1 ]* i
" `; \9 {# g& J
' A: v0 y  C8 h& ^- s& d! m

; b; @( \$ |- K#默认回车就行
$ b- z2 q$ |. c! c( Z2 W
Common Name (eg: your user, host, or server name) [openvpnserver]:  z% e4 q" _( c' q1 o" e
Keypair and certificate request completed. Your files are:
7 b5 D  B9 b& o- ~$ ]  e* j
% F3 ^8 h& M2 [5 I* i( p
& F3 ?& I/ r+ y! L! B* P+ g. E# S5 O5 b. i9 L

% j/ x8 p* ~1 o#请求文件6 P& ?0 e2 p' j0 a$ h7 j$ G
req: /data/openvpn/easy-rsa-server/easyrsa3/pki/reqs/openvpnserver.req5 a- E( Z/ j8 [! E
#私钥文件# X3 {$ y9 K- `$ ^1 m8 z/ h
key: /data/openvpn/easy-rsa-server/easyrsa3/pki/private/openvpnserver.key
; M2 T! {. d! K( x8 ?' L; b- `7 g" |
#3)签发服务端证书
1 H' A' p0 B( V& ?7 C* |& f绿色部分不做:9 d! ~1 z  C5 I: S7 n
root# cd /data/openvpn/easy-rsa-server# T( j0 w" s+ t! _0 t( n6 ^
cd /data/openvpn/easy-rsa-server/easyrsa3
( P) B) u  K* T4 S$ s#这里的server是代表服务端意思,openvpnserver这个是上面我们创建的服务端证书的名称
; D* w7 V- h7 h# {' @! W! Froot# ./easyrsa sign server openvpnserver
) _, X5 }! A; G" o- l& e#输入yes& b# ?( ?5 z, p. D; a5 o
Type the word 'yes' to continue, or any other input to abort.
7 N4 C8 g$ D% q* ~% |" F8 x7 ?Confirm request details: yes3 o5 z3 o/ X- K: x* H" K: _# S+ d8 P
#服务端的证书文件
7 Y) `  I9 r; C% b9 gCertificate created at: /data/openvpn/easy-rsa-server/pki/issued/openvpnserver.crt
! f$ k3 O. w5 m7 W  `2 g
! e: F, U& k' K
0 m8 M3 N* [: M( p
: A) @( E+ I) K2 Z; X
[root@openvpn easyrsa3]#  ./easyrsa sign server openvpnserver4 v8 W+ N* t" }' o
Using Easy-RSA 'vars' configuration:; I+ W7 z/ t* ^
* /data/openvpn/easy-rsa-server/easyrsa3/vars) W; p5 r; h0 y: R2 X# Y# u
Please check over the details shown below for accuracy. Note that this request
5 E8 R; O' W0 ]5 ^5 a/ b# f# xhas not been cryptographically verified. Please be sure it came from a trusted
2 X2 w1 {0 Y. e7 m) Bsource or that you have verified the request checksum with the sender.% K$ Q' G/ b& R
You are about to sign the following certificate:
3 x, i% P) F  X% K5 ]$ h. T) u! t' n! ]7 Y* C' y5 ]; _+ z. _
  Requested CN:     'openvpnserver'
) ?* F  O4 ~& r$ \& R, L- h! I  Requested type:   'server'
, v, U; Y1 w1 e6 g% G  Valid for:        '365' days+ ?3 t+ w2 l2 Q) ^- ]& y2 {. @
2 E4 {0 Z, s6 `5 N! S5 J& t

  C' I9 ]- X0 }4 wsubject=# [) S; U! l6 c; }, m
    commonName                = openvpnserver6 ]! s) l4 U8 s8 l6 r# L' y  n
1 X: G' \6 Q% h
Type the word 'yes' to continue, or any other input to abort.5 a; l9 X1 ?4 K2 A4 _$ h& e
  Confirm requested details: yes* S8 d) [! H4 r  H

' d2 }: w1 z' WUsing configuration from /data/openvpn/easy-rsa-server/easyrsa3/pki/774d5125/temp.1.1
: t9 E% C1 O" I- @2 QCheck that the request matches the signature2 k/ {0 C4 l9 d) f' s% n3 @( s. X5 d
Signature ok( Q/ L9 O/ x! b1 j
The Subject's Distinguished Name is as follows( }, e* I0 `/ R; U6 a% l5 ]
commonName            :ASN.1 12:'openvpnserver'/ Q  u- X2 J) W2 X+ I6 x
Certificate is to be certified until Jan 17 04:25:48 2027 GMT (365 days)
0 `2 d, S( Y4 Y  m: ^, B! l; |* J: T. J2 P9 F# {( c1 `: T
Write out database with 1 new entries
4 D5 ]" E1 @, i3 `' FData Base Updated# V3 `( Y' U1 W8 S4 I- k

0 ~5 P9 }+ `% T* g4 Q! INotice
4 s# y8 `8 s/ o0 n, j; E------
3 {& I! c6 x& P% LInline file created:; F9 f0 \) J: u* X
* /data/openvpn/easy-rsa-server/easyrsa3/pki/inline/private/openvpnserver.inline
6 U. [3 t. h' I; F
" q8 B: e1 ?" u. c) m$ y( m; `; E7 L# U+ O4 `8 d
Notice1 \8 g8 A/ Y( W/ ^& b
------
- J7 ?0 Y3 B  C6 t5 uCertificate created at:
" ]/ ^3 q* z" u$ Q7 z) w4 d# v* /data/openvpn/easy-rsa-server/easyrsa3/pki/issued/openvpnserver.crt! J1 \3 G' P; F! ~6 P/ u
$ ^4 j+ u- x- r9 L* h
% ~) Q7 |' j, b. d: [$ O, b

6 y7 A& h" O) V( D2 V8 ]#4)创建交互秘钥
# s9 I1 n0 H( Y* a3 F2 oroot# cd /data/openvpn/easy-rsa-server
1 d- B# V% r5 J/ Q7 w1 ?$ Q8 Dcd /data/openvpn/easy-rsa-server/easyrsa3: u. p* W; T$ O0 E$ N- P+ L
root# ./easyrsa gen-dh
! k, L8 q  {1 a$ _1 ?DH parameters of size 2048 created at /data/openvpn/easy-rsa-server/pki/dh.pem1 L3 ^1 y5 l) c
+ S$ J; T" A6 B# ^8 {* w

/ W! C$ N8 T" w  k4 E[root@openvpn easyrsa3]# ./easyrsa gen-dh
' P# b' X3 d2 ^, v% JUsing Easy-RSA 'vars' configuration:9 T7 `/ p5 H- j2 P  h3 S
* /data/openvpn/easy-rsa-server/easyrsa3/vars. [4 \6 b, x6 A/ C+ i/ _
Generating DH parameters, 2048 bit long safe prime, generator 2$ N' L" l- S+ V$ L) [/ w
This is going to take a long time
/ ?- a8 |  s. C............................................................................................+...........+..............................................+.....................................+.................................+....................................................+.........................................................................................................+...................+.................................................................................................................................................................................+......................................................+.............................................................................+..............................................................................+...............................................................................................................+........................................+....................................+............................................+.............................................................................................+........................................................................................................++*++*++*++*
2 Z+ M/ d1 q3 J) H. y+ X: q9 xDH parameters appear to be ok.
2 k& t  W% |+ [2 I2 T: u* _+ T
8 |( c! P: l' R5 J$ qNotice, [: u: W/ e% p/ L5 q9 X
------0 V+ f8 C8 V! ^% I5 O% R
0 Y. H8 d. @2 I( |& t+ |* X1 u
DH parameters of size 2048 created at:" v. y0 ?8 S7 z$ L) h
* /data/openvpn/easy-rsa-server/easyrsa3/pki/dh.pem+ r6 o: L3 ]7 Q; P2 q7 q: u! d9 j
' s5 K; y% i. j: u; G6 A4 F9 o

: I- _& {: P1 b# N# M$ o
( h5 @$ v) e8 T* D# V$ k+ f5 X) z#5) 启用安全增强配置
+ w% h4 ^) K7 C! ]' L" \root# cd /data/openvpn/easy-rsa-server
. x1 i! G" c% G& bcd /data/openvpn/easy-rsa-server/easyrsa3
& S) f: y& D! |/ h& v% E1 H
* Y3 ]4 S  w3 |& Zroot# openvpn --genkey tls-auth ta.key/ J, |, E7 J5 Y- `& |- g

/ }* u4 P9 d1 L& n2 r/ g, v9 r4 w( p9 h0 D3 }) c3 V" x4 b% M
[root@openvpn easyrsa3]# openvpn --genkey tls-auth ta.key: w  [/ o( ?4 X
[root@openvpn easyrsa3]# ls. z& N  V6 z4 j
easyrsa  openssl-easyrsa.cnf  pki  ta.key  vars  vars.example  x509-types
% h+ \. K# m7 e( n- Q4 t& Q9 S: B[root@openvpn easyrsa3]# / m$ o; Q6 v1 Q  g9 Q3 c- X) P
7 e3 ]' y1 ?3 O' g) X7 R

& {8 @9 C7 b! d) ]
) k" h1 {9 V- \$ B2.3.3 OpenVPN服务端配置
! A6 c' |- ^3 t; f( Q& N#创建openvpn用户
( v" N& K% ^. r! b% g3 B8 ^root# groupadd openvpn
* k( ^+ ?% k7 i: U' t8 V; D2 troot# useradd -M -s /sbin/nologin -g openvpn openvpn
8 h  ~0 C! X% f) J9 n4 M/ j9 v+ t- o8 A% s# ?% ]0 q( d% Z# }
[root@localhost easy-rsa-server]# groupadd openvpn
1 m' V; f, A( X4 V. D- ?! i  ]6 ^[root@localhost easy-rsa-server]# useradd -M -s /sbin/nologin -g openvpn openvpn
, w3 t" L0 T' }- x0 T
) O$ e/ ?/ O+ x3 ~( C, e3 O9 c5 F" Z$ f4 b) y7 d
# 创建证书存放目录2 n; B9 w* R: I/ G  Y" I9 O
root# mkdir /data/openvpn/certificate
5 _& x) a9 z" w' p
5 j/ f# W0 Q0 J  h- \: q5 m( }# X% C5 }# 创建日志存放目录
+ ^: m; Q- r8 ^) l2 F/ yroot# mkdir /data/openvpn/logs7 s0 r# H5 ^) \8 A1 \% N% {) t
root# chown openvpn. /data/openvpn/logs& {2 q9 ~* @! y0 w4 Y; R+ _0 s5 p) l

3 b4 _0 z6 F9 R6 }
; ?" P: W8 z  Z2 g[root@localhost logs]# chown -R openvpn. /data/openvpn/logs/  O/ Q- C- N( j& E" Q

" [0 w. y# [% u1 W) x+ ]3 K
6 }: }9 l. J! d. p# 将服务端证书秘钥和交互秘钥复制到certificate目录
- D! o& \* H' K8 l% A- |, }( t& v# N2 p2 _9 u
[root@openvpn easyrsa3]# cp /data/openvpn/easy-rsa-server/easyrsa3/pki/ca.crt /data/openvpn/certificate/' Y' U# L  @$ d/ P
[root@openvpn easyrsa3]# cp /data/openvpn/easy-rsa-server/easyrsa3/pki/issued/openvpnserver.crt /data/openvpn/certificate/) a8 A  k$ d% w
[root@openvpn easyrsa3]# cp /data/openvpn/easy-rsa-server/easyrsa3/pki/private/openvpnserver.key /data/openvpn/certificate/
4 ^3 ?. b1 `2 L7 M" l0 E/ `[root@openvpn easyrsa3]# cp /data/openvpn/easy-rsa-server/easyrsa3/pki/dh.pem /data/openvpn/certificate/6 {& {8 B! Y! ~1 Y! M
[root@openvpn easyrsa3]# cp /data/openvpn/easy-rsa-server/easyrsa3/ta.key /data/openvpn/certificate/
7 K: B4 ]* h1 Y& e
* N: J* w/ @  l" h( x( A: D#添加配置文件
6 E1 a3 C7 A& n6 a9 @$ X2 Aroot# cd /data/openvpn/
* u2 `* M+ L7 Groot# vim /data/openvpn/server.conf# B5 N- l' [' P1 C' i8 z, Q
#__server.conf—stat___
1 @. a# ]" M1 `; d* \( t* c#端口5 T/ M+ J& g0 K1 [
port 1195/ [1 }* d/ w% w) q8 W
#协议/ N. ]: a; n: C# Z
proto tcp
' I* N1 U7 |+ R+ H6 r1 I) T# edev tun8 Y9 \2 z( N5 D
#ca证书文件" ?& w) [3 b7 ~4 o3 v% [
ca /data/openvpn/certificate/ca.crt
/ H1 `: P. d/ U0 q) z; ]#服务端证书文件
5 i. e) s% J: r, e% Acert /data/openvpn/certificate/openvpnserver.crt
2 J, h- S6 [4 |#服务端私钥文件
0 ^0 j3 x' R5 B2 Y( F/ I' ekey /data/openvpn/certificate/openvpnserver.key
9 f0 T$ i. y( M+ e# X4 q8 k7 [#交换秘钥文件- N7 \2 p2 G9 S0 a
dh /data/openvpn/certificate/dh.pem
5 b! c" d/ I( N#安全增强文件,0是服务端,1是客户端
  w# O0 V; @2 p! k. B% E9 |tls-auth /data/openvpn/certificate/ta.key 0
" v6 h* a6 w; e. i! N8 b$ L2 C#分配客户端IP的网段,不能和服务器一个网段,不能冲突
# G- `6 U( d; e7 H5 k7 mserver 10.8.0.0 255.255.255.07 P# Y2 b, q7 e: G
#运行通讯的内网路由,可以多条  m) ~& N: F$ V& D5 w# d6 m
push "route 192.168.0.0 255.255.255.0"
6 G9 k! y5 l( g( I9 B  ^( q# Z$ n/ ?. d. [0 V: z1 W- S
push "route 192.168.6.0 255.255.255.0"
" u& A* A" p" N' i( L# v" upush "route 172.30.1.0 255.255.252.0"- f$ V0 x$ z5 l* o
#会话检测,每十秒测试一下,超过120秒没回应就认为对方down
$ a) e/ j! h  n/ y8 I/ ukeepalive 10 1205 ?" `1 R  r5 h5 r
#加密算法
" f" S6 t4 n  `! }* p# a3 s+ Ycipher AES-256-CBC
* W+ Z9 f7 T$ {+ P1 F/ v& K#压缩算法
9 j' X) x  Q; x, @compress lz4-v2
; ^( ~" z& H. r#推送客户端使用lz4-v2算法4 m6 L0 t, p1 o, T
push "compress lz4-v2"
1 S# a' {0 H2 ^+ m! J#最大客户端数
/ r$ \; M8 R+ Z- l( q8 umax-clients 100) _8 |' R- _3 k: w6 `5 F4 ]
#运行openvpn的用户和用户组- M* I8 K$ E: F7 U1 |3 F5 h0 ^
user openvpn, T+ O  Z6 s8 {4 M
group openvpn
( P. L  b3 h7 n/ ]1 v: X: q2 a9 C#状态日志
6 P7 L; ?8 t# t9 _status /data/openvpn/logs/openvpn-status.log$ F) ~0 F4 c+ @
log-append /data/openvpn/logs/openvpn.log
7 Q1 w2 ]3 Y6 }# A+ ~#日志级别
: A1 ?1 v, q3 }2 C0 _- Nverb 3+ ?& A6 q; j( F& s% T6 H' l% |
mute 20* U) f. v+ ^( ^5 N- e! j
#__server.conf—end___2 v; r4 @3 X1 h1 m9 ~5 ]

$ G. O7 e6 m8 y$ M. U% W9 R" V  @' R$ l, Q$ p' j
#内核转发规则
8 t2 G0 I" Z6 }7 d& d) f1 t6 Iroot# echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf4 h$ T0 I2 T7 R, [: ~
root# sysctl -p
6 ^5 s# y, X; S5 D/ E+ r' f
5 ^* K2 J1 d9 q5 ^#iptablesNAT规则
" m1 x" f* O, h. N0 N6 @#这里的ip就是server.conf 中的server 10.10.10.0 255.255.252.0 ;添加转发规则到开机启动项
, P# h' h+ L: Z+ ?7 v! Q: v: n1 Hroot#echo 'iptables -t nat -A POSTROUTING -s 10.10.10.0/22 -j MASQUERADE' >> /etc/rc.d/rc.local
5 L! q% l+ D3 sroot#echo 'iptables -t nat -A POSTROUTING -s 172.30.1.0/22 -j MASQUERADE' >> /etc/rc.d/rc.local6 C& m5 ?6 ^+ t
root# chmod +x /etc/rc.d/rc.local
' Y0 H+ r* [$ G. m+ h& nroot# /etc/rc.d/rc.local% Z8 B+ ?/ {5 O# l/ U

$ m3 s8 R5 w$ g$ X7 _% @2 l% i3 F. W$ ~! f
上面的可以暂时不执行,都使用firewall-cmd方式添加 :                        8 u3 w5 i1 e5 Z- R  U$ C3 u& Y  Y/ }
firewall-cmd --permanent --zone=public --add-interface=tun0
2 g0 g- ?. B' d& G# o8 V5 Vfirewall-cmd --permanent --zone=public --add-masquerade0 b' N% l# |3 I3 {# z8 ^  E
firewall-cmd --permanent --add-forward7 ^+ V  M% ?1 D- L
/ L' {( _7 A) I  p4 i" U! T, r添加转发规则。允许可通行。
4 G4 s$ p" J: s; F6 ]
2 ^  g3 C" W& \: X, \1 M  m& E, I' j8 x3 L: I
$ Q: D6 E% |% E- s+ m+ i* B
2.3.4 启动OpenVPN
/ q& h9 `% ?% @8 p( I# 创建启动文件) \; y- a3 D2 I! O2 ?' N0 i
root# vim /etc/systemd/system/openvpn.service
+ }" ]& y5 G' [- }& i[Unit]
  C, H7 w& O2 A; yDescription=OpenVPN Server+ G/ U) x! ~+ |
After=network.target
7 p$ u/ D# @8 |) v* R0 ^After=syslog.target
+ P$ o, y; R8 H1 y- G" }' q, R% P0 B- _" |/ t
[Install]
# y' z& W% m6 @1 b! t' e! Y5 IWantedBy=multi-user.target
( G' [! S4 V$ f8 O2 h* @
0 E( _2 ]& j3 f! n. V% X! d) J. w[Service]
' a; p8 k! t3 f0 \6 i# GExecStart=/data/openvpn/sbin/openvpn --config /data/openvpn/server.conf2 N& A: s( ~& j5 [2 z4 l

/ x! N  R, u. w; N' ^
% B5 t4 H/ ^  |1 `4 |& K8 h#加载系统服务! f! F) I" O) [2 K! p  q1 r
root# systemctl daemon-reload
/ h& V2 x# r1 o2 K#开机启动
* |6 ^! e; C' O+ D' froot# systemctl enable openvpn.service
) Q3 e7 z" b6 t* q: w* z#启动服务
/ |! H7 ]" x, a( N6 h7 i, c6 h1 i9 e7 Uroot# systemctl start openvpn.service/ ?* X& v: h6 v: d
#查看服务运行状态3 h  Y; S0 C3 V, K) ^4 F& P
root# systemctl status openvpn.service! R. j# A' |0 t( k( Y% l

) c/ }2 C6 z9 d1 l" t2 ?0 ~. R  M( ^" P( d! I7 A  e
2.4 客户端文件配置5 X. E4 O8 a# m, U% J, I
2.4.1 准备客户端证书
/ K9 v  g' F9 ]0 R9 o$ I
#1)创建客户端申请证书
! U$ W, I2 F8 b
' I! n, A- U7 s0 C6 e3 U[root@openvpn data]# cp -r /data/easyRSA-3.3.2/ /data/openvpn/easy-rsa-client
) H7 ~% ?$ F8 J! P[root@openvpn data]# cd /data/openvpn/easy-rsa-client/easyrsa3/% K& ~8 e) _, r
[root@openvpn easyrsa3]# ls+ T: ?' |3 c  c$ q3 A
easyrsa  openssl-easyrsa.cnf  vars.example  x509-types
8 z9 z  @( {: `% s, n. r[root@openvpn easyrsa3]# % ?# I' V* R4 z) q+ e# H

" l, V$ m! o/ Q! i/ o! A+ V3 N# O  B3 i3 u8 ]- ?
5 X* m2 o, p( ^7 N3 J/ `
#初始化,执行此命令会生成pki目录
5 t8 y$ N9 S& `" proot# ./easyrsa init-pki
! z2 f2 e, r/ w- x# C/ X/ [- |* [: @+ L$ F. g- z' v0 k" u1 r
2 ~/ n. }. {6 s6 N+ `7 }
[root@openvpn easyrsa3]# ./easyrsa init-pki
9 K8 e8 |* Q* }
# Y# d, F, \2 W; [6 |/ JNotice6 H! C1 N/ a7 N. l9 Q0 }6 N
------
2 ~3 R0 I! V" b% ^3 v6 g9 n'init-pki' complete; you may now create a CA or requests.1 @  [. d+ h; p; |4 v' P

0 K1 L& s  C7 |# F2 j& ]- q/ IYour newly created PKI dir is:, F3 r6 W( A* E
* /data/openvpn/easy-rsa-client/easyrsa3/pki
7 S( w' Z4 b; y  p) L4 Z6 l0 n
4 c: T2 n1 k# I0 C, R8 [/ YUsing Easy-RSA configuration:
2 v, M! X$ M0 P7 Q5 U' G* undefined
5 P& z, u! n' \' X2 l2 Z
" n1 t' d; V2 b& ^& X- P& k0 C" J) H
* F8 e% N7 y" E# Y5 [#创建客户端申请证书,我这里用的是名字全拼
+ t# \; O, `$ B; y
4 |9 Z5 v9 M$ j& y+ l/ v( Z8 l9 ~

+ C$ n3 h* ~' S$ p[root@openvpn easyrsa3]# ./easyrsa gen-req longrui nopass* U  {% `1 q. j4 a3 x4 D5 j
Generating a RSA private key4 q/ G3 [3 {' O- s& q1 M
..+++++
' W( i+ y4 n+ }* |6 c7 N) X2 o.......+++++5 Z6 S- V8 \1 D' Y) q9 g: S
writing new private key to '/data/openvpn/easy-rsa-client/easyrsa3/pki/2f9b0fd7/temp.2.1', K* m! x! `% b: h; F6 P
-----
) W& I8 s: D$ _You are about to be asked to enter information that will be incorporated
  K8 M8 u# C1 L# t+ F+ f" o' Xinto your certificate request.
7 h& v" r5 x6 z# ?) v% t7 BWhat you are about to enter is what is called a Distinguished Name or a DN.
1 o0 r( @  B8 ^8 o1 [6 h* hThere are quite a few fields but you can leave some blank5 N2 J# P3 `1 K9 a
For some fields there will be a default value,+ z, D7 k; Y+ B
If you enter '.', the field will be left blank.8 F. G+ r! U% Y0 O+ d  g
-----) [6 N9 u) x; }2 t! P9 W; @
Common Name (eg: your user, host, or server name) [longrui]:/ Z, z* w1 Z: p, I0 O

6 @4 N2 W5 _3 Z0 }Notice5 ]4 i7 a+ j: j" ?- }+ q
------
! f1 T: @, g" ~- n- Y3 I" ePrivate-Key and Public-Certificate-Request files created.
: h: `% S% R9 N( S9 ]; HYour files are:! _# u+ S8 N* M3 o
* req: /data/openvpn/easy-rsa-client/easyrsa3/pki/reqs/longrui.req' H+ R0 ~. {! a; {
* key: /data/openvpn/easy-rsa-client/easyrsa3/pki/private/longrui.key2 T& C$ W, e/ q1 p3 {; f6 ?8 h& a! M) ]

, k" U; C6 ^9 @
8 l& q2 X' D! u5 @7 q
/ c. M0 ?# P3 O, w7 w#2)服务端签发证书
) x& w# k, V6 D1 L+ @3 k/ P: M$ ?; ^8 ]& d5 ^  t% z
[root@openvpn easy-rsa-server]# cd /data/openvpn/easy-rsa-server/easyrsa3/2 U+ }. d% S* s  M$ [
[root@openvpn easyrsa3]# ; x( k% r! W/ E* Q+ A3 C) |. J2 n

% l+ h1 ^  }7 ^$ i( Y0 Y" A3 m7 y#将客户端证书复制到CA工作目录' T- t5 t3 h0 {2 I" ^
( ]+ j! }, V& R

- |5 t: \  P. j$ B[root@openvpn easyrsa3]# ./easyrsa import-req /data/openvpn/easy-rsa-client/easyrsa3/pki/reqs/longrui.req longrui" Y7 Z! k; t! J2 T' j
Using Easy-RSA 'vars' configuration:
, ^# Q* F  m) z+ l% H7 k, ^1 i* /data/openvpn/easy-rsa-server/easyrsa3/vars: o9 L9 x$ [* R, F
6 H, m6 I" ]5 u: N" r1 z& c
Notice+ O: O- q' _0 E1 ?5 ]5 Q+ ^  b
------
, C3 {+ A& D3 p; z6 X" IRequest successfully imported with short-name: longrui
+ O2 U, D$ L, D" l! lThis request is now ready to be signed.
; L; s& \& @9 l- ]0 n% I
( w3 \6 v6 y$ |' y4 K, T% h, n8 t, r; m' i- `% l
7 ^" t% j! `. g- w4 d
#设置客户端证书有效期,我这里设置的是90天: d7 U6 q' D5 l/ B( V0 _+ @
root# sed -i "s/set_var EASYRSA_CERT_EXPIRE.*$/set_var EASYRSA_CERT_EXPIRE\t90/g" ./vars; B4 i  J% m; m& \9 z& @9 q
#签发证书1 f8 M: }0 u4 n& k
root# ./easyrsa sign client longrui
" h# q7 q/ E! ~7 u4 s# w; s#输入yes
+ I0 l, @# S2 ZType the word 'yes' to continue, or any other input to abort.' d: C" t( Y6 T
Confirm request details:yes! f. \+ ^: v  c: O3 U' T& A" n3 b- Z' t

/ R" w% G3 H% x' B: X/ U7 H  u" }& e
#生成的证书
, W* q6 e% U6 \. S7 HCertificate created at: /data/openvpn/easy-rsa-server/pki/issued/longrui.crt1 {/ B& ]) D  u( B  y

! w0 Z# n  M2 G" o  y
% u) R5 ~2 e% e[root@openvpn easyrsa3]# ./easyrsa sign client longrui 9 i6 N# t6 r, W: [( H; C$ A
Using Easy-RSA 'vars' configuration:
9 y) z- X% h6 k# o; Z0 w* /data/openvpn/easy-rsa-server/easyrsa3/vars% v  M4 ?% T0 t" F. ?1 r( Q  D5 R# y
Please check over the details shown below for accuracy. Note that this request3 j, m6 d; n. r) v+ {8 ~5 d% U3 |
has not been cryptographically verified. Please be sure it came from a trusted3 Z4 i. t3 Y/ Z4 i
source or that you have verified the request checksum with the sender.6 l; T+ c  C6 F) x, K1 Z- o( |
You are about to sign the following certificate:) \; G4 w5 V# @- X, Z
9 T! n. Z3 z" r5 b0 t: {" z) y
  Requested CN:     'longrui'. |& P0 m3 m- i8 ?) p; i
  Requested type:   'client': [% S, a  ]7 ~8 [3 Z# |
  Valid for:        '365' days
' F0 y6 d5 c" t. r2 S; c# m: C# b: r2 i# \* Q
3 F) Z6 ~6 b; z1 w: {! \
subject=6 L: `" ?! {3 G" Y% `3 @6 f% \# @
    commonName                = longrui: r& {4 C+ c0 z, f& y
  P$ y) k0 |7 O' m% ]/ I
Type the word 'yes' to continue, or any other input to abort.
: z' `- I) X1 |  Confirm requested details: yes
! e( h7 r+ t3 ~2 t* g7 p3 b4 j; J1 Y9 M9 H
Using configuration from /data/openvpn/easy-rsa-server/easyrsa3/pki/48fc94cb/temp.1.1
6 ~" a. T( h/ {Check that the request matches the signature: F# e9 X9 @. f  |4 e
Signature ok
: l' M/ j; c1 L! m9 C" l+ }' t6 uThe Subject's Distinguished Name is as follows
+ E2 z0 a9 y& x  G# ~commonName            :ASN.1 12:'longrui'
; g+ l4 {" ?( w  F* L9 SCertificate is to be certified until Jan 17 07:12:25 2027 GMT (365 days); w5 w5 n2 B3 V4 U/ ^" K  n$ ^
# s$ \! N3 `# [* U, X) B. c, w1 ^
Write out database with 1 new entries
0 y& ?! y/ ?3 K! p6 HData Base Updated* q) A# [4 H$ B
4 N) u9 L+ V% B1 n
WARNING
0 X3 y  _" V0 I5 v$ `=======
1 I* O; ~! Q; K7 J  P+ K7 _3 ZINCOMPLETE Inline file created:
: e, N" |0 I2 ?9 J8 {9 l6 G& O* /data/openvpn/easy-rsa-server/easyrsa3/pki/inline/longrui.inline/ V  _' L9 D  F0 w5 S3 E8 x
" r% r0 k. d* F- v

/ v: S% }( W- X1 F4 h1 `# P1 ]Notice
% q/ r5 r4 i: a+ v------% n0 E2 @7 g( j0 {- i) i
Certificate created at:
7 _( L; L/ ~6 @* f7 h' _0 T* /data/openvpn/easy-rsa-server/easyrsa3/pki/issued/longrui.crt
, T2 |& {" B  P" s0 c  U/ j
) r! C0 f! y; F# i. I2 E! O
. S3 C" n# h$ T2 }# N  ?2 C6 J2.4.2 准备客户端配置文件
/ h5 W6 R1 o" f- A#创建存放目录$ {+ [, `  h4 q# ^2 X4 Y0 h; u
root# mkdir /data/openvpn/client/
# _, n! V  V3 n8 B4 @) q#创建张三证书存放的目录
% T" Q7 f; i' @root# mkdir /data/openvpn/client/longrui+ M# Z0 X5 I7 w2 U- c3 N
#复制证书
  V; l1 b. }5 Z4 t1 @8 S
" N3 m' I3 W: C) V* y
! O/ w* E( E0 b( `  `. m; s9 J[root@openvpn easyrsa3]# mkdir /data/openvpn/client/longrui4 b2 d6 C+ J, a$ [. c& z$ A
[root@openvpn easyrsa3]# find /data/openvpn/ \( -name "longrui.key" -o -name "longrui.crt" -o -name "ca.crt" -o -name "ta.key" \) -exec cp {} /data/openvpn/client/longrui \;
$ I' N2 x/ ?5 i) j$ }cp: '/data/openvpn/client/longrui/longrui.crt' and '/data/openvpn/client/longrui/longrui.crt' are the same file
& b3 ^4 e9 q% T$ f( ]. }' q# Lcp: '/data/openvpn/client/longrui/ca.crt' and '/data/openvpn/client/longrui/ca.crt' are the same file7 t3 d- P" {( W6 X
cp: '/data/openvpn/client/longrui/ta.key' and '/data/openvpn/client/longrui/ta.key' are the same file
$ x0 k+ ^# k9 _0 j/ Kcp: '/data/openvpn/client/longrui/longrui.key' and '/data/openvpn/client/longrui/longrui.key' are the same file
" f4 l; i( p4 K, G; F8 S, d3 ^* x1 c( r1 t' ^
  I+ k8 {$ ^6 I4 }

7 q4 e2 b: P8 B- e: ?* i* A# ]) j) ][root@openvpn2 ~]# firewall-cmd --permanent --direct --add-rule ipv4 nat POSTROUTING 0 -s 10.160.131.0/24  -j MASQUERADE
5 N, Z3 ]$ q; [' M& j9 B, asuccess, R2 T: n3 e" K$ d  q
[root@openvpn2 ~]# firewall-cmd --permanent --direct --add-rule ipv4 nat POSTROUTING 1 -s 172.30.0.0/22  -j MASQUERADE; @( S% `! S& G5 {9 _
success2 j% [* ?2 c  d
2 Y/ u+ p3 _9 u
firewall-cmd --add-interface=tun0
5 m! R! ?( ~& b  Z4 O/ ?
& l. [2 p# F$ d7 Z3 b9 D修改文件:, r$ a2 M. }% X
root# vim /data/openvpn/client/longrui/client.ovpn0 I) s+ b4 i/ D9 s
client
: d* R0 N1 k& s+ E! O2 Udev tun4 L' S% E8 p$ G8 e* q( O. p
proto tcp
% |: H5 Y; C! O4 sremote 公网ip 1194
1 b" Q# `" q- @5 l, kresolv-retry infinite
; x0 N" [' ^5 B" h. l( C4 Tnobind4 c' I& t0 a+ H5 t
ca ca.crt
: `3 E3 d' L; x/ Pcert longrui.crt
( u* E7 v6 ^9 A0 G* w, p; |key longrui.key
3 J6 F- M& k  y* I/ Sremote-cert-tls server7 Y4 ^# N; r' c' F0 ?) \' O6 I6 h
tls-auth ta.key 1
* d' S4 w8 D& p8 M7 i+ jcipher AES-256-CBC9 {& W, ?5 T3 c2 D! g1 n
verb 31 b9 t: t6 m9 f0 b% M' z
compress lz4-v26 s/ o" S3 K  s0 Y: @0 `1 z* v
% i( k# o' j+ t3 m, u

+ y: j3 F: {, d7 I, g: u* f# ^, A2.5 测试7 T. _* L* l2 c+ p  }
#将证书下载下来
2 p( I( o7 l/ x; b/ Y* sroot# cd /data/openvpn/client/
/ W3 c: S. O. E) o* T" Z  Uroot# tar -zcvf longrui.tar.gz longrui9 W/ R$ M; t9 z0 w+ O
root# sz longrui.tar.gz! L. q" I& M' F$ U/ ]# D- r
" d3 `; j& X* Q7 d" L* P
#win10 安装客户端(这里不演示了)5 l- I  W6 u' Z, [
https://swupdate.openvpn.org/com ... tall-2.4.5-I601.exe3 R0 h- N2 i6 a+ r! J$ l
#将 zhangsan.tar.gz 复制到 openvpn的config目录,然后点击链接
* a9 g$ K2 }8 z, H4 W
# e# \9 e- a2 P/ j5 S
. Q7 s" M/ w2 {  i& @' N#双击运行. Q  H* a: `/ T( a/ b. _, u9 o
# q9 X" n/ L4 Z

, U/ R0 z5 C: ~* @: o3 |7 ~* K0 `5 Z
#这样表示链接成功了9 R" M' r: |2 C0 n

: v- s2 e$ X9 ~
0 L/ a* \3 B% _! M#测试连接mysql数据库端口. Q) Y6 Y' n  B8 }, Q

$ Y) {- P- u+ V# ?
% X  z3 p6 N1 {, ?. ?& Z. G% ~- o6 B2 n" w) |9 R
3 :安装包
) L* S" S3 A) g9 S6 U官网下载地址:
( }! w' i3 P8 Xopenvpn 服务端下载地址:- q) Z; T9 `0 x' F, v
https://swupdate.openvpn.org/com ... penvpn-2.5.6.tar.gz2 h/ c( E; @/ _: Q  s; {" Y7 u" f
openvpn 客户端下载地址:) P) H4 |- ^. O/ t
https://swupdate.openvpn.org/com ... tall-2.4.5-I601.exe9 i8 M& p& B' L# f$ m7 y0 p0 @
EasyRSA下载地址:
/ o$ p: M& K6 [https://github.com/OpenVPN/easy- ... 8/EasyRSA-3.0.8.tgz; G( _& \3 W4 R& F" w& V' m

* `9 P* V  I# v4 o  e  F. [0 G" d9 N4 `
添加防火墙规则:1 _" y' m3 s; m! _- o) }
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i tun0 -o bondmgt -j ACCEPT
7 j$ G; Q  }( P+ ^/ |/ l firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i bondmgt -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
2 X+ C. M. w7 h) l' i$ n0 |, c1 \ firewall-cmd --permanent --direct --add-rule ipv4 nat POSTROUTING 0 -s 10.160.131.0/24  -j MASQUERADE
/ `) q1 E" {% ~- R/ jfirewall-cmd --zone=internal --add-masquerade --permanent
& q2 N% b: i* X; s9 p+ m9 r$ [5 u# w3 J$ w6 P0 Z. J5 M3 [, k
这是后面测试的结果,上面的可以暂时不执行:0 g( T' k" ~. y- h- h% r& F  ~
firewall-cmd --permanent --zone=public --add-interface=tun0
$ D$ Q9 n8 P$ Zfirewall-cmd --permanent --zone=public --add-masquerade
! ^/ x% `* s2 s+ E% ]firewall-cmd --permanent --add-forward7 ^+ V  M% ?1 D- L, V$ U5 X& ?4 G" z
添加转发规则。允许可通行。

" q' b' k! Y- a7 W1 b6 q5 x8 s
5 ~& D6 Z: H9 w% J2 Q/ o% H$ G$ P) ?2 S3 s2 T6 c
./easyrsa sign-req client wogong3
3 `3 [5 `3 Q: k5 \# o, m#wogong3为创建客户端的证书的Common Name
7 T- o" m+ r5 g验证证书是否正确+ @2 B6 z6 O; m
openssl verify -CAfile ca.crt issued/wogong2.crt+ g! W+ Q. Q( C, J# T
openssl verify -CAfile ca.crt issued/wogong3.crt' R, z- [5 E7 S/ J  q' f

7 `/ [0 x5 T: |4 V. ~/ w. x4 y0 B
5 q, X& z4 a8 p  r5 e
# M# r4 Z( N1 [- M6 V$ d

0 X$ e% d/ v+ D  [* i/ b$ }! `" q
, K8 H0 k0 `' B! D' X! n& J8 b2 U" A6 t. p9 U( V" a" p

  ^3 J& E( {( e! y1 D9 F# h+ u/ ], W" q5 c2 E1 Z0 t9 I
 楼主| 发表于 2026-1-17 13:19:47 | 显示全部楼层
configure: Enabled ovpn-dco support for Linux
6 X& A+ }# l. X4 m& nchecking for LIBCAPNG... no
+ c- k* T0 g- f4 t: ~& qconfigure: error: libcap-ng package not found. Is the development package and pkg-config (/usr/bin/pkg-config) installed?/ U. d+ U) z9 [
[root@openvpn openvpn-2.6.17]# dnf install -y libnl3-devel  pkgconf-pkg-config libcap-ng-devel+ i: F( h) ]6 Y  }+ Y( E
Last metadata expiration check: 0:10:36 ago on Sat 17 Jan 2026 01:08:46 PM CST.5 K! i# |: M) ^" @/ \
Package libnl3-devel-3.5.0-1.el8.x86_64 is already installed.
. p1 i: G8 p# ?Package pkgconf-pkg-config-1.4.2-1.el8.x86_64 is already installed.
) w) S3 X! B. kDependencies resolved.
1 B: N" U! L1 ?! O; A( |==================================================================================================================================================================================================================================================================0 a0 ^  N, u. S7 K
Package                                                             Architecture                                               Version                                                            Repository                                                Size
- N$ _4 v- _( S# ]0 b! r==================================================================================================================================================================================================================================================================
7 p3 p) h/ g8 {; h$ y1 \/ N$ lInstalling:
  K+ q3 ]. `! f$ Z- i! a/ R/ c libcap-ng-devel                                                     x86_64                                                     0.7.11-1.el8                                                       base                                                      30 k: }/ k# c4 a6 i& V  A' v
2 W, G  I' J  I0 o; [& h6 D4 {
Transaction Summary
+ f; ?  M* _0 F& X$ i) b7 |$ k1 f==================================================================================================================================================================================================================================================================
$ A0 w6 \' T9 F& n! r9 [  p- UInstall  1 Package
) \$ W" R2 T. L! ~7 S  {. F
1 L% ]' h. b9 v2 u/ d! CTotal download size: 30 k$ o& |+ v/ D) a' Y7 J  X
Installed size: 15 k
  W/ j$ I% j; l, cDownloading Packages:
: ?$ G/ y3 L+ _9 _3 Z3 S: Dlibcap-ng-devel-0.7.11-1.el8.x86_64.rpm                                                                                                                                                                                            88 kB/s |  30 kB     00:00    5 |& ]5 J, q+ ~; i5 W
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
: y. n- R9 @2 @" F5 qTotal                                                                                                                                                                                                                              88 kB/s |  30 kB     00:00     + `% `0 y- q: _, ^9 V* f. U+ k/ w
Running transaction check. y; P) j3 d( V
Transaction check succeeded.
) L1 i) s! `: d5 g& d6 R( l: J( B; Y; |Running transaction test
. s7 p- [) b. iTransaction test succeeded.+ S& |  \: L2 d& G6 ?: z) D" H0 h
Running transaction
. `% X* S. N* M  Preparing        :                                                                                                                                                                                                                                          1/1
/ S4 B6 D. h! S8 v  Installing       : libcap-ng-devel-0.7.11-1.el8.x86_64                                                                                                                                                                                                      1/1
6 V( U$ ^9 O; Q2 B! {; ?  Running scriptlet: libcap-ng-devel-0.7.11-1.el8.x86_64                                                                                                                                                                                                      1/1
2 s+ Z# O  m- Z( p, x4 O1 O5 T  Verifying        : libcap-ng-devel-0.7.11-1.el8.x86_64                                                                                                                                                                                                      1/1 ; ?. z, }  q5 Z5 I0 H2 J: O0 w4 q

, z# v5 G2 G/ z) C2 p" L+ jInstalled:
- L  \# x' ^7 @& U2 k6 O0 [; r  libcap-ng-devel-0.7.11-1.el8.x86_64                                                                                                                                                                                                                             ! |$ S8 I5 F2 y0 w1 r5 Q9 x

$ Y. g$ W8 F, d2 S- pComplete!
5 K  O2 R0 J- m* d2 y6 s, U
 楼主| 发表于 2026-1-17 13:20:56 | 显示全部楼层
checking for lz4.h... no! w% D# K! `3 Z2 ]* \8 K
configure: error: No compatible LZ4 compression library found. Consider --disable-lz41 p2 k4 D5 e6 [  D7 F+ o  i
[root@openvpn openvpn-2.6.17]# dnf install -y lz4-devel
1 @/ ^1 X$ E- M* s4 P" L2 c/ PLast metadata expiration check: 0:11:51 ago on Sat 17 Jan 2026 01:08:46 PM CST.
0 C4 s, T2 ~9 \( A7 yDependencies resolved.- P6 U3 |7 }/ X/ \9 ^# _
==================================================================================================================================================================================================================================================================+ Z! Z; D5 z8 _* c* E/ M8 w6 k
Package                                                        Architecture                                                Version                                                               Repository                                                 Size. B# P* j- T- P
==================================================================================================================================================================================================================================================================
2 E. ~8 E3 e0 `' Q6 ]# ?) }8 @Installing:4 Z. R8 N9 k. p- S
lz4-devel                                                      x86_64                                                      1.8.3-3.el8_4                                                         base                                                       31 k
3 }. s* C9 Y" m% |4 s/ J; h+ ?6 e# o3 H- ^
Transaction Summary' s. h$ E$ Q7 G3 m! \  k
==================================================================================================================================================================================================================================================================; E) ]& H/ U6 I; n8 G
Install  1 Package8 g0 |+ o7 i* U  \1 B9 t

) ^- Q& p8 I+ M! NTotal download size: 31 k: w- N1 w) g8 D! e
Installed size: 76 k
8 `- G. x4 d" J/ t* P1 sDownloading Packages:
- l  y3 E/ O6 _  o9 i( `0 tlz4-devel-1.8.3-3.el8_4.x86_64.rpm                                                                                                                                                                                                 26 kB/s |  31 kB     00:01    6 s0 Y9 c" {7 e0 g% M& _1 E
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------* o& r5 V& F4 {# E
Total                                                                                                                                                                                                                              26 kB/s |  31 kB     00:01     ; D, U6 S+ }. e/ R
Running transaction check+ P, q; V- H2 S! E7 M, N! N9 k+ L5 g9 \
Transaction check succeeded.+ J6 \9 W" n* L5 J/ i
Running transaction test
+ }$ ]% H2 u, A9 |: C4 A8 ^Transaction test succeeded.
$ o' Q  S2 N& v  P  n+ y; Z: yRunning transaction
! q% i& o: r  R' D3 L$ @% D" [. d  Preparing        :                                                                                                                                                                                                                                          1/1
! @1 ?. P1 k, D; c: k% U2 A  Installing       : lz4-devel-1.8.3-3.el8_4.x86_64                                                                                                                                                                                                           1/1
/ |$ \7 @4 u( I2 D( T  K% N  Running scriptlet: lz4-devel-1.8.3-3.el8_4.x86_64                                                                                                                                                                                                           1/1 6 Y* N: g1 r8 _9 g8 F! ~
  Verifying        : lz4-devel-1.8.3-3.el8_4.x86_64                                                                                                                                                                                                           1/1 ! I1 E  L3 p: S9 d2 A) P8 d

6 m+ z0 u( [* L$ @% a/ I2 E; FInstalled:
& K  M6 ]& ^- A  lz4-devel-1.8.3-3.el8_4.x86_64                                                                                                                                                                                                                                 
) k4 v" x0 x, @8 ?1 Y
3 f* F( V/ G! ~$ C/ J& l+ UComplete!1 L0 S% V9 f' x$ z
 楼主| 发表于 2026-1-17 13:26:25 | 显示全部楼层
Missing python-docutils - skipping man page generation (openvpn-examples.5)) t; e; B  X6 j0 ~' ^  `, ~
make[4]: Entering directory '/usr/src/openvpn-2.6.17/doc'
" B4 V& s9 J7 b/ Cmake[4]: Nothing to be done for 'install-exec-am'.
; s$ x# I# Z% f  O: r /usr/bin/mkdir -p '/data/openvpn/share/doc/openvpn'/ ?6 {- g) G5 @# }. }" S8 x! l
/usr/bin/install -c -m 644 management-notes.txt gui-notes.txt '/data/openvpn/share/doc/openvpn'7 L( d5 Z3 C2 ]. o3 e/ ~
Missing python-docutils - skipping man page generation (openvpn.8)9 P  f4 @# ?9 N1 s3 l6 h, u
Missing python-docutils - skipping man page generation (openvpn-examples.5)& l% _4 E+ {- ]. D" E+ v7 E9 Z
/usr/bin/mkdir -p '/data/openvpn/share/man/man5'
: m) x2 \6 K7 s  r /usr/bin/install -c -m 644 ./openvpn-examples.5 '/data/openvpn/share/man/man5'
6 o) e, O3 i% O& D- v) K/usr/bin/install: cannot stat './openvpn-examples.5': No such file or directory! |4 C/ M7 v9 R- ]. _3 [
make[4]: *** [Makefile:554: install-man5] Error 1
* C* Q# R! q3 V3 ]3 @1 Omake[4]: Leaving directory '/usr/src/openvpn-2.6.17/doc'2 t* Y& v; s  J  N0 k" g9 X
make[3]: *** [Makefile:855: install-am] Error 2" O9 x7 ^' ~' X. v, t6 {# V- T
make[3]: Leaving directory '/usr/src/openvpn-2.6.17/doc'+ {8 k, @# E" W+ R9 \
make[2]: *** [Makefile:688: install-recursive] Error 1; S2 x, [1 U- ~. u
make[2]: Leaving directory '/usr/src/openvpn-2.6.17/doc'
0 K" X; ]5 V( [7 Zmake[1]: *** [Makefile:616: install-recursive] Error 1
- d' u. U( [' V+ k( Pmake[1]: Leaving directory '/usr/src/openvpn-2.6.17'& P3 U9 W4 o( q  r. ?
make: *** [Makefile:916: install] Error 2  O% j- h# V3 Z( u! {
[root@openvpn openvpn-2.6.17]# dnf install python3-docutils5 K: z/ @3 X9 V5 ^* Q
Last metadata expiration check: 0:16:38 ago on Sat 17 Jan 2026 01:08:46 PM CST.
3 ~, v. \4 c! W9 ~& G, ]Dependencies resolved.$ z- Z. b; }/ a: |" A
==================================================================================================================================================================================================================================================================
/ ?3 F/ E3 a9 d5 x; g4 T Package                                                       Architecture                                        Version                                                                           Repository                                              Size3 a6 W6 e7 h0 g/ I+ n. V
==================================================================================================================================================================================================================================================================, J5 w+ Y0 b- U
Installing:0 ~" q0 B* |& f& F
python3-docutils                                              noarch                                              0.14-12.module_el8.5.0+761+faacb0fb                                               AppStream                                              1.6 M7 b9 ^5 y8 ]& ]* b3 }
Installing dependencies:
$ Y" j- _# V& _' G9 ~( N python3-pip                                                   noarch                                              9.0.3-20.el8                                                                      AppStream                                               20 k3 E+ [0 w3 t. Z7 e5 @
python36                                                      x86_64                                              3.6.8-38.module_el8.5.0+895+a459eca8                                              AppStream                                               19 k
8 k( K! V, M& Y3 TEnabling module streams:
+ d$ {3 C* x+ k9 r  U6 L) F python36                                                                                                          3.6                                                                                                                                           7 W' S" }; b# H! g

" A6 f5 L0 N7 X2 s- @' p4 ~  _Transaction Summary
9 h' x  D0 s4 _# t: w/ d==================================================================================================================================================================================================================================================================8 S) ^2 J+ A$ h, G7 l5 N7 A! V
Install  3 Packages
, _, p4 ?5 ]7 W0 N0 n7 a! ~1 B
/ Z' j- Q) E& L* t  B9 h2 R7 jTotal download size: 1.6 M) T4 V0 j7 S' R) U& v9 x
Installed size: 5.9 M
! f( G! O6 b, W1 w* a. y4 q1 TIs this ok [y/N]: y4 V( S8 d' w% H4 [# T: ~! B8 h# a
Downloading Packages:  `; H1 z+ V$ b
(1/3): python3-pip-9.0.3-20.el8.noarch.rpm                                                                                                                                                                                        125 kB/s |  20 kB     00:00    0 h6 v: a/ j- O) q4 p( k
(2/3): python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64.rpm                                                                                                                                                                   120 kB/s |  19 kB     00:00    , w8 G/ |- w- Q/ b7 N, O. _1 F
(3/3): python3-docutils-0.14-12.module_el8.5.0+761+faacb0fb.noarch.rpm                                                                                                                                                            3.2 MB/s | 1.6 MB     00:00   
/ l5 b* Z  L% b: g% C# F0 o------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  _( I1 |6 z4 c# m: ~0 O  g
Total                                                                                                                                                                                                                             3.2 MB/s | 1.6 MB     00:00     " ?& i* V/ M; d5 k
Running transaction check' E3 M3 [" K. _4 B6 L( u7 l
Transaction check succeeded.% i, y% }/ `6 T: L/ E- s& U
Running transaction test4 |4 J7 U3 |+ ~- R" ~
Transaction test succeeded.
/ ^0 _  _; u5 ]9 s; fRunning transaction
/ u' f6 Q! @) a* x  Preparing        :                                                                                                                                                                                                                                          1/1   Q; j& K% Y# _$ [
  Installing       : python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64                                                                                                                                                                                     1/3
, [7 \5 o& L! v6 Y! V. m7 T  Running scriptlet: python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64                                                                                                                                                                                     1/3
- @/ E0 B. W% ^  Installing       : python3-pip-9.0.3-20.el8.noarch                                                                                                                                                                                                          2/3 " S+ y$ ^6 {" I/ U
  Installing       : python3-docutils-0.14-12.module_el8.5.0+761+faacb0fb.noarch                                                                                                                                                                              3/3
" T" B# t( S; t6 q  j* E. y  Running scriptlet: python3-docutils-0.14-12.module_el8.5.0+761+faacb0fb.noarch                                                                                                                                                                              3/3
( v6 L: H+ [" G& [5 {" J  Verifying        : python3-docutils-0.14-12.module_el8.5.0+761+faacb0fb.noarch                                                                                                                                                                              1/3
. w; ^; \( y$ q5 Y5 U# R. g3 M3 i% y  Verifying        : python3-pip-9.0.3-20.el8.noarch                                                                                                                                                                                                          2/3
( G9 o2 P# E+ w. A3 r3 e; t  Verifying        : python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64                                                                                                                                                                                     3/3 # N, c5 O, j( P! k" |2 Q
9 Z+ A; O: w+ N- R/ K
Installed:
3 y& F: b" ?$ r; B  python3-docutils-0.14-12.module_el8.5.0+761+faacb0fb.noarch                                      python3-pip-9.0.3-20.el8.noarch                                      python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64                                     / n6 E: B% L- ?& ?# v! @! |

' u! I; [/ C8 a8 r. KComplete!
1 g! w2 l- J% t+ T- U4 ]
 楼主| 发表于 2026-1-17 16:43:57 | 显示全部楼层
sysctl -w net.ipv4.ip_forward=1
# O( s" S, X" v* i( o: y2 M5 anet.ipv4.ip_forward = 1: R8 h% E# N5 Z$ l/ t: M: t/ h
  
 楼主| 发表于 2026-3-10 16:45:25 | 显示全部楼层
137  source /etc/rc.local
3 B& \$ ~  ?3 {. m& \  138  cat /etc/rc.local
8 w0 X2 ^7 s* c# R! [$ f  139  iptables -t nat -A POSTROUTING -s 10.170.133.0/24 -j MASQUERADE8 c8 V4 E0 t; u2 k& y6 c
  140  iptables -t nat -A POSTROUTING -s 172.30.1.0/22 -j MASQUERADE; I4 Z% o' ?9 |* \* F# \' n  \
  141  iptables -L( R: i3 v5 q! N4 f. p& s- H( _4 k7 G
  142  firewall-cmd --reload - ~, B3 u+ ~- A: o+ ~
  143  firewall-cmd --list-all. P9 v8 M: F$ |, c$ R" B
  144  firewall-cmd --permanent --add-service=openvpn " j; F$ ?; i7 n3 r. Q% X
  145  firewall-cmd --list-all
3 J2 z" g; W  y5 G  146  firewall-cmd --reload 8 p2 |+ o, a  \! w  V" u
  147  firewall-cmd --list-all
, M5 M* O* v, Y0 W& h  148  telnet 192.168.16.53 22, |. K! `# c" ^: n, i5 ~
  149  ssh 192.168.16.53 223 ?+ U) L& b& N! d% e" k$ `
  150  ip addr! J+ {) N! Q* N4 H. \
  151  rm -rf /etc/sysconfig/network-scripts/ifcfg-bondmgt.2 2 P& Z, C) \. ~: E
  152  ls7 e" \8 f" Q4 W* l
  153  ip addr0 g. h2 d  @, W2 k
  154  cd
  C7 ]+ ]3 S/ ?' X. B0 O3 x; p' D* D  155  reboot# A  z; P2 t9 Z0 B. D) o9 Y
  156  passwd 6 K$ Q" |5 w; V$ ]. w; C" t
  157  firewall-cmd --list-all
/ Z! H1 N% j+ G' g( y  158  ip addr
4 A( d4 O0 S! w- q+ @5 @  159  firewall-cmd --list-all% A" h, I) H; T9 {. j1 ^+ M
  160  getenforce & k/ z: m4 @# W* K1 u
  161  ls
+ P5 j% y6 b: @8 r" o  162  cd /etc/sysconfig/network-scripts/1 k3 A* M  }  R( w8 h& ?
  163  ls
0 ^  b8 O4 D( O) i, W$ D- y( S  164  rm -rf ifcfg-bondvirt
: |! X7 A: Q9 Q) N5 i  165  ls' s$ [7 `! [2 j4 J0 i( w- O
  166  ip addr* R$ M' z0 Y( Y& G2 [
  167  netstat -ntlp# Q5 e1 F2 c& W7 T  T
  168  cd
4 Q' O9 i& F7 D$ M$ [# Q  p3 m  169  ip r
( l" q  M6 H' `9 H& i7 V5 x$ a  170  vim /data/openvpn/server.conf 0 y( x. n5 S- o4 t7 d7 A
  171  route -n
' L  h" \/ l$ u0 |/ g0 A  n  172  dnf install -y libnl3-devel  pkgconf-pkg-config libcap-ng-devel
: Y5 n+ h3 D6 ~- j) q5 J) p  173  dnf install -y lz4-devel  c7 u& y1 _. _7 D) S+ Q- T: A
  174  dnf install python3-docutils2 E; Q6 e' \' [" J% ^$ Y# @6 Y8 \- p6 M* H
  175  sysctl -w net.ipv4.ip_forward=1( w5 S  h: K0 a/ P* ?+ S9 s; T: x1 U
  176  sysctl -p
& _. C% ]+ d/ h8 Y6 H$ m  177  firewall-cmd --permanent --add-masquerade
4 B( H5 a( A6 a# ?3 D) P* j* _  178  firewall-cmd --reload
: T5 o  i- e" F, B7 [: p  179  sysctl -a | grep net.ipv4.ip_forward1 X* c% n. ], P
发表于 2026-3-11 10:47:45 | 显示全部楼层
firewall-cmd --permanent --zone=public --add-interface=tun0
2 p! }# R8 \3 ^9 G! }firewall-cmd --permanent --zone=public --add-masquerade
. n  _2 A5 L! ~' cfirewall-cmd --permanent --add-forward
! |, s# W, F1 z9 _% ^6 w. w添加转发规则。允许可通行。
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 点击这里给我发消息

GMT+8, 2026-3-9 00:34 , Processed in 0.067411 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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