alpine安装WireGuard进行组网教程
1.服务器A安装WireGuard:
apk add wireguard-tools-wg-quick ip6tables
2.生成密钥(在/etc/wireguard目录可以看到)
wg genkey | tee privatekey | wg pubkey > publickey
3.创建/etc/wireguard/wg0.conf:
[Interface]
Address = fd00:1::1/64
PrivateKey = A_PRIVATE_KEY
ListenPort = 51820
PostUp = ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -A FORWARD -o %i -j ACCEPT
PostDown = ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -D FORWARD -o %i -j ACCEPT
[Peer]
PublicKey = B_PUBLIC_KEY
AllowedIPs = fd00:1::2/128, 2001:470:abcd:1::/64
4.在/etc/network/interfaces添加wg0以开机启动:
auto wg0
iface wg0 inet manual
pre-up wg-quick up wg0
post-down wg-quick down wg0
rc-service networking restart
5.服务器B安装WireGuard:
apk add wireguard-tools-wg-quick
6.创建/etc/wireguard/wg0.conf:
[Interface]
Address = fd00:1::2/64
PrivateKey = B_PRIVATE_KEY
PostUp = ip -6 route add default via fd00:1::1 dev wg0
[Peer]
PublicKey = A_PUBLIC_KEY
Endpoint = 服务器A的ip:51820
AllowedIPs = ::/0
PersistentKeepalive = 25
7.在/etc/network/interfaces添加:
auto wg0
iface wg0 inet manual
pre-up wg-quick up wg0
post-down wg-quick down wg0
rc-service networking restart