How to Fix ‘iptables: No chain/target/match by that name’ in Linux

Configuring firewall rules, port forwarding, or NAT masquerading in Linux terminal environments using the iptables utility can result in an abrupt failure: “iptables: No chain/target/match by that name”. This error occurs despite entering syntactically valid parameters. Rather than indicating an unknown command switch, this message indicates that the Linux kernel cannot locate the specified user-defined chain, the requested target extension module (such as MASQUERADE or REDIRECT) is not loaded into memory, or a backend conflict exists between traditional iptables-legacy and modern nftables.

Why Does iptables Return ‘No chain/target/match by that name’?

Netfilter is modular inside the Linux kernel. When an iptables rule references a specific table, match condition, or target action, the kernel dynamically loads the corresponding kernel module. Common triggers for this error include:

  • Missing Kernel Modules in Containers or Minimal Kernels: Inside Docker containers, LXC instances, or virtual private servers (VPS) running stripped-down kernels, core modules like xt_MASQUERADE, iptable_nat, or nf_conntrack are not loaded or permitted.
  • Mismatched iptables Backend (Legacy vs nftables): Modern distributions (Debian, Ubuntu, Red Hat) use an iptables-nft translation wrapper by default. If existing firewall chains were established under iptables-legacy, the two layers cannot resolve each other’s custom chains.
  • Non-Existent Target or Chain Name: Referencing a custom user-defined chain that has not yet been declared with the -N switch, or entering a case-sensitive target name in lower case (e.g., typing -j drop instead of -j DROP).
  • Typo in Match Extensions: Invoking a match parameter like -m multiport or -m state without specifying the accompanying criteria properly.

Step 1: Verify Chain and Target Capitalisation

Standard Netfilter targets and built-in chains are strictly case-sensitive in Linux.

  1. Ensure built-in chains are entered in uppercase: INPUT, OUTPUT, FORWARD, PREROUTING, POSTROUTING.
  2. Ensure target actions are entered in uppercase: -j ACCEPT, -j DROP, -j REJECT, -j MASQUERADE, -j RETURN.
  3. List all currently existing chains in the target table to ensure your target chain actually exists:
    sudo iptables -L -v -n
    (For the NAT table, use: sudo iptables -t nat -L -v -n)
  4. If targeting a custom chain, create it first using the -N flag:
    sudo iptables -N MY_CUSTOM_CHAIN

Step 2: Manually Probe Required Netfilter Kernel Modules

If the error occurs specifically when adding NAT or connection tracking rules, the necessary kernel driver module is not loaded.

  1. Load the basic iptables filter and NAT modules into the kernel:
    sudo modprobe ip_tables
    sudo modprobe iptable_filter
    sudo modprobe iptable_nat
    sudo modprobe xt_nat
    sudo modprobe xt_MASQUERADE
    sudo modprobe xt_conntrack
  2. Confirm the modules are active:
    lsmod | grep -E "xt_|iptable"
  3. Re-run your original iptables command.

Step 3: Switch Between iptables-nft and iptables-legacy

If your Linux distribution transitioned to the nftables backend while legacy firewall scripts or Docker rules rely on classic Netfilter structures, aligning the alternative wrapper eliminates chain translation mismatches.

  1. On Debian or Ubuntu, inspect your current iptables alternatives configuration:
    sudo update-alternatives --display iptables
  2. Switch the system default to iptables-legacy:
    sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
    sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
  3. Alternatively, if you are migrating fully to modern nftables, set both to iptables-nft:
    sudo update-alternatives --set iptables /usr/sbin/iptables-nft
    sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-nft
  4. Flush and reload your firewall rules to apply the clean backend.

Step 4: Resolving Container and WSL2 Kernel Limitations

If you encounter this error inside Windows Subsystem for Linux (WSL2) or an unprivileged Docker container, the container runtime environment lacks raw socket privileges or the custom kernel lacks Netfilter configuration.

  1. For Docker containers, ensure the container is launched with the necessary network capabilities:
    docker run --cap-add=NET_ADMIN ...
  2. For WSL2 on Windows 11, update the WSL Linux kernel to the latest version by running wsl --update in Windows PowerShell as administrator. Modern WSL2 kernels bundle full Netfilter and iptables module support.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.