DockerコンテナまたはWSL2自体でWireguardクライアントを実行しようとすると、次の問題が発生します。
2022-04-27 17:15:45,035 DEBG 'start-script' stderr output:
[#] ip -4 rule add table main suppress_prefixlength 0
2022-04-27 17:15:45,036 DEBG 'start-script' stderr output:
[#] sysctl -q net.ipv4.conf.all.src_valid_mark=1
2022-04-27 17:15:45,036 DEBG 'start-script' stderr output:
[#] iptables-restore -n
2022-04-27 17:15:45,247 DEBG 'start-script' stderr output:
iptables-restore v1.8.7 (legacy): unknown option "--save-mark"
Error occurred at line: 5
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
2022-04-27 17:15:45,247 DEBG 'start-script' stderr output:
[#] resolvconf -d wg0 -f
2022-04-27 17:15:45,251 DEBG 'start-script' stderr output:
could not detect a useable init system
2022-04-27 17:15:45,267 DEBG 'start-script' stderr output:
[#] ip -4 rule delete table 51820
2022-04-27 17:15:45,270 DEBG 'start-script' stderr output:
[#] ip -4 rule delete table main suppress_prefixlength 0
2022-04-27 17:15:45,283 DEBG 'start-script' stderr output:
[#] ip link delete dev wg0
2022-04-27 17:15:45,456 DEBG 'start-script' stdout output:
[warn] WireGuard interface failed to come 'up', exit code is '1'
それともこれを見て
sh-5.1# wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.8.130.27 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] wg set wg0 fwmark 51820
[#] ip -4 route add 0.0.0.0/0 dev wg0 table 51820
[#] ip -4 rule add not fwmark 51820 table 51820
[#] ip -4 rule add table main suppress_prefixlength 0
[#] sysctl -q net.ipv4.conf.all.src_valid_mark=1
[#] iptables-restore -n
iptables-restore v1.8.7 (legacy): unknown option "--save-mark"
Error occurred at line: 5
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
[#] ip -4 rule delete table 51820
[#] ip -4 rule delete table main suppress_prefixlength 0
[#] ip link delete dev wg0
sh-5.1#
これは同じエラーメッセージですが、範囲が狭くなりました。
ベストアンサー1
原因は、WSL2カーネルが必要なnetfilterターゲットまたは一致するiptablesまたはnftables操作でコンパイルされていないためです。
次のコマンドを実行してこれを確認できます。
$ iptables -C INPUT -m connmark --mark 0x10/0x10 -j DROP
iptables v1.8.4 (legacy): Couldn't load match `connmark':No such file or directory
WSLインストールに付属のLinuxカーネルにはこのCONFIG_NETFILTER_XT_MATCH_CONNMARK
フラグはありませんでした。
まず、Microsoftが使用するカーネルソースコードをインポートする必要があります。次のコマンドを使用してgithubページからインポートできます。
git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel.git
現在のカーネル構成をコピーするには、次のコマンドを使用します。
zcat /proc/config.gz > .config
sed を使用した検索と置換
sed -i 's/# CONFIG_NETFILTER_XT_MATCH_CONNMARK is not set/CONFIG_NETFILTER_XT_MATCH_CONNMARK=y/g' .config
これで正しいフラグを有効にしてカーネルをコンパイルできます。使用:
yes "" | make -j $(nproc)
yes ""
指定されていない設定に対して Enter キーを押し、デフォルト値を入力すると機能します。
$(nproc)
CPUが処理できるスレッドの数。
次に、新しくコンパイルされたカーネルイメージをWindows側にコピーする必要があります。以下を使用してコピーできます。
cp arch/x86_64/boot/bzImage /mnt/c/Users/<user>/bzImage
構成ファイルを追加して、WSLに新しいカーネルを使用するように指示します。
フォルダには、次のファイルが含まれている必要が/mnt/c/Users/<user>/
あります。C:\Users\<user>\
.wslconfig
[wsl2]
kernel=C:\\Users\\<user>\\bzImage
WSLをオフにしてプロンプトでオフにしますcmd
。
wsl --shutdown
次にstart wslを使用してくださいwsl
。uname -r
これで、新しいカーネルを使用していることがわかります。
さて、上記のエラーは消えなければならず、Wireguardクライアントが正しく機能していることを願っています。