Alpine의 Wireguard: 부팅 후 자동으로 wg0 마운트

Alpine의 Wireguard: 부팅 후 자동으로 wg0 마운트

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:~#

나는 이 문서를 적용했습니다:https://wiki.alpinelinux.org/wiki/Configure_a_Wireguard_interface_(wg)#Bringing_up_an_interface_using_wg-tools

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]
...

내 실수는 어디에 있습니까?

답변1

실수는 없습니다. 설정만 하면 됩니다.오픈RC그것을 위한 서비스. 다음과 같은 초기화 스크립트를 작성하십시오 /etc/init.d/wg-quick.

#!/sbin/openrc-run

description="WireGuard Quick"

depend() {
    need localmount
    need net
}

start() {
    wg-quick up wg0
}

stop() {
    wg-quick down wg0
}

그런 다음 다음 명령을 실행하여 기본 런레벨에 대해 활성화합니다.

rc-update add wg-quick default

답변2

귀하의 답변에 대해 Justin Ludwig에게 감사드립니다. /etc/network/interfaces다음과 같이 수정하여 문제를 해결했기 때문에 솔루션을 테스트하지 않았습니다 .

auto wg0
iface wg0 inet static
        address 10.6.6.1
        netmask 255.255.255.0
        post-up wg-quick up /etc/wireguard/wg0.conf
        post-down wg-quick down /etc/wireguard/wg0.conf

관련 정보