如何在Amazon EC2 VPC NAT Ami上保留iptablesconfiguration?

我有一个这样的小脚本来configurationiptables

#!/bin/bash PRE_STR="iptables -t nat -A PREROUTING -p tcp -j DNAT" FOR_STR="iptables -A FORWARD -p tcp -j ACCEPT" ##################################### # instances CM="10.0.1.137" MASTER="10.0.1.149" MYSQL="10.0.1.83" REPORTING="10.0.1.85" ##################################### # Clear Iptables iptables -F iptables -t nat -F ##################################### # Forward to enable Internet on private nodes iptables -t nat -A POSTROUTING -j MASQUERADE ##################################### # Port forwarding forward() { $PRE_STR --dport $1 --to $2:$3 $FOR_STR --dport $3 -d $2 } #what from to ip to port forward 3222 $CM 22 forward 7183 $CM 7183 forward 7180 $CM 7180 forward 3122 $MASTER 22 forward 8888 $MASTER 8888 forward 11000 $MASTER 11000 forward 2122 $MYSQL 22 forward 13306 $MYSQL 3306 iptables-save > /etc/firewall.conf 

问题是,如何在下一次启动时使用当前iptables设置加载/etc/firwall.conf

在一台普通的Debian机器上,我会放一个脚本,将iptables-restore < /etc/firewall.conf文件复制到/etc/network/if-up.d/iptables文件夹中。 但是在这个图像中不可用。

那么为什么要加载这个/etc/firewall.conf什么?

AMI ID:ami-1de2d969

更新:

可以在/etc/rc.local中的iptables-restore < /etc/firewall.conf中启动它吗?

资料来源: http : //www.cyberciti.biz/faq/how-do-i-save-iptables-rules-or-settings/

Debian(及其衍生产品)使用iptables-persistent软件包来执行此任务。

/etc/iptables/rules.4和/或/etc/iptables/rules.6定义您的规则,然后激活该服务(使用update-rc.dchkconfig或您select的工具。

在RHEL及衍生产品上,启动脚本/etc/init.d/iptables读取/etc/sysconfig/iptables ,因此您需要在那里定义您的规则,并确保iptables服务已激活( chkconfig iptables on )并启动service iptables start )。

 service iptables save 

要么

 /etc/init.d/iptables save