IPTABLES-SAVE手册页&IPTABLES-RESTORE手册页

总览
iptables-save [-c] [-t table]

说明
通过简单的语法格式把一个IP TABLE的内容转储到STDOUT(标准输出).可以
用由shell提供I/0重定向写到一个文件中

-c, --counters
输出中包括所有包和字节计数器的当前值

-t, --table tablename
仅输出指定表名的那个表,若没有指定,将输出所有可用的表

总览
iptables-restore [-c] [-n]

说明
iptables-restore的作用是通过STDIN(标准输入)上指定的数据来恢复IP Table。
由你的shell提供的I/O重定向功能从一个文件中读取。

-c, --counters
恢复所有包和字节计数器的当前值

-n, --noflush
不删除表中以前的内容,如果没有指定(这一参数),iptables-restore会清空(删除)所有
以前表中的内容。

[@more@] 呵呵,ubuntu上使用iptables稍稍有些麻烦。

/usr/share/doc/iptables/examples/3iptables-ppp_down-rules
/usr/share/doc/iptables/examples/oldinitdscript.gz
/usr/share/doc/iptables/examples/3iptables-ppp_up-rules.gz

可以从上面的地址找到例子。其中oldinitdscript 是对应于希望使用
iptables start/stop/restart
准备的,不过不推荐使用。

如果希望自己控制,可以使用 3iptables-ppp_up-rules 。加到
/etc/ppp/ip-up的最后,不过我使用发现有些问题就是
3iptables-ppp_down-rules 没有办法清楚nat的配置,索性我不要了,
将3iptables-ppp_down-rules 修改的面目全非。呵呵。

如下:
代码:
#!/bin/sh
#
# 3iptables-ppp_up-rules, v0.6 03/09/2003.
# Kiryanov Vasiliy, mailto://root@lycos.ru
#
# Thanks: Uwe Zeisberger - rfc1918 violating fix;
#
# Many people use ppp to connect to the InterNet, this script set BASIC
# firewall (iptables) rules to protect you machine from crackers.
# For good protect read iptables(8) manual and tune this script!

# FOR USAGE:
# put 3iptables-ppp_up-rules script in /etc/ppp/ip-up.d
# put 3iptables-ppp_down-rules script in /etc/ppp/ip-down.d
# check: scripts owned by root.root and have mode 700.

# If you find some errors or missing write me: root@lycos.ru
#--------------------------------------------------------------

# check if iptables exist and have kernel support
test -x /sbin/iptables || exit 1
/sbin/iptables --list --numeric >/dev/null 2>&1
test $? -eq 0 || exit 1

# When started pppd it call ip-up, which set variables and uses run-parts
# to run scripts in /etc/ppp/ip-up.d, one of which is that.

# ip-up set this variables, so we don't need to do it:
# Var Name Example

INET_IFACE="ppp0"
VPN_IFACE="ppp+"

LAN_IP="192.168.3.1"
LAN_IP_RANGE="192.168.3.0/24"
LAN_IFACE="eth0"

LO_IFACE="lo"
LO_IP="127.0.0.1"

IPTABLES="/sbin/iptables"

echo "1" > /proc/sys/net/ipv4/ip_forward

modprobe ip_tables
modprobe ip_nat_ftp
modprobe ip_conntrack
modprobe ip_conntrack_ftp


# PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

#Save iptables exist rulesets, we restore them after PPP interface down!

# disable `root group` and `other users` access
umask 066
# protect against symbolic link attack
test ! -e /tmp/3iptables-ppp_up-SAVE || rm -f /tmp/3iptables-ppp_up-SAVE
# save exist ruleset
/sbin/iptables-save > /tmp/3iptables-ppp_up-SAVE


$IPTABLES -F -t filter
$IPTABLES -F -t nat

$IPTABLES -A INPUT -p TCP -s 0/0 --dport 21 -j ACCEPT
$IPTABLES -A INPUT -p TCP -s 0/0 --dport 22 -j ACCEPT
$IPTABLES -A INPUT -p TCP -s 0/0 --dport 80 -j ACCEPT
$IPTABLES -A INPUT -p TCP -s 0/0 --dport 113 -j ACCEPT

#VPN ACCEPT
$IPTABLES -A INPUT -p TCP -s 0/0 --dport 1723 -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $VPN_IFACE -j ACCEPT
$IPTABLES -A INPUT -p GRE -j ACCEPT
$IPTABLES -A INPUT -p UDP --dport 5000 -j ACCEPT
$IPTABLES -A INPUT -i tun+ -j ACCEPT
$IPTABLES -A FORWARD -i tun+ -j ACCEPT
$IPTABLES -A INPUT -i tap+ -j ACCEPT
$IPTABLES -A FORWARD -i tap+ -j ACCEPT

$IPTABLES -A INPUT -p UDP -s 0/0 --dport 53 -j ACCEPT
$IPTABLES -A INPUT -p UDP -s 0/0 --dport 2074 -j ACCEPT
$IPTABLES -A INPUT -p UDP -s 0/0 --dport 4000 -j ACCEPT

$IPTABLES -A INPUT -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
$IPTABLES -A INPUT -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT

$IPTABLES -A INPUT -p ALL -i $LAN_IFACE -j ACCEPT
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -j DROP

$IPTABLES -A FORWARD -i $INET_IFACE -j ACCEPT
$IPTABLES -A FORWARD -i $LAN_IFACE -j ACCEPT
$IPTABLES -A FORWARD -i $VPN_IFACE -j ACCEPT
$IPTABLES -A FORWARD -j DROP

$IPTABLES -A OUTPUT -p ALL -j ACCEPT

$IPTABLES -t nat -A POSTROUTING -s 192.168.3.0/24 -j MASQUERADE

$IPTABLES -t nat -A PREROUTING -i eth0 -p tcp -s 192.168.3.0/24
-d ! 192.168.3.1/24 --dport 80 -j REDIRECT --to-ports 3128

#
# try '# ifconfig' to see if your ppp interface all right
# try '# iptables --list --verbose' to see if all rules right


不过我还是推荐使用 shorewall ,配置也不复杂,主要是安全性比较高。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/786540/viewspace-1002072/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/786540/viewspace-1002072/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值