-1

我在 Windows 11、WSL2、内核 5.10.60.1-microsoft-standard-WSL2 上。

我正在使用 RHEL 发行版,并且正在尝试启用 netfilter NAT 规则。问题是如果我尝试将规则添加到 Pre 或 PostRouting 的 NAT 表中,我会收到此错误:

[root@rhel8 nftables]# nft add chain nat prerouting { type nat hook prerouting priority 0 \; }
Error: No such file or directory
add chain nat prerouting { type nat hook prerouting priority 0 ; }
          ^^^

我的谷歌搜索让我相信我需要添加一些内核配置才能使其工作,但从我可以从 Microsoft 默认值中看出,一切似乎都已打开。如果那里有内核专家可以给我一个提示,我将不胜感激!

4

1 回答 1

0

为了任何遇到此错误的人的繁荣:

我提取了 microsoft WSL 内核(https://github.com/microsoft/WSL2-Linux-Kernel.git),然后将 ./Microsoft/config-wsl 复制到 .config 以播种内核编译。

跑过make config答案,直到编译的 netfilter 部分,然后对 netfilter 的整个部分回答是,包括 NAT 等。

make -j $(nproc)

编译内核后,我将 x86(不是 x86_64)./arch/x86/boot/bzImage 复制到 Windows 文件系统(/mnt/c/users/me/xxxx)上可访问的位置。

然后进行备份,然后编辑您的c:\users\me\.wslconfig内核并将其更新为新内核(请记住,您必须\\在内核路径中使用,例如c:\\users\\me\\bzimage_custom。最后重新启动 WSL 以启动新内核:

wsl --shutdown
wsl -d mydistro

然后您将拥有可用的 NAT :)。

于 2021-10-20T00:43:06.623 回答