I'm on Windows 11, WSL2, kernel 5.10.60.1-microsoft-standard-WSL2.
I'm using a RHEL distribution and I'm trying to enable a netfilter NAT rule. The problem is I receive this error if I try to add a rule to the NAT table for Pre or PostRouting:
[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 ; }
^^^
My googling leads me to believe that I need to add some kernel configuration in order to make this work, but from what I can tell from the Microsoft defaults, everything appears to be switched on. If there is a kernel guru out there who can give me a hint I'd appreciate it!
For prosperity for anyone who hits this error:
I pulled the microsoft WSL kernel (https://github.com/microsoft/WSL2-Linux-Kernel.git) then copied the ./Microsoft/config-wsl to .config to seed the kernel compilation.
Ran
make config
to step through the answers until the netfilter section of the compilation, then answered yes to the entire section on netfilter, including NAT etc.Once the kernel compiled, I copied the x86 (not x86_64) ./arch/x86/boot/bzImage to something reachable on the windows file system (
/mnt/c/users/me/xxxx
).Then make a backup of, then edit your
c:\users\me\.wslconfig
and update kernel to be the new kernel (remembering that you must use\\
in the path to the kernel e.g.c:\\users\\me\\bzimage_custom
. Finally restart WSL to boot the new kernel:Then you will have NAT available :).