./build-dh 命令完成后,我们会/usr/share/doc/openvpn/examples/easy-rsa/2.0/keys 得到 ca.crt、ca.key、dh1024.pem 等文件。其中,ca.key 的安全非常重要,OpenVPN 并不需要这个文件,所以可以存放在其他比较安全的地方,否则,OpenVPN 的通信将不再安全。 cp /usr/share/doc/openvpn/examples/easy-rsa/2.0/keys/server.crt /etc/openvpn/ cp /usr/share/doc/openvpn/examples/easy-rsa/2.0/keys/server.key /etc/openvpn/ cp /usr/share/doc/openvpn/examples/easy-rsa/2.0/keys/dh1024.pem /etc/openvpn/ cp /usr/share/doc/openvpn/examples/easy-rsa/2.0/keys/ca.crt /etc/openvpn/ 生成服务端证书 ./build-key-server server
生成客户端证书 ./build-key client
cp /usr/share/doc/openvpn/examples/server.conf.gz /etc/openvpn/ cd /etc/openvpn/ gzip -d server.conf.gz 配置服务端配置文件 vim server.conf server local 10.145.8.95 #更改为服务器内网IP port 1194 proto udp dev tun ca ca.crt cert server.crt key server.key # This file should be kept secret dh dh1024.pem server 172.16.1.0 255.255.255.0 push "redirect-gateway def1" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" client-to-client keepalive 10 120 comp-lzo comp-noadapt user daemon group daemon persist-key persist-tun status openvpn-status.log verb 3 开启nat转发 iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -o eth0 -j MASQUERADE
将ca.crt,client.crt,client.key,dh1024.pem copy到config目录下
在config目录下创建client.ovpn 编辑client.ovpn写入以下内容
client proto udp dev tun remote 119.28.1.124 1194 #更改为服务器外网IP ca ca.crt cert client.crt key client.key # This file should be kept secret dh dh1024.pem keepalive 10 120 comp-lzo comp-noadapt user daemon group daemon persist-key persist-tun status openvpn-status.log verb 3 注:部分云服务器是通过eth1通信,需要将上述配置中的eth0更改为eth1
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有