WSL: Adding nftables sets doesn't work on WSL 2

Environment

Microsoft Windows [Version 10.0.19041.508] Ubuntu 20.04 WSL 2

Steps to reproduce

After installing nftables (my version from repo: 0.9.3) and trying to configure named set in specified table - i’m getting an error.

$ sudo nft add table inet test_table
$ sudo nft add chain inet test_table test_chain {type filter hook input priority 0\;}
$ sudo nft add set inet test_table my_set {type ipv4_addr\;}
Error: Could not process rule: Operation not supported
add set inet test_table my_set {type ipv4_addr;}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expected behavior

The set must be created and displayed in listing (nft list ruleset)

Actual behavior

I got the following error: “Could not process rule: Operation not supported”

GitHub_issue

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 14
  • Comments: 17 (1 by maintainers)

Most upvoted comments

@panktrip I had to do something similar to what was referenced in another ticket.

update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

Is this being addressed? I can’t run native docker without reverting back to legacy iptables, which I can imagine is not going to be around forever. What is a longer-term path to run native docker? Ticket 6655, which was closed as a dup of this, describes the symptoms/effect very well.

If you are running into this problem from an RPM-based distribution, many of the fixes given may not work for you. Specifically, I ran into this issue using the AlmaLinux-8 distro running under distrod (to enable the use of systemd). I originally went down the path of trying to find and install the legacy version of iptables (xtables-legacy-multi) to use the same fix mentioned above; however, after spending many hours in (unsuccessfully) trying to find that package in non-Fedora yum repositories, I pivoted to fixing the issue in the kernel instead.

As referenced by @therealkenc, the issue of supporting the newer, nftables-based iptables is that the proper interfaces are not available in the standard WSL kernel; however, the interfaces exist in the code - they just need to be configured on / compiled in. Here is how I went about fixing the issue in AlmaLinux-8 (under distrod) starting from a fresh install:

  1. Install requisite packages for building the kernel (thanks to this guide for pointing me in the right direction)
    1. sudo dnf config-manager --set-enabled powertools
    2. sudo dnf group install "Development Tools"
    3. sudo dnf install ncurses-devel binutils-devel openssl-devel python39 dwarves
  2. Clone the kernel repo: git clone https://github.com/microsoft/WSL2-Linux-Kernel.git kernel (note that the default checkout branch is probably what you will need, but run uname -r and make sure the version of kernel you have corresponds to the branch you are checked out to in the repo)
  3. Configure the kernel build
    1. cd kernel
    2. cp Microsoft/config-wsl .config
    3. make menuconfig
    4. At this point, you are presented with a dialog text UI (TUI) that allows you to configure which modules are built into the kernel. Descend down into Networking Support → Networking options → Network packet filtering framework (Netfilter), and find any option having to do with nf_tables and enable it (including under the Core Netfilter Configuration sub-menu). I readily admit that I do not know which subset of these options is actually required for iptables using nf_tables to work, so I just blanket enabled them all.
    5. (Optional) Exit back up to the top-level menu and go into General setup → Local version - append to kernel release, then change the name to something that reflects the kernel modifications (this is just to easily keep track of what kernel you are using at runtime)
    6. Save and Exit back out of the menus
  4. Build the kernel: make KCONFIG_CONFIG=.config -j $(nproc)
  5. Copy the kernel outside of the VM: cp arch/x86/boot/bzImage /mnt/c/Users/<YOUR USER>/kernel
  6. Follow the instructions for global WSL configuration to point to the kernel file you just copied
  7. Shutdown WSL: wsl --shutdown
  8. Re-launch your distro

At this point, if you performed the optional step to give a custom kernel postfix, you can run uname -r to ensure you are using the new kernel. If so, then try restarting the docker daemon (i.e. sudo systemctl restart docker) and confirm that it is up and running.

I realize this is a heavy-handed approach, but I hope it can help any folks using an RPM-based distribution until the problem is officially addressed either by docker or by the WSL standard kernel.

Secondly, I realize that RPM-based distributions have moved towards the use of podman, but I have seen reports of similar issues with iptables, especially when using sudo podman, so hopefully this can help in that scenario as well. As a side note, if you want to be able to install both podman and docker at the same time in AlmaLinux-8 (for example, to play nicely with Jenkins pipelines or if podman features are unstable), you can follow this guide to do so.

Nothing is resolved here

This issue has been automatically closed since it has not had any activity for the past year. If you’re still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

There are some others vs. Ububtu’s expected kconfig:

CONFIG_NF_TABLES_SET
CONFIG_NF_TABLES_NETDEV
CONFIG_NF_TABLES_ARP
CONFIG_NF_TABLES_BRIDGE

image

Thanks a lot @kobenauf . This worked for me on Ubuntu-22.04 in WSL2.