从春节假期之后,因为一些原因,就没有再使用 SS 作为访问互联网的工具了,而是使用了 V2ray,使用 2个月下来,感受还是很好的,无论是速度还是稳定性都要比 SS 好很多。最近看到好多新闻说 Wireguard 客户端适配多了起来,比如 Win,Mac,Android,今天尝试一下。
Wireguard
WireGuard is a free and open-source software application and protocol that implements virtual private network (VPN) techniques to create secure point-to-point connections in routed or bridged configurations. It is run as a module inside the Linux kernel and aims for better performance than the IPsec and OpenVPN tunneling protocols.[2]
Linus 的评价: Maybe the code isn't perfect, but I've skimmed it, and compared
to the horrors that are OpenVPN and IPSec, it's a work of art.
服务端配置
kernel 配置
环境配置为:CentOS Linux release 7.6.1810 (Core)
Kernel 版本: 4.20.3-1.el7.elrepo.x86_64
安装 kernel-devel kernel-headers
,注意,如果使用的是 elrepo
源,则需要安装对应版本的 kernel-ml-devel kernel-ml-headers
, 安装后状态:
1 | # rpm -qa |grep kernel |grep "4.20" |
安装 wireguard
yum install wireguard-dkms wireguard-tools
加载 Kernel module
modprobe wireguard && lsmod |grep wire
编辑 wireguard 配置文件
通过 ip ad
查看本机网卡名称,以 eth0
为例:
1 | #mkdir /etc/wireguard && cd /etc/wireguard |
启动服务
1 | #wg-quick up wg0 |
客户端配置
配置文件
1 | # wg genkey # 生成客户端 PublicKey |
服务端添加客户端信息
1 | #wg set wg0 peer <客户端公钥> allowed-ips 10.0.0.2/24 |
检查
在服务端查看主机路由信息:1
2
3# ip route show
default via 111.111.111.1 dev eth0
10.0.0.0/24 dev wg0 proto kernel scope link src 10.0.0.1
可以看到已经添加的 wireguard 网络默认路由是通过 10.0.0.1,所以我们需要开启地址转发功能:1
2
3#cat /etc/sysctl.conf
net.ipv4.ip_forward = 1
# sysctl -p
此时在服务端 ping 客户端 IP,也就是 10.0.0.2 ,检查状态:1
2
3
4# ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=334 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=335 ms
已经看到可以联通了。
整体上来说 Wireguard 配置上很简单,没有过多的配置文件,只是目前非 Linux 客户端都处于开发阶段,不推荐使用,尝鲜还是可以的。
配置文件示例
wg0
1 | [Interface] |
client.conf
1 | [Interface] |