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
相关推荐
徐同保1 天前
nginx转发,指向一个可以正常访问的网站
linux·服务器·nginx
HIT_Weston1 天前
95、【Ubuntu】【Hugo】搭建私人博客:_default&partials
linux·运维·ubuntu
实心儿儿1 天前
Linux —— 基础开发工具5
linux·运维·算法
oMcLin1 天前
如何在SUSE Linux Enterprise Server 15 SP4上通过配置并优化ZFS存储池,提升文件存储与数据备份的效率?
java·linux·运维
SelectDB1 天前
驾驭 CPU 与编译器:Apache Doris 实现极致性能的底层逻辑
运维·数据库·apache
❀͜͡傀儡师1 天前
docker部署Arcane容器可视化管理平台
运维·docker·容器
老姚---老姚1 天前
docker常用命令
运维·docker·容器
深圳安锐科技有限公司1 天前
边坡倾斜自动化监测 倾角仪 如何通过安锐云查看监测曲线?
运维·视觉检测·实时监测·自动化监测·结构健康监测·倾斜角度监测·倾角传感器
咕噜企业分发小米1 天前
有哪些开源的直播云服务器安全防护方案?
运维·服务器·云计算
C_心欲无痕1 天前
nginx - 开启 gzip 压缩
运维·前端·nginx