iptables的NAT功能设置和linux升级内核后遇到 can't initialize iptables table `nat': Table does not exist 问题
来源:互联网 发布:如何理解算法分析 编辑:程序博客网 时间:2024/06/06 03:53
方法:
提示: 以下方法只适用于红帽企业版Linux 3 以上。
1、打开包转发功能:
echo "1" > /proc/sys/net/ipv4/ip_forward
2、修改/etc/sysctl.conf文件,让包转发功能在系统启动时自动生效:
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
3、打开iptables的NAT功能:
/sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
说明:上面的语句中ppp0是连接外网或者连接Internet的网卡. 执行下面的命令,保存iptables的规则: service iptables save
4、查看路由表:
netstat -rn 或 route -n
5、查看iptables规则:
iptables -L
查看nat表
iptables -t nat -L
编译好新内核后
# iptables -t nat -nL 提示
iptables v1.3.5: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
解决方法: 编译内核时加入以下模块
Linux Kernel Configuration
-> Networking support
-> Networking options
-> Network packet filtering framework(netfilter)
-> Core netfilter configuration
-> Netfilter connection tracking support
-> Netbios name service protocal support(new)
-> Netfilter Xtables support (required for ip_tables)
Linux Kernel Configuration
-> Networking support
-> Networking options
-> Network packet filtering framework(netfilter)
-> IP: Netfilter Configuration
-> IPv4 connection tracking support (require for NAT)
-> IP tables support (required for filtering/masq/NAT)
-> Full NAT
-> MASQUERADE target support
-> REDIRECT target support
make -j2
make -j2 all
make -j2 modules_install
make -j2 install
升级完成后重启重新配置nat即可。
can't initialize iptables table `nat': Table does
etworking --->
Networking options --->
Network packet filtering framework (Netfilter) --->
Core Netfilter Configuration --->
Now just set the modules you need for your netfilter box. That's it, I hope now it works to you.
如果执行 iptable -L 出现以下信息,那么就需要重新配置和编译内核:
iptables v1.4.2: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
配置选项:
Networking —->
Networking options —->
[*] Network packet filtering (replaces ipchains) —>
Core Netfilter Configuration —>
<*> Netfilter Xtables support (required for ip_tables)
IP: Netfilter Configuration —>
<*> Connection tracking (required for masq/NAT)
<*> IP tables support (required for filtering/masq/NAT)
<*> IP range match support
<*> Packet filtering
<*> REJECT target support
<*> Full NAT
ip_forward
除此之外,需要在主机上打开 ip 转发以保持连接通道。
查看是否已打开 ip 转发(1 表示打开):
cat /proc/sys/net/ipv4/ip_forward
如果未打开,则用以下命令打开:
echo 1 > /proc/sys/net/ipv4/ip_forward
保存设置
以上 iptables 设置和 ip 转发设置在重启系统之后就会消失,因此如果有需要,请将设置保存。
保存 iptables 设置:
/etc/init.d/iptables save
设置系统启动时自动加载 iptables 设置(以 gentoo 为例):
rc-update add iptables default
保存 ip_forward 设置(在 /etc/sysctl.conf 中设置):
net.ipv4.ip_forward = 1
安全隐患
在打开了 ip_forward 后,一般要同时打开 rp_filter (Reverse Path filter),对数据包的源地址进行检查。
如果在没有打开这个设置,就很容易受到来自内部网的 IP 欺骗。
打开 rp_filter:
for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done
保存设置(在 /etc/sysctl.conf 中设置):
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
如果执行 iptable -L 出现以下信息,那么就需要重新配置和编译内核:
iptables v1.4.2: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
配置选项:
Networking —->
Networking options —->
[*] Network packet filtering (replaces ipchains) —>
Core Netfilter Configuration —>
<*> Netfilter Xtables support (required for ip_tables)
IP: Netfilter Configuration —>
<*> Connection tracking (required for masq/NAT)
<*> IP tables support (required for filtering/masq/NAT)
<*> IP range match support
<*> Packet filtering
<*> REJECT target support
<*> Full NAT
以上配置只为端口映射准备,如果需要其它功能,请根据需要增加相关的配置。
编译安装内核步骤略过。
iptabes
iptables 规则如下:
iptables -t nat -A PREROUTING -p tcp –dport 11101 -d 192.168.1.100 -j DNAT –to-destination 192.168.2.101:22
- iptables的NAT功能设置和linux升级内核后遇到 can't initialize iptables table `nat': Table does not exist 问题
- ptables的NAT功能设置和linux升级内核后遇到 can't initialize iptables table `nat': Table does not exist 问题
- can't initialize iptables table `nat': Table does
- Android内核编译(支持netfilter/iptalbes)(can't initialize iptables table `filter': iptables who)
- linux-iptables设置NAT
- iptables的NAT设置
- 容器中使用iptables报错can't initialize iptables table Permission denied (you must be root)
- Linux下iptables的NAT功能实现路由器
- Linux下iptables的NAT功能实现路由器
- linux-iptables nat设置路由转换
- iptables的NAT配置
- iptables的nat的简单设置
- VSFTPD与iptables NAT的设置详解
- iptables NAT
- Iptables+NAT
- iptables---NAT
- iptables NAT
- IPTABLES NAT
- Tomcat性能调优
- Xamarin iOS开发中的编辑、连接、运行
- HDU 1978 How many ways
- SqlServer查询计划
- iOS学习之Table View的简单使用
- iptables的NAT功能设置和linux升级内核后遇到 can't initialize iptables table `nat': Table does not exist 问题
- Windows7下安装MongoDB
- 浅谈泛型(二)
- Android 判断桌面是否快捷方式,不存在则创建
- cocos2dx-3.4环境搭建及apk发布调试之谜海归巢
- Git在线教学网站
- IOS crash之NSInvalidArgumentException
- vCloud Suite Deployment Configurations---vCloud 部署配置
- Android系统回顾(六):菜单