UOS桌面操作系统搭建open vxn服务

news2024/9/20 22:24:05

UOS系统搭建openVPN

    • 一、环境说明
    • 二、服务端配置
      • 1、软件安装
      • 2、创建目录用来存放生成证书中要用到的各种文件
      • 3、准备证书生成相关文件
      • 4 、准备生成证书用的CSR相关配置
      • 5、生成CA证书
      • 6、生成服务端证书
      • 7、使用CA给服务端证书签名
      • 8、生成DH证书
      • 9、生成ta密钥
      • 10、生成客户端证书,然后将它们复制到客户机上。为client1创建证书和密钥
      • 11、将server端证书和密钥都统一放到/etc/openvpn/目录下,方便管理和配
      • 12、主配文件:/etc/openvpn/server.conf
      • 13、启动openvpn服务器
      • 14、检查服务与查看虚拟接口
    • 三、客户端配置
      • 1、安装openvpn
      • 2、服务器端证书与秘钥拷贝到本机
      • 3、在设置里创建vpn连接,根据实际情况更改网关(服务器ip),证书位置以及私钥密码
      • 4、第二种方法
        • 1)创建配置文件client.conf
        • 2)执行查看
    • 四、报错以及解决方案
      • 1、openvpn客户端连接失败,服务端服务报错
      • 2、openvpn@server.service启动报错
      • 3、客户端连接断开,连接VPN失败,原因未知
      • 4、客户端使用图形化连接无反应,或者如下连接失败报错

一、环境说明

IP地址说明
10.200.152.67服务端
10.200.152.68客户端

测试环境保证时间的同步,不然会存在客户端拨号报错情况

二、服务端配置

1、软件安装

sudo apt install openvpn easy-rsa -y

说明:easy-rsa主要用来给OpenVPN Server启动要用到的相关证书的生成

2、创建目录用来存放生成证书中要用到的各种文件

mkdir /etc/openvpn/easy-rsa

3、准备证书生成相关文件

cp -ra /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/

4 、准备生成证书用的CSR相关配置

创建/etc/openvpn/easy-rsa/vars配置文件

cat <<EOF > /etc/openvpn/easy-rsa/vars
set_var EASYRSA_REQ_COUNTRY "CN"
set_vEASYRSA_REQ_PROVINCE "BeiJing"
set_var EASYRSA_REQ_CITY "Bei Jing"
set_var EASYRSA_REQ_ORG "TEST Co"
set_var EASYRSA_REQ_EMAIL "it@test.com"
set_var EASYRSA_REQ_OU "Test Organizational Unit"
#证书有效期
set_var EASYRSA_CA_EXPIRE 3650
set_var EASYRSA_CERT_EXPIRE 3650
EOF

5、生成CA证书

cd /etc/openvpn/easy-rsa/
./easyrsa init-pki

Note: using Easy-RSA configuration from: /etc/openvpn/easy-rsa/vars
init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /etc/openvpn/easy-rsa/pki
./easyrsa build-ca

Note: using Easy-RSA configuration from: /etc/openvpn/easy-rsa/vars
Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017
Enter New CA Key Passphrase: 需要设置一个密码,我这里设为"123456"
Re-Enter New CA Key Passphrase:
Generating RSA private key, 2048 bit long modulus
……………………………+++
……………………………….+++
e is 65537 (0x10001)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
- - - - -
Common Name (eg: your user, host, or server name) [Easy-RSA CA]: 输入"CN"后直接回车
CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/etc/openvpn/easy-rsa/pki/ca.crt

6、生成服务端证书

./easyrsa gen-req server nopass

Note: using Easy-RSA configuration from: /etc/openvpn/easy-rsa/vars
Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017
Generating a 2048 bit RSA private key
.……………………………………………………….+++
.+++
writing new private key to '/etc/openvpn/easy-rsa/pki/easy-rsa-982.cJcd0X/tmp.RiZw8A'
-——
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-——
Common Name (eg: your user, host, or server name) [server]: 输入"CN",直接回车
Keypair and certificate request completed. Your files are:
req: /etc/openvpn/easy-rsa/pki/reqs/server.req
key: /etc/openvpn/easy-rsa/pki/private/server.key

7、使用CA给服务端证书签名

./easyrsa sign server server


