适用于家庭网络的 Wireguard VPN,带有 raspbery pi4 8Gb(64 位)

适用于家庭网络的 Wireguard VPN,带有 raspbery pi4 8Gb(64 位)

我一直尝试在我的家庭网络上设置 wirguard VPN,但一直很沮丧,我想我已经解决了所有常见问题,但当我显然连接到 VPN 时,我仍然无法访问互联网或家庭网络上的东西。

在我自己无法让它工作之后,我重新映像了我的驱动器并尝试了 PIVPN 的安装脚本,不幸的是,这不适用于我正在运行的 64 位 Raspberry Pi 操作系统,因为我使用的是 8Gb pi4。我不认为软件包存储库中的 dkms 模块是为 64 位 arm 构建的,因为我无法安装它,所以我从源代码构建了它,并且成功了。在撰写本文时,内核 5.4 用于 64 位 pi os buster 映像,因此 wireguard 需要 dkms 模块。如果您手动构建它们或者如果您更新到已经内置它们的较新内核(我尝试了 5.10sudo BRANCH=next rpi-update并在任何内核更改后重新启动),PIVPN 仍然希望从存储库安装 dkms 模块,所以我放弃了 PIVPN 并重新尝试自己做。

我检查过的常见问题:

  • 端口 51820 已转发到路由器上的 pi(UDP)

  • 我的动态 DNS 指向我的家庭 IP - 我可以使用我的公共地址 ssh 到我网络上的另一台主机

  • 我认为密钥对是正确的,我已经手动仔细检查过,并且从我尝试过的对等点来看,连接似乎可以正常工作,除非密钥认证悄悄失败,但我怀疑情况并非如此。

  • net.1pv4.ip_forward=1(我没有更改ipv6)

  • 我还没有在树莓派上设置防火墙,所以这不碍事

这是我的配置文件:

更新我设法通过改变 PostUp/Down 线并添加持久保持功能来使其工作。

wg0.conf

[Interface]
Address = 10.9.0.1/24
ListenPort = 51820
# DNS = ip.of.home.router # tried with and without, also 8.8.8.8 not sure if this is supposed to be local or not
PrivateKey = "Server"privatekey=

# eth0 is the correct name for my network Interface
# I have tried it with and without these lines as some guides I have read include them an others don't and I'm not clear on what exactly they do
# Old:
# PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

# New
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE


[Peer]
#peer1
PublicKey = "peer"publickey=
AllowedIPs = 10.9.0.2/32

peer1 配置文件

[Interface]
Address = 10.9.0.2/32
# DNS = ip.of.home.router # tried with and without, also 8.8.8.8 not sure if this is supposed to be local or not
PrivateKey = "peer"privatekey= 

[Peer]
PublicKey = "host"publickey= 
Endpoint = mydomain.me:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentkeepAlive = 30

我使用 为 wireguard 启用了 systemd 服务sudo systemctl enable wg-quick@wg0,当我使用 检查时,它报告自身处于活动状态sudo systemctl status wg-quick@wg0

(我将此二维码发送到我的手机上,以qrencode -t ansiutf8 < /etc/wireguard/peer1.conf使用移动数据从网络外部测试连接)

我对网络方面的东西还很陌生——我是否错过了一些显而易见的东西?

显然,动态调试日志记录是内核 5.6 之后的功能,因此我将在内核 5.10 上再次尝试日志记录,这样我就可以尝试获取一些错误消息,这些消息会为我指明正确的方向,同时我等待看看你们中是否有好心人可以提供任何帮助 - 谢谢。

(交叉发布自https://serverfault.com/questions/1047909/wireguard-vpn-for-home-network-with-raspbery-pi4-8gb-64bit?noredirect=1#comment1364340_1047909有人告诉我这是题外话)


wgpi4 对等体上的输出

interface: wg0
  public key: *key*
  private key: (hidden)
  listening port: 51820

peer: *key*
  endpoint: peer1.pub.lic.ip:57681
  allowed ips: 10.9.0.2/32
  latest handshake: 2 hours, 20 minutes, 56 seconds ago
  transfer: 14.59 KiB received, 564 B sent

wg showconf wg0pi 对等体上的输出

[Interface]
ListenPort = 51820
PrivateKey = *key*

[Peer]
PublicKey = *key*
AllowedIPs = 10.9.0.2/32
Endpoint = peer1.pub.lic.ip:57681

ip route在 pi4 上运行得到:

default via *local router IP* dev eth0 proto dhcp src *pi4 local IP* metric 202 
10.9.0.0/24 dev wg0 proto kernel scope link src 10.9.0.1 
192.168.1.0/24 dev eth0 proto dhcp scope link src 192.168.1.108 metric 202

相关内容