V**直译就是虚拟专用通道,是提供给企业之间或者个人与公司之间安全数据传输的隧道,OpenV**无疑是Linux下开源V**的先锋,提供了良好的性能和友好的用户GUI。
下面通过在如下拓扑图环境下搭建OpenV** Server,介绍如何在CentOS7下搭建OpenV** Server
由于没有公网IP进行模拟,在路由器LAN一侧(192.168.60.X)的CentOS7服务器上搭建OpenV** Server,在路由器WAN一侧(192.168.31.X)的Windows机器上使用V** Client拨入V**进行测试
下面先介绍OpenV** Server的搭建
1)先yum install -y epel-release
yum install -y install openV** easy-rsa net-tools bridge-utils
2)创建CA和证书
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 生成DH需要等待一段时间
[root@CentOS7_DIY 3]# ./easyrsa gen-dh
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
.................................................................................. ...
.......
.................................................................................. ........ * *
DH parameters of size 2048 created at /usr/share/easy-rsa/3/pki/dh.pem
3)创建TLS-Auth Key
openV** --genkey --secret ./pki/ta.key
cp -pR /usr/share/easy-rsa/3/pki/{issued,private,ca.crt,dh.pem,ta.key} /etc/openV**/server/
4)内核参数中开启ipv4 forwarding
cd /etc/sysctl.d/
vi 99-sysctl.conf
追加net.ipv4.ip_forward = 1
sysctl --system
5)配置OpenV** Server
cp /usr/share/doc/openV**-2.4.7/sample/sample-config-files/server.conf /etc/openV**/server/
vi /etc/openV**/server/server.conf
需要修改的地方如下
# line 32: change if need (listening port of OpenV**)
port 1194
# line 35: change if need
;proto tcp
proto udp
# line 78: specify certificates
ca ca.crt
cert issued/server1.crt
key private/server1.key
# line 85: specify DH file
dh dh.pem
# line 101: specify network to be used on V**
# any network are OK except your local network
server 10.8.0.0 255.255.255.0
# line 143: uncomment and change to your local network
push "route 192.168.60.0 255.255.255.0"
# line 231: keepalive settings
keepalive 10 120
# line 244: specify TLS-Auth key
tls-auth ta.key
# line 263: uncomment (enable compress)
comp-lzo
# line 281: enable persist options
persist-key
persist-tun
# line 287: change log path
status /var/log/openV**-status.log
# line 296: change log path
log /var/log/openV**.log
log-append /var/log/openV**.log
# line 306: specify log level (0 - 9, 9 means debug lebel)
verb 3
6)启动openV**-server服务并设置开机自启动
[root@CentOS7_DIY ~]# systemctl start openV**-server@server
[root@CentOS7_DIY ~]# systemctl enable openV**-server@server
7)路由器上需要将V** Server 192.168.60.13服务端口udp 1194映射到外网192.168.31.22的1194端口
8)V** Client端下载安装V**
openV**官网可以下载
并将如下四个文件从V** Server上sz下载下来,拷贝到V** Client的安装目录下config文件夹
/etc/openV**/server/ca.crt /etc/openV**/server/ta.key /etc/openV**/server/issued/client1.crt
/etc/openV**/server/private/client1.key
并从C:Program FilesOpenV**sample-config拷贝client.oV**文件到config目录下进行编辑
添加及修改如下字段
remote 192.168.31.22 1194
ca ca.crt
cert client1.crt
key client1.key
tls-auth ta.key 1
comp-lzo
修改完成后重命名为client1.oV**
9)打开OpenV** GUI 连接V**
这时测试发现连接不上
查看服务器上openV**.log日志有如下报错
通过搜索报错信息,查到的解决方案为
key-direction 0 (on server)
key-direction 1 (on client)
在服务端加TLS配置后面添加key-direction 0
vi server.conf
修改后 systemctl restart openV**-server@server
在客户端client1.oV**配置添加key-direction 1
再重新连接V**,就可以连接上了
10) 连上V**后,获取到V**地址为10.8.0.X段地址,ping 内网OpenV** Server的内网地址 192.168.60.113可以ping通
这时发现ping不通192.168.60.254等内网其它地址
需要在内网路由器上加一条静态路由,目的网络为V**网段
10.8.0.0/24,下一跳为V**服务器的内网地址192.168.60.113
加上这条路由之后,就可以ping通192.168.60.X的服务器,并访问192.168.60.X的服务器业务了