Note: using Easy-RSA configuration from: /etc/openvpn/easy-rsa/vars
Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017
You are about to sign the following certificate.
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.
Request subject, to be signed as a server certificate for 3650 days:
subject=
commonName = CN
Type the word 'yes' to continue, or any other input to abort.
Confirm request details: yes,这里输入yes
Using configuration from /etc/openvpn/easy-rsa/pki/easy-rsa-1033.vfaQKy/tmp.CHstGn
Enter pass phrase for /etc/openvpn/easy-rsa/pki/private/ca.key: 这里输入步骤4中设置的密码"123456"
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'CN'
Certificate is to be certified until Aug 17 08:36:18 2031 GMT (3650 days)
Write out database with 1 new entries
Data Base Updated
Certificate created at: /etc/openvpn/easy-rsa/pki/issued/server.crt

8、生成DH证书

./easyrsa gen-dh

Note: using Easy-RSA configuration from: /etc/openvpn/easy-rsa/vars
Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
…………………………………………………………………………………………….++++
DH parameters of size 2048 created at /etc/openvpn/easy-rsa/pki/dh.pem

9、生成ta密钥

openvpn --genkey --secret /etc/openvpn/ta.key  #输入配置的密码

10、生成客户端证书,然后将它们复制到客户机上。为client1创建证书和密钥

./easyrsa build-client-full client1

11、将server端证书和密钥都统一放到/etc/openvpn/目录下,方便管理和配

cp /etc/openvpn/easy-rsa/pki/ca.crt /etc/openvpn/
cp /etc/openvpn/easy-rsa/pki/private/server.key /etc/openvpn/
cp /etc/openvpn/easy-rsa/pki/issued/server.crt /etc/openvpn/
cp /etc/openvpn/easy-rsa/pki/dh.pem /etc/openvpn/

12、主配文件:/etc/openvpn/server.conf

cd /etc/openvpn/
cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz ./
gunzip server.conf.gz
vim server.conf

打开如下注释:
topology subnet
push “redirect-gateway def1 bypass-dhcp”
push “dhcp-option DNS 208.67.222.222”
push “dhcp-option DNS 208.67.220.220”
tls-auth ta.key 0
user nobody
group nogroup
client-to-client
修改如下信息:
修改前:
dh dh2048.pem
cipher AES-256-CBC
修改后:
dh dh.pem
cipher BF-CBC
注释如下信息:
;tls-auth ta.key 0
备注:server 10.8.0.0 255.255.255.0可根据需求填写,这里使用默认

13、启动openvpn服务器

    systemctl start openvpn@server.service
    systemctl enable openvpn@server.service
    或者
    cd /etc/openvpn
    sudo openvpn --config server.conf

在这里插入图片描述

14、检查服务与查看虚拟接口

    netstat -lntup |grep openvpn
    udp        0      0 0.0.0.0:1194         0.0.0.0:*      24443/openvpn  
    ifconfig
    可以看到一个tun0网络接口,IP地址是10.8.0.1

在这里插入图片描述

三、客户端配置

1、安装openvpn

apt install openvpn -y

2、服务器端证书与秘钥拷贝到本机

    客户端操作:
    scp 10.200.152.67:/etc/openvpn/easy-rsa/pki/ca.crt  /etc/openvpn
    scp 10.200.152.67:/etc/openvpn/easy-rsa/pki/private/client1.key  /etc/openvpn
    scp 10.200.152.67:/etc/openvpn/easy-rsa/pki/issued/client1.crt  /etc/openvpn

3、在设置里创建vpn连接,根据实际情况更改网关(服务器ip),证书位置以及私钥密码

在这里插入图片描述

4、第二种方法

1)创建配置文件client.conf

vi /etc/openvpn/client.conf

client
dev tun
proto udp
remote 10.200.152.67 1194 #根据实际情况改为服务器的ip地址
ca ca.crt
cert client1.crt
key client1.key
user nobody
group nogroup
verb 3

 ##终端运行测试
   cd /etc/openvpn
   openvpn --config client.conf

备注:执行该命令的窗口不能关闭,可以在后台执行(至少openvpn进程不能结束)
输出“Initialization Sequence Completed”字样,说明OpenVPN成功连接

 ##后台运行测试
  echo 123456 |tee  /etc/openvpn/passwd
  openvpn --config /etc/openvpn/client.conf --cd /etc/openvpn --daemon --askpass /etc/openvpn/passwd

在这里插入图片描述
拨号成功服务端日志参考
在这里插入图片描述

2)执行查看

# ifconfig
##可以看到一个tun0网络接口,IP地址是10.8.0.x, ping 10.8.0.1 ping通ssh可以连接,测试openvpn连接成功

