#修改配置
vim /etc/openvpn/server.conf
#打开这个配置, ccd文件夹,相对路径,和配置server.conf同一路径
client-config-dir ccd
#绝对路径 /etc/openvpn/ccd
client-config-dir /etc/openvpn/ccd
#比如:pk用户
cat /etc/openvpn/ccd/pk
ifconfig-push 10.8.0.21 10.8.0.22
#pk用户的固定IP为: 10.8.0.21
#ifconfig-push ${IP} ${NETMASK}
#若是使用net30子网的时候${NETMASK}就是${IP}的下一位,好比ifconfig-push 10.8.0.1 10.8.0.2
在此示例中,10.8.0.21是分配给客户端的固定IP地址,10.8.0.22是服务器端的对等地址。
此处ip需要对等配置,注意配置合适,否则会出现以下错误:
There is a problem in your selection of --ifconfig endpoints [local=10.8.0.21, remote=10.8.0.22]. The local and remote VPN endpoints must exist within the same 255.255.255.252 subnet. This is a limitation of --dev tun when used with the TAP-WIN32 driver. Try ‘openvpn --show-valid-subnets’ option for more info.
重点:255.255.255.252子网掩码允许每个子网中有4个IP地址,其中2个是可用的IP地址,1个是网络地址,1个是广播地址。
例如:
10.8.0.0/30子网范围:10.8.0.0 - 10.8.0.3
可用IP对:10.8.0.1和10.8.0.2
10.8.0.4/30子网范围:10.8.0.4 - 10.8.0.7
可用IP对:10.8.0.5和10.8.0.6
确保您为每个客户端分配的IP地址对位于同一个子网范围内。
openvpn服务端参考配置文件如下
[root@test-machine openvpn]# cat server.conf
# 配置
port 8199 #openVPN端口
proto tcp #tcp连接
dev tun #生成tun0虚拟网卡
ca keys/ca.crt #相关证书配置路径(可以修改为全路径/etc/openvpn/keys)
cert keys/server.crt
key keys/server.key # This file should be kept secret
dh keys/dh2048.pem
server 10.4.82.0 255.255.255.0 #默认虚拟局域网网段,不要和实际的局域网冲突就可以
ifconfig-pool-persist ipp.txt
client-config-dir /etc/openvpn/ccd #固定客户端IP文件夹的路径
push "route 10.4.82.0 255.255.255.0" #可以通过iptables进行路由的转发
client-to-client #如果客户端都是用一个证书和密钥连接VPN,需要打开这个选项;(配置后客户端之间可以互相访问)
duplicate-cn
keepalive 10 120
tls-auth keys/ta.key 0 # This file is secret
comp-lzo
persist-key
persist-tun
status openvpn-status.log #状态日志路径
log-append openvpn.log #运行日志
verb 3 #调试信息级别
- 安装openvpn服务端参考:https://i4t.com/4481.html
- 本文参考:https://blog.51cto.com/u_15454062/4924216
评论区