port 1194
proto tcp/udp
dev tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
dh /etc/openvpn/dh.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
;push "route 0.0.0.0 0.0.0.0"
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
keepalive 5 30
comp-lzo
max-clients 100
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
log-append /tmp/openvpn.log
verb 3
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
iptables设置
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j MASQUERADE
iptables -F && iptables -X
service iptables save
service iptables restart
sysctl.conf设置
net.ipv4.ip_forward = 1
安装openvpn
yum install openvpn
安装easy-rsa
unzip master.zip && mv easy-rsa-master easy-rsa
cp -R easy-rsa /etc/openvpn
cp -R easy-rsa client/easy-rsa
cp easy-rsa/easyrsa3/vars.example vars
CA证书配置
根证书,其它证书基于根证书生成
./easyrsa init-pki
./easyrsa build-ca
这里需要输入二次密码,密码在生成子证书时要用上,不要随便按openvpn服务器证书
./easyrsa gen-req server nopass
生成一个server命名的证书./easyrsa sign server server
这里要输入创建根证书时的密码Diffie-Hellman文件,应该是数据传输过程的一个加密密钥
./easyrsa gen-dh
openvpn客户端证书
./easyrsa init-pki
./easyrsa gen-req devin nopass
./easyrsa import-req client/easy-rsa/easyrsa3/pki/reqs/devin.req devin
./easyrsa sign client devin
签名过程输入的common name跟server签名的name相同的话会出现客户端连接异常 *查看所有证书文件是否齐全启动openvpn服务
设置openvpn启动配置
启动服务
systemctl -f enable openvpn@server
systemctl start openvpn@server
systemctl restart openvpn@server
systemctl -l status openvpn@server
客户端连接
连接配置.ovpn文件