在这里插入图片描述

四、报错以及解决方案

1、openvpn客户端连接失败,服务端服务报错

journalctl -fu openvpn@server.service


WARNING: ‘link-mtu’ is used inconsistently, local='link-mtu 1557, remote='link-mtu 1541
WARNING: ‘tun-mtu’ is used inconsistently, local=‘tun-mtu 1400’, remote=‘tun-mtu 1500’
在这里插入图片描述
解决方案
查看服务端server.conf配置文件

添加如下信息:
link-mtu 1541
tun-mtu 1500
keysize 128
cipher BF-CBC

2、openvpn@server.service启动报错

TLS Eerror cannot locate HMAC in incoming packet  from [AF_INET]10.200.152.230:56765

在这里插入图片描述
解决方案
修改/etc/openvpnserver.conf

#注释如下信息:
;tls-auth ta.key 0 

3、客户端连接断开,连接VPN失败,原因未知

分析:查看日志未发现报错,使用命令行启动后报错如下:
Mon Sep  5 15:46:49 2022 ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2)
Mon Sep  5 15:46:49 2022 Exiting due to fatal error

解决方案
内核选项缺失

zcat /proc/config.gz  |grep -i CONFIG_TUN
# CONFIG_TUN is not set
# CONFIG_TUN_VNET_CROSS_LE is not set
#内核开启TUN模块选项即可

4、客户端使用图形化连接无反应,或者如下连接失败报错

在这里插入图片描述
解决方案
查看客户端与服务端时间是否同步

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/359895.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

07 二叉树

开始系统学习算法啦&#xff01;为后面力扣和 蓝桥杯的刷题做准备&#xff01;这个专栏将记录自己学习算法是的笔记&#xff0c;包括 概念&#xff0c; 算法运行过程&#xff0c;以及 代码实现&#xff0c;希望能给大家带来帮助&#xff0c;感兴趣的小伙伴欢迎评论区留言或者私…

CHAPTER 1 Web Server - apache(httpd)

Web Server - apache1.1 概念介绍1.1.1 什么是Web Service?1.1.2 什么是Web Server?1.1.3 常见的Web服务程序有哪些?1.2 httpd1.2.1 httpd和apache的区别关系1.2.2 httpd版本介绍1.2.3 httpd安装1. yum 安装2. 编译安装1.3 通过systemctl管理httpd1.3.1 配置文件原因1.3.2 为…

析构函数、拷贝构造

1、析构函数析构函数的定义方式函数名和类名相同&#xff0c;在类名前加~&#xff0c;没有返回值类型&#xff0c;没有函数形参&#xff08;不能重载&#xff09;当对象生命周期结束的时候&#xff0c;系统会自动调用析构函数先调用析构函数&#xff0c;再释放对象的空间析构函…

C#中多态、抽象类、虚方法

多态、重装、重写 •多态&#xff1a;同一操作作用于不同的对象&#xff0c;可以有不同的解释&#xff0c;产生不同的执行结果&#xff0c;这就是多态性。抽象类、虚函数、接口三种方法实现的可以是多态性。•重载&#xff08;overload&#xff09;&#xff1a;对象中同名函数&…

【Galois工具开发之路】给你的JVM安装一个插件~

什么是DCEVM Dcevm&#xff08;DynamicCode Evolution Virtual Machine&#xff09;是Java Hostspot的一个扩展插件&#xff0c;属于开源性工具&#xff0c;非JDK官方提供&#xff0c;它允许你在运行环境下修改加载的类文件。当前虚拟机只允许修改方法体&#xff08;Method&am…

【Python学习笔记】43.Python3 JSON 数据解析及日期和时间

前言 本章介绍python的JSON及日期和时间。 Python3 JSON 数据解析 JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。 Python3 中可以使用 json 模块来对 JSON 数据进行编解码&#xff0c;它包含了两个函数&#xff1a; json.dumps(): 对数据进行编码。json…

苏宁基于 AI 和图技术的智能监控体系的建设

汤泳&#xff0c;苏宁科技集团智能监控与运维产研中心总监&#xff0c;中国商业联合会智库顾问&#xff0c;致力于海量数据分析、基于深度学习的时间序列分析与预测、自然语言处理和图神经网络的研究。在应用实践中&#xff0c;通过基于 AI 的方式不断完善智能监控体系的建设&a…

C# 业务单据号生成器(定义编号规则、自动获取编号)

