阿里云ECS vpc网络与办公网内网互通

news/2024/7/23 10:50:00 标签: 阿里云, 网络, 服务器

        公网远程操作很不安全,因此决定使用内网互通模式,虽然阿里云有自带的vpn,但是太贵了,身为运维的我,一定要为公司省钱,只能想想法子,自己搭建一套内网vpn使用

环境:

阿里云vpc网络的ecs

办公网使用的ikuai 软路由

系统是centos8

网络:该服务器 10.81.184.196/16, 该网段内有好多阿里云服务器,其中一台ip为  10.81.184.186,本次就是办公网可以与 10.81.184.186 互通

要求:办公网使用内网可以随意访问阿里云服务器

  1. 搭建openvpn服务

  2. 添加路由表

  3. 配置openvpn内网访问策略

  4. 在ikuai添加阿里云内网访问路由

搭建步骤

1.搭建openvpn服务

dnf install epel-release -y 
dnf install openvpn easy-rsa -y

配置 

cd /etc/openvpn/
rm -rf client/* rm -rf easy-rsa/
cp -r /usr/share/easy-rsa/3.0.8/ /etc/openvpn/easy-rsa
cp -r /usr/share/doc/easy-rsa/vars.example /etc/openvpn/easy-rsa/vars

生成证书

cd /etc/openvpn/easy-rsa/
./easyrsa init-pki
./easyrsa build-ca nopass                 #输入 vpn.dvcloud.xin

创建服务器证书

./easyrsa gen-req server nopasss            #输入  vpn.dvcloud.xin
./easyrsa sign server server                #输入  yes
 

创建 Diffie-Hellman 

./easyrsa gen-dh
openvpn --genkey --secret ta.key
cp -r ta.key /etc/openvpn/

创建客户端证书

#Monday,Tuesday、Wednesday、Thursday、Friday、Saturday 、Sunday

cd /etc/openvpn/client/
rm -rf easy-rsa/
\cp -r /usr/share/easy-rsa/3.0.8/ /etc/openvpn/client/easy-rsa
\cp -r /usr/share/doc/easy-rsa/vars.example /etc/openvpn/client/easy-rsa/vars
cd /etc/openvpn/client/easy-rsa/
./easyrsa init-pki
./easyrsa gen-req client nopass        #输入  Monday
cd /etc/openvpn/easy-rsa/
find pki -name "client*" -delete
./easyrsa import-req /etc/openvpn/client/easy-rsa/pki/reqs/client.req client
./easyrsa sign client client            #输入  yes

   

整理证书

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

# one two three four five

整理客户端

mkdir /etc/openvpn/client/Monday
cd /etc/openvpn/client/Monday
cp /etc/openvpn/easy-rsa/pki/ca.crt .
cp /etc/openvpn/easy-rsa/pki/issued/client.crt .
cp /etc/openvpn/easy-rsa/pki/private/ca.key .
cp /etc/openvpn/ta.key .
cp /etc/openvpn/client/easy-rsa/pki/private/client.key .
#服务器配置如下
[root@devops openvpn]# grep '^[^;|^#]' /etc/openvpn/server/server.conf
port 31393
proto udp
dev tun
ca /etc/openvpn/certs/ca.crt
cert /etc/openvpn/certs/server.crt
key /etc/openvpn/certs/server.key
dh /etc/openvpn/certs/dh.pem
server 192.168.60.0 255.255.255.0
push "route 10.81.0.0 255.255.0.0"
client-to-client
duplicate-cn
keepalive 10 120
tls-auth /etc/openvpn/ta.key 0
cipher AES-256-CBC
comp-lzo
persist-key
persist-tun
status openvpn-status.log
log-append  openvpn.log
verb 3
mute 20
explicit-exit-notify 1

打开ip转发功能

vim /etc/sysctl.conf

#增加下行到文件中
net.ipv4.ip_forward = 1

#然后执行命令
sysctl -p

启动服务

systemctl start openvpn-server@server.service

可以看的,openvpn的网络是  192.168.60.0 255.255.255.0  ,推送的路由是 10.81.0.0 255.255.0.0  ,10.81.0.0 255.255.0.0这个路由就是阿里云ecs vpc网络

2.添加路由表

路由表下一跳填写 阿里云服务器搭建openvpn的ecs实例

3.配置openvpn内网访问策略

这个需要在安全组进行配置

打开被访问服务器的安全组,添加openvpn访问路由的ip 

4.在ikuai 添加openvpn 客户端配置

保存之后,通过本地电脑访问

发现可以正常访问,第一条是ikuai路由器网关,第二条是openvpn 网关,第三条是目标服务器地址


http://www.niftyadmin.cn/n/1265360.html

相关文章

项目管理之jira 9.1安装

系统环境centos8 官方文档 Installing Jira applications on Linux | Administering Jira applications Data Center and Server 9.1 | Atlassian Documentation 1.下载程序包 a,访问下载连接,进行下载最新的安装包 更新 Jira Software Server | Atlassian # 软件…

frp使用oidc认证和搭建

frp 是什么? frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网 github源码:https://github.com/fatedier/frp/ 官方文档&…

容器化部署mariadb数据库

compose文档:Compose specification | Docker Documentation 容器地址及文档:Docker Hub 部署环境依赖 1.docker-ce安装 a.卸载老版本的docker sudo yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-l…

kms服务器搭建及测试

vlmcsd代码仓库:https://github.com/Wind4/vlmcsd 搭建步骤 本次操作环境centos7,通过内网进行搭建 1.安装依赖环境 yum install gcc git make -y 2.下载源码,编译安装 cd /var/opt/ git clone https://github.com/Wind4/vlmcsd.git cd vlmcs…

知识库协同confluence7.19安装

系统环境centos8 官方文档:Installing Confluence | Confluence Data Center and Server 7.19 | Atlassian Documentation docker安装:Docker Hub 本次是通过压缩包安装 1.下载程序包 a,访问下载连接,进行下载最新的安装包 Confluence Serv…

Django 增加自定义加密字段

前言 由于业务需求,并且保证数据安全行,某些数据字段需要加密,比如用户身份等隐私数据。 数据加密情况下,假设被脱库,也不会丢失用户隐私数据 实现 AES的优点是比较快,缺点就是密钥的保密很关键&#xff0…

Django DRF 排序过滤查询filter and order

前言 某些需求,前端可能需要后端数据的过滤,排序条件来查询数据,但是自己写这些接口又很是费劲,这不,今天推荐一个第三方包 django_filters GitHub - carltongibson/django-filter: A generic system for filtering …

js计算大文件sha1值,分块计算

计算文件hash,使用到了模块 js-sha1 该模块文档:GitHub - emn178/js-sha1: A simple SHA1 hash function for JavaScript supports UTF-8 encoding. 主要思路就是通过内置方法 slice 分块按顺序计算hash值 import sha1 from js-sha1export async function Content…