2.应用Iptables规则 示例

允许WWW

iptables –A INPUT –p tcp –dport 80 –j ACCEPT

该规则被添加到filter表的INPUT链,允许目的端口是80的数据包。

在内部接口上允许DHCP

iptables –A INPUT –i eth0 –p tcp - - sport 68 - -dport 67 ACCEPT

iptables –A INPUT –i eth0 –p ucp - -sport 68 - -dport 67 ACCEPT

以上同时允许TCP和UDP协议。

3.保存和恢复Iptables

保存Iptables

使用iptables-save可将现行的iptables规则保存,

iptables-save > iptables保存路径,如# iptables-save > /etc/iptables.up.rule

恢复Iptables

使用iptables-restore 可从配置文档恢复iptables表到现行iptables表.

iptables-restore < /etc/iptables.up.rule

二、Ubuntu Server中的Iptables

Ubuntu Server6.06中已经默认安装iptables,版本是1.3.3.默认状态是关闭。

通过修改/etc/network/interfaces可将iptables打开:

auto lo

Iface lo inet loopback

auto eth0

iface eth0 inet dhcp

#添加以下内容

pre-up iptables-restore < /etc/iptables.up.rule

#call the restored rule when active the eth0

post-down iptables-save > /etc/iptables.up.rule

#restore the iptables rule when shutdown the interface eth0

然后重新激活eth0即可。

另外,可随时修改/etc/iptables.up.rule配置文件,来更改iptables的规则。Iptables.up.rule格式如下:

#Generated by iptables-save V1.3.3 on Tue Jul 31 14:18:44 2007

*filter

:INPUT ACCEPT [73:8213]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [8:825]

-A INPUT –i lo –p icmp –j DROP

-A INPUT –i eth0 –p icmp –j DROP

COMMIT

#Completed on Tue Jul 31 14:10:44 2007

行与行之间不能有空行。

三.Summary

iptables表链中每条规则的顺序很重要,如果首条是accept all,那末所有的数据包都会被允许通过firewall,因此应当适当的安排规则顺序。

通常的法则是:拒绝所有 允许少数.

通过阅读文章,我们清楚的知道Linux系统Iptables防火墙,希望本文对你们有帮助!

  • Ubuntu 10.10 设置iptables做NAT
  • iptables与natcheck
  • iptables限制访问某个IP地址
  • 用iptables限制黑客破解密码
  • iptables 菜鸟变大虾
  • iptables 端口转发
  • iptables nat 技术笔记


相关内容