系列文章 C#底层库–数据库访问帮助类&#xff08;MySQL版&#xff09; 本文链接&#xff1a;https://blog.csdn.net/youcheng_ge/article/details/126886379 C#底层库–JSON帮助类_详细&#xff08;序列化、反序列化、list、datatable&#xff09; 本文链接&#xff1a;htt…

用友Java架构师面试

自我介绍。项目中的一些优化。Q&#xff1a;kafka消息的时序性怎么保证&#xff1f;A1&#xff1a; 核心意思就是要实现局部有序&#xff0c;需要有序的消息应设置相同的key&#xff0c;这样通过哈希取模后会分到同一个partition。又因为一个partition只能被一个consumer组中的…

智慧校园信息化管理平台技术方案

1.2总体架构设计 智慧校园平台是以学校现有网络为基础&#xff0c;以服务于全校师生的教学、科研、生活为目的&#xff0c;建立在学校数据中心平台之上&#xff0c;涵盖了学校的学校管理、学生管理、教学管理、班级管理、家校共育、教务管理等全方位的管理信息平台与信息服务平…

阿里P8经验分享 —— 送给想要学习自动化测试的同学6条建议

基于我的经验&#xff0c;送给想要学习自动化测试的同学6条建议 第一条建议&#xff1a;先学习编程语言&#xff0c;然后再接触自动化工具。 语言选择上Java或者Python都是可以的&#xff0c;可以先从Python入手&#xff0c;之后再开始Java。在学习语言的过程中&#xff0c;一…

playwright python环境运行报错 ImportError: DLL load failed

网上建议网上好多文章介绍playwright的环境搭建&#xff0c;用以下两条语句即可完成pip install playwrightplaywright install安装完毕后&#xff0c;尝试执行一段经典的python demofrom playwright.sync_api import sync_playwright with sync_playwright() as p: browser p…

seo优化案例截图

点击进入》》三支一扶课程聚合页面 百度统计数据 流量稳步增长&#xff0c; 2022年9月比2021年9月 同期增长 约30%。

SpringCloud - Nacos

目录 服务注册到Nacos 服务分级存储模型 NacosRule负载均衡 服务实例的权重设置 环境隔离 Nacos与Eureka的对比 添加Nacos配置 微服务配置拉取 配置热更新 多环境配置共享 服务注册到Nacos 1.在父工程引入SpringCloudAlibaba的依赖 2.注释掉order-service和user-ser…

@KafkaListener 详解及消息消费启停控制

参考&#xff1a;Kafka参数一、KafkaListener注解KafkaListener(id "11111", groupId "demo-group",topics Constants.TOPIC)public void listen(String msgData) {LOGGER.info("收到消息" msgData); } KafkaListener(id "22222"…

React系列之Redux

1 Redux概述 Redux 是 JavaScript 状态容器&#xff0c;提供可预测化的状态管理。Redux中文文档 Redux 和react没有必然关系&#xff0c;redux可以应用于各种框架&#xff0c;包括jquery&#xff0c;甚至js都可以使用redux&#xff0c;只不过redux和react更加搭配。redux也推…

javaee之git

一张图说明git 分支之间的操作 这个 框里面的linux命令都可以用 操作开始&#xff1a; 在master分支里面创建了一个hello.txt&#xff0c;并且放入了一些数据进去 这个去查一下日志 问题&#xff1a;当你放入了暂存区&#xff0c;你去查看日志会报错 一个分支这个指针head永…

Django框架之Django使用自带模板

Django使用自带模板 1 配置 在工程中创建模板目录templates。 在settings.py配置文件中修改TEMPLATES配置项的DIRS值&#xff1a; TEMPLATES [{BACKEND: django.template.backends.django.DjangoTemplates,DIRS: [os.path.join(BASE_DIR, templates)], # 此处修改APP_DIR…

vue-router 的基本用法

vue-router 的基本用法 1.什么是 vue-router vue-router 是 vue.js 官方给出的路由解决方案。它只能结合 vue 项目进行使用&#xff0c;能够轻松的管理 SPA 项目中组件的切换。 vue-router 的官方文档地址&#xff1a;https://router.vuejs.org/zh/ 2.vue-router 安装和配置的…

GIT分支管理策略

git基本操作git操作的前提条件:本地windows安装git学习idea中的插件使用idea的git基本操作:远程仓库remote更新fetch:git fetch拉取pull: git pull上传push: git push合并merge: git merge 合并分支本地提交commit:git commit分支branch: git branch 查看分支或者 切换分支上述…