chunli@ubuntu:~/H3$ touch linux/.scmversion chunli@ubuntu:~/H3$ vim linux/arch/arm/configs/sunxi_defconfig 删除行 # CONFIG_WIREGUARD is not set 新增行 CONFIG_WIREGUARD=y 新增行 CONFIG_WIREGUARD_DEBUG=y
root@NanoPi-Duo2:~# git clone https://git.zx2c4.com/wireguard-tools root@NanoPi-Duo2:~# cd wireguard-tools/src/ root@NanoPi-Duo2:~/wireguard-tools/src# make root@NanoPi-Duo2:~/wireguard-tools/src# make install root@NanoPi-Duo2:~/wireguard-tools/src# cp systemd/wg-quick@.service /lib/systemd/system/
配置
生成秘钥对
1 2 3 4 5 6 7 8 9 10 11 12
root@NanoPi-Duo2:~# mkdir WG root@NanoPi-Duo2:~# cd WG/ root@NanoPi-Duo2:~/WG# wg genkey | tee 1_key | wg pubkey > 1_pub #当服务端 root@NanoPi-Duo2:~/WG# wg genkey | tee 2_key | wg pubkey > 2_pub #当客户端 root@NanoPi-Duo2:~/WG# wg genkey | tee 3_key | wg pubkey > 3_pub #当客户端
root@NanoPi-Duo2:~# wg-quick up /etc/wireguard/VPN.conf [#] ip link add VPN type wireguard [#] wg setconf VPN /dev/fd/63 [#] ip -4 address add 192.168.173.1/32 dev VPN [#] ip link set mtu 1420 up dev VPN [#] ip -4 route add 192.168.173.101/32 dev VPN [#] ip -4 route add 192.168.173.100/32 dev VPN [#] iptables -A FORWARD -i VPN -j ACCEPT; iptables -A FORWARD -o VPN -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE root@NanoPi-Duo2:~#
服务端关闭命令
1 2 3 4
root@NanoPi-Duo2:~# wg-quick down /etc/wireguard/VPN.conf [#] ip link delete dev VPN [#] iptables -D FORWARD -i VPN -j ACCEPT; iptables -D FORWARD -o VPN -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE root@NanoPi-Duo2:~#
作为系统服务
1 2 3 4 5
root@NanoPi-Duo2:~# systemctl enable wg-quick@VPN Created symlink from /etc/systemd/system/multi-user.target.wants/wg-quick@VPN.service to /lib/systemd/system/wg-quick@.service. root@NanoPi-Duo2:~# root@NanoPi-Duo2:~# systemctl restart wg-quick@VPN root@NanoPi-Duo2:~#
定时重启服务
有的时候 断网N小时, 网络恢复后.WG latest handshake 一直状态不成功.
1 2 3 4 5 6 7 8 9
# 每小时 重启1次 # 检测网路的连通性 root@localhost:~# vim /etc/crontab