7

I'm trying to do some NAT on my Raspi 2 running Raspbian. But when I try to do anything with the nat table in iptables, I get the following error:

iptables v1.4.21: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

And when I try modprobe:

pi@raspberrypi:~ $ sudo modprobe iptables
modprobe: ERROR: ../libkmod/libkmod.c:557 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.11-v7+/modules.dep.bin'

Version info:

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l GNU/Linux
9

Quick guess: You've upgraded the OS and the system has been up for a very long time, or managed to upgrade it without replacing the kernel, because the 4.4.11-v7+ modules have already been removed from Raspbian.

If there is no such directory as /lib/modules/4.4.11-v7+ (look) you should run sudo apt update then sudo apt upgrade to ensure your kernel has been replaced, then reboot and check uname -r; it should give a version with a corresponding /lib/modules/ directory that does exist. The pi kernel can boot without any, however, so to check, try lsmod; if there's nothing, something is wrong. If there is, you can filter that lsmod | grep -P "ip|nf" to see the ones that are related to iptables/netfilter (and anything else that coincidentally contains those letter combinations).

The base module is actually ip_tables, but it should be loaded automatically. The base module for NAT is nf_nat but that should be loaded automatically as well.

  • 1
    Your guess is amazingly accurate! I have done a dist-upgrade recently, whi h updated the kernel, without a reboot. I tried to reboot and everything works well now! – Cnly Jul 15 '16 at 16:09
  • They should really have a mechanism to not leave people in the lurch this way, e.g., by quickly checking the running kernel version before deleting its modules! The issue on the pi is by default it loads a kernel ambiguously named kernel.img (or kernel7.img) unless you add a line to config.txt. When they update the kernel, they do it by deleting/overwriting the old one (changing config.txt instead might create a hassle for some people, but in general would probably be a cleaner approach). – goldilocks Jul 15 '16 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.