centos部署openvpn

centos部署openvpn

openvpn服务端

安装依赖组件

sh 复制代码
yum -y install epel-release openvpn easy-rsa net-tools bridge-utils

配置服务端证书

创建ca和证书,使用免密模式

sh 复制代码
cd /usr/share/easy-rsa/3
./easyrsa init-pki
./easyrsa build-ca
./easyrsa build-server-full server1 nopass
./easyrsa build-client-full client1 nopass
./easyrsa gen-dh
openvpn --genkey --secret ./pki/ta.key

复制证书到运行目录下

sh 复制代码
cp -pR /usr/share/easy-rsa/3/pki/{issued,private,ca.crt,dh.pem,ta.key} /etc/openvpn/server/

配置路由转发

修改内核参数

复制代码
vi /etc/sysctl.d/99-sysctl.conf
配置net.ipv4.ip_forward = 1
sysctl --system 

服务端配置说明

配置文件里的路径相对server.conf所在目录

sh 复制代码
cp /usr/share/doc/openvpn-x/sample/sample-config-files/server.conf /etc/openvpn/server/
vi /etc/openvpn/server/server.conf
txt 复制代码
## 为客户端分配的ip段
server 10.8.0.0 255.255.255.0
## 服务端内网网段例172.16.30.0则配置如下
push "route 172.16.30.0 255.255.255.0"
## 允许多客户端使用同一个证书连接
duplicate-cn
## 证书目录
ca ca.crt
cert issued/server1.crt
key private/server1.key
dh dh.pem
## 日志输出目录
status /var/log/openvpn/openvpn-status.log
log    /var/log/openvpn/openvpn.log
## 使用tcp时注释掉以下配置
;explicit-exit-notify 1

服务端启动

sh 复制代码
systemctl start openvpn-server@server
systemctl enable openvpn-server@server
systemctl status openvpn-server@server

配置允许访问同一网段

不配置则客户端只能访问vpn服务器所在ip。需添加路由表配置转发,例10.8.0.0/16是服务端server.conf为客户端分配的网段

sh 复制代码
iptables -t nat -A POSTROUTING -s 10.8.0.0/16 -j MASQUERADE

查看服务端日志

详见服务端server.conf里配置的日志目录

查看已接入的客户端

sh 复制代码
cat /etc/openvpn/server/ipp.txt

客户端使用

客户端证书

拷贝服务端生成的证书文件放到客户端config目录下

复制代码
/etc/openvpn/server/ca.crt
/etc/openvpn/server/ta.key
/etc/openvpn/server/issued/client1.crt
/etc/openvpn/server/private/client1.key  

windows客户端配置

从服务端拷贝sample.ovpn配置编辑,也放在config目录下

复制代码
/usr/share/doc/openvpn-x/sample/sample-windows/sample.ovpn

客户端配置说明

复制代码
## vpn服务端所在公网ip和vpn服务端口
remote x.x.x.x 1194
## 客户端证书
ca ca.crt
cert client1.crt
key client1.key 
tls-auth ta.key 1
## 设备类型和服务端配置一致
dev tun
## 协议要和服务端配置一致
proto tcp
相关推荐
蓝速科技41 分钟前
会议室门牌公告通知发布选型与落地指南丨蓝速科技
大数据·运维·数据库·人工智能·科技
chicheese1 小时前
Linux 面试速查表:从初级到高级,附高频场景答题模板
linux·运维
Linux-lucky2 小时前
32-38-Linux学习之旅之MySQL综合
linux·运维·学习·mysql·ubuntu
智能运维指南2 小时前
2026年ITSM系统怎么选?四款主流方案与五维评估模型
运维·itsm·嘉为蓝鲸
vortex53 小时前
常用终端模拟器全面对比:Kitty、WezTerm、Ghostty 与 Konsole
linux
我命由我123453 小时前
Git 推送报错:error: src refspec main does not match any
运维·git·gitee·github·运维开发·学习方法·版本控制
骇客野人3 小时前
测试环境MySQL迁移Vastbase(海量数据库)完整改造与落地实施方案
运维·服务器
迪康Defender3 小时前
终端安全实战:如何高效解决企业U盘泄密与管控难题
运维·网络·安全·web安全·终端安全管理
INGNIGHT4 小时前
270 · 电话号码的字母组合II(Trie)
linux·算法
zly35004 小时前
VMware Converter Standalone 物理机转化为虚拟机后源1硬盘变成了2个硬盘(2个硬盘文件)虚拟机无法启动。
linux·运维·服务器