利用Wireguard搭建公司到家的私有VPN网络

作为搞IT的我们。经常需要访问公司的云盘和其他内容。同时也需要在公司时访问家里的私有云盘数据和内部PC电脑的数据。

把这些数据全部映射到互联网上,是非常不安全的。如果采用常规的L2tp、PPTP等VPN方式。由于部署复杂,且不兼容手机。 如果采用专业VPN厂商的设备,又投入太高。不符合实际需求。

11.png

于是寻找到Wireguard。

本次以我家庭网络和公司网络作为参考。

12.png
一、什么是Wireguard

在官方的介绍上,Wireguard是一个Faster、Modern的VPN技术。我认为是Wireguard是一个快速、安全、对NAT穿越支持较好的VPN方式。

二、安装 Wireguard

wireguard支持常见的所有操作系统。包括Windows、Linux、MacOS、ISO、Android等; 安装方式如下:

Centos

$ yum update -y
$ reboot # unless there were no updates
$ sudo curl -Lo /etc/yum.repos.d/wireguard.repo https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo
$ sudo yum install epel-release
$ sudo yum install wireguard-dkms wireguard-tools

Ubuntu

$ sudo add-apt-repository ppa:wireguard/wireguard
$ sudo apt-get update
$ sudo apt-get install wireguard

Windows

X86_64: https://download.wireguard.com/windows-client/wireguard-amd64-0.0.20.msi

ISO

https://itunes.apple.com/us/app/wireguard/id1441195209?ls=1&mt=8

Android

https://play.google.com/store/apps/details?id=com.wireguard.android

三、配置Wireguard

Wireguard是基于端口、Key、shareKey三者来验证的。不采用固定形式。在运行后,需要在本段和远端生成PrivateKey和PublicKey。PublicKey共享给对端。PrivateKey来验证对端发过来的PublicKey是否是已知的和可信任的。

a.生成PrivateKey

wg genkey > privatekey

b.生成PublicKey根据生成的PrivateKey来生成对应的Publickey。

wg pubkey < privatekey > publickey

以上步骤,分别需要在本端和远端执行。

c.配置Virtual Interface信息部分配置参数描述

区域项目参数备注
localPrivateKeyLocal Private Key填写本端的PrivateKey
localListenPortLocal Port填写本端监听的端口,如果处于NAT内网,可以留空不写
localAddressVirtual IP Address虚拟接口的IP地址,两个
RemotePublicKey对端的PublicKey对端公钥
RemoteEndpoint对端地址:port可以是域名、IP和端口
RemoteAllowedIPsAllow IP Range允许通过的IP地址,支持IPv6
RemotePersistentKeepaliveKeepalive连接保活
Openwrt上的配置方式: 登录到Openwrt上。创建一个Interface接口。配置上本端的PrivateKey、Port、IPaddress;对端的Publickey、Port、IPaddress即可。 Linux下的配置方式 在Linux上,可以直接编写配置脚本文件。
[Interface]
table = off                            `禁止自动生成路由`
Address = 172.23.150.81/30            `虚拟接口的IP地址`
Address = fd00:abcd:e:0001:0000:0000:0001:81/112    `虚拟接口的IPv6地址`
ListenPort = 60205                    `本地监听端口,如果本地处于NAT内部,可以不写该参数`
PrivateKey = xxxxxxxxxxxxxxxxxxxx    `本端的私钥(PrivateKey)`
[Peer]
PublicKey = yyyyyyyyyyyyyy            `对端的公钥(PublicKey)`
AllowedIPs = 0.0.0.0/0,::/0            `允许通过的IP地址范围。0.0.0.0/0表示所有IP范围`
Endpoint = 114.114.114.114:60205    `对端IP地址和端口`
PersistentKeepalive = 30            `保活`

将上面配置文件放到/etc/wireguard/目录下。取名为xxxx.conf。然后wg-quick up xxxx启动该接口即可。

四、连接测试

C:\Users\yangy>tracert 192.168.200.1
通过最多 30 个跃点跟踪到 192.168.200.1 的路由
  1     6 ms     3 ms     3 ms  gateway [192.168.77.253]
  2     9 ms     9 ms    11 ms  node.150.23.172.in-addr.arpa [172.23.150.46]
  3     9 ms     8 ms     8 ms  192.168.200.1
跟踪完成。

标签: none

添加新评论