简体   繁体   English

iptables v1.4.14:无法初始化 iptables 表 `nat':表不存在(你需要 insmod 吗?)

[英]iptables v1.4.14: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)

I'm trying to set iptable rules, and I got following error message when I use iptable :我正在尝试设置 iptable 规则,但在使用 iptable 时收到以下错误消息:

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

I'm using :我正在使用 :

cat /etc/debian_version 
7.4

uname -a
Linux myserver 2.6.32-22-pve #1 SMP Mon Jul 15 08:36:46 CEST 2013 x86_64 GNU/Linux

uname -r
2.6.32-22-pve

This is a virtual server hosted by a service provider.这是由服务提供商托管的虚拟服务器。

What can I do to solve this ?我能做些什么来解决这个问题?

I had the same problem with Debian 8. I fixed it by restarting the system.我在 Debian 8 上遇到了同样的问题。我通过重新启动系统来修复它。 It seems that the error can occur if the kernel image was updated and the system was not restarted thereafter.如果更新内核映像并且此后没有重新启动系统,似乎会发生错误。

I had the same problem and this worked:我有同样的问题,这有效:

sudo modprobe ip_tables
sudo echo 'ip_tables' >> /etc/modules

http://www.howtoforge.com/forums/showthread.php?t=3196 http://www.howtoforge.com/forums/showthread.php?t=3196

It maybe useful to add that if you're seeing this error message and you're not using some kind of restricted container based hosting (eg OpenVZ) then the problem maybe that the kernel is missing the nat modules.补充一点可能有用,如果您看到此错误消息并且您没有使用某种基于容器的受限托管(例如 OpenVZ),那么问题可能是内核缺少 nat 模块。 To check run:要检查运行:

modinfo iptable_nat

Which should print out the location of the module, if it prints an ERROR then you know that is your problem.哪个应该打印出模块的位置,如果它打印出一个错误,那么你就知道这是你的问题。 There are also dependent modules like nf_nat which might be missing so you'll have to dig deeper if the iptable_nat module is there but fails.还有像 nf_nat 这样的依赖模块可能会丢失,所以如果 iptable_nat 模块在那里但失败了,你必须深入挖掘。 If it is missing you'll need to get another kernel and modules, or if you're rolling your own ensure that the kernel config contains CONFIG_IP_NF_NAT=m (for IPv4 NAT).如果它丢失,您将需要获得另一个内核和模块,或者如果您自己滚动,请确保内核配置包含CONFIG_IP_NF_NAT=m (用于 IPv4 NAT)。

For info the relevant kernel module is usually found in one of these locations:有关信息,相关内核模块通常位于以下位置之一:

ls /lib/modules/`uname -r`/kernel/net/netfilter/
ls /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/

And if you're running IPv6 also look here:如果您正在运行 IPv6,请查看此处:

ls /lib/modules/`uname -r`/kernel/net/ipv6/netfilter/

Finaly, my service provider answered :最后,我的服务提供商回答:

This is a limitation of the virtualization system we use (OpenVZ), basic iptables rules are possible but not those who use the nat table.这是我们使用的虚拟化系统(OpenVZ)的一个限制,基本的 iptables 规则是可能的,但那些使用 nat 表的规则是可能的。

If this really is a problem, we can offer you to migrate to a other system virtualization (KVM) as we begin to offer our customers.如果这确实是个问题,我们可以在我们开始为客户提供服务时为您提供迁移到其他系统虚拟化 (KVM) 的服务。

SO I had to migrate my server to the new system...所以我不得不将我的服务器迁移到新系统......

Short version :精简版 :

run iptables on the host before to run it in the virtual server (I'm pretty sure this is some sort of LXC or OpenVZ container here).在主机上运行 iptables 之前在虚拟服务器中运行它(我很确定这是某种 LXC 或 OpenVZ 容器)。

Long version :长版:

The problem is due to the fact that the ip_table module is loaded on demand.问题是由于 ip_table 模块是按需加载的。 So, after a reboot, on any machine that does not have any iptables rules loaded at boot time, the ip_tables module is not loaded (no demand for the modules == the module is not loaded).因此,在重新启动后,在启动时没有加载任何 iptables 规则的任何机器上,不会加载 ip_tables 模块(对模块没有需求 == 未加载模块)。 Consequently, the LXC or OpenVZ containers cannot use iptables (since they share the host kernel but cannot modify which modules are loaded) until the host has somehow loaded the ip_tables module.因此,LXC 或 OpenVZ 容器不能使用 iptables(因为它们共享主机内核但不能修改加载的模块),直到主机以某种方式加载了 ip_tables 模块。

The table names are case-sensitive so you should use lower-case nat instead of upper-case NAT.表名区分大小写,因此您应该使用小写的 nat 而不是大写的 NAT。 For example;例如;

iptables -t nat -A POSTROUTING -s 192.168.1.1/24 -o eth0 -j MASQUERADE

iptalbes tool relies on a kernel module interacting with netfilter to control network traffic. iptalbes 工具依赖于与 netfilter 交互的内核模块来控制网络流量。

This error happens while iptalbes cannot found that module in kernel, so iptables suggest you to upgrade it :)当 iptalbes 在内核中找不到该模块时会发生此错误,因此 iptables 建议您升级它:)

Perhaps iptables or your kernel needs to be upgraded.

However in most cases it's just the module not added to kernel or being banned, try this command to check whether be banned:但是大多数情况下只是模块没有加入内核或被禁止,试试这个命令来检查是否被禁止:

cd /etc/modprobe.d/ && grep -nr iptable_nat

if the command shows any rule matched, such as blacklist iptable_nat or install iptable_nat /bin/true , delete it.如果该命令显示任何匹配的规则,例如blacklist iptable_natinstall iptable_nat /bin/true ,则将其删除。 Since iptalbes will cost some performance, it's not strange to ban it while not necessary.由于 iptalbes 会消耗一些性能,因此在没有必要的情况下禁用它并不奇怪。

If nothing found in blacklist, try add iptable-nat to the kernal manual:如果在黑名单中没有找到,请尝试将 iptable-nat 添加到内核手册中:

modprobe iptable-nat

If all of above not works, you can consider really upgrade your kernal...如果以上都不起作用,你可以考虑真正升级你的内核......

"IP conntrack functionality has some negative impact on venet performance (uo to about 10%), so they better be disabled by default." “IP conntrack 功能对 venet 性能有一些负面影响(大约 10%),因此默认情况下最好禁用它们。” It's need for nat它需要 nat

https://serverfault.com/questions/593263/iptables-nat-does-not-exist https://serverfault.com/questions/593263/iptables-nat-does-not-exist

That solution from the official wiki:来自官方维基的解决方案:

vzctl set $CTID --netfilter full --save

https://openvz.org/VPN_via_the_TUN/TAP_device#Troubleshooting https://openvz.org/VPN_via_the_TUN/TAP_device#Troubleshooting

On OpenSUSE 15.3 systemd log reported this error (insmod suggestion was unhelpful).在 OpenSUSE 15.3 systemd 日志上报告了这个错误(insmod 的建议没有帮助)。

Feb 18 08:36:38 vagrant-openSUSE-Leap dockerd[20635]: iptables v1.6.2: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)

REBOOT fixed the problem重新启动解决了问题

If you are running puppet it may set /proc/sys/kernel/modules_disabled to 1, inhibiting further module loading.如果您正在运行puppet,它可能会将/proc/sys/kernel/modules_disabled为 1,从而阻止进一步的模块加载。 When the machine is reboot, it gets set back to 0, allowing for changes, such as loading the iptables modules.当机器重新启动时,它会重新设置为 0,允许进行更改,例如加载 iptables 模块。 After a certain amount of time puppet will set it back to 1 to protect the system from kernel root kits.在一定时间后, puppet会将其设置回 1 以保护系统免受内核根工具包的攻击。 Therefore, whatever modules that we are going to need should be loaded during or shortly after boot time .因此,我们需要的任何模块都应该在启动时或启动后不久加载

请确保您在编译 Linux 内核时设置了 IP_NF_NAT [=y]。

check if tun/tap enabled:检查 tun/tap 是否启用:

cat /dev/net/tun

if ok will see something :如果确定会看到一些东西:

cat: /dev/net/tun: File descriptor in bad state
uname -av;
sudo apt install --reinstall (output from uname -av)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM