我在 Alpine 服务器上安装了一个wireguard。它正在工作,但是当我重新启动服务器时,我必须手动执行 wg-quick up wg0
wireguard:~# wg show
wireguard:~# wg-quick up wg0
[#]
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.6.6.1/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] ip -6 route add fd9f:6666::1/128 dev wg0
[#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
wireguard:~# wg show
interface: wg0
public key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
private key: (hidden)
listening port: 51820
peer: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
preshared key: (hidden)
endpoint: xx.xx.xx.xx:49323
allowed ips: fd9f:6666::1/128, 10.6.6.2/32
latest handshake: 2 seconds ago
transfer: 7.05 KiB received, 6.31 KiB sent
wireguard:~#
wireguard:~# cat /etc/modules
af_packet
ipv6
wireguard
wireguard:~# cat /etc/wireguard/wg0.conf
# Updated: 2021-11-29 22:52:22.801259882 +0000 UTC / Created: 2021-11-29 19:52:59.17510794 +0000 UTC
[Interface]
Address = 10.6.6.1/24
ListenPort = 51820
PrivateKey = xxxxxxxxxxxxx=
PreUp =
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PreDown =
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
...
我的错误在哪里?
没有错误,你只需要为它设置一个OpenRC服务。在以下位置创建一个这样的初始化脚本
/etc/init.d/wg-quick
:然后运行以下命令为默认运行级别启用它:
感谢贾斯汀路德维希的回答。我没有测试您的解决方案,因为我已经设法解决了我的问题,修改
/etc/network/interfaces
如下: