Chinaunix首页 | 论坛 | 博客
  • 博客访问: 207944
  • 博文数量: 53
  • 博客积分: 2059
  • 博客等级: 大尉
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-30 03:03
文章分类
文章存档

2012年(4)

2011年(19)

2010年(30)

分类: 网络与安全

2010-07-02 04:48:34

Red Hat(Centos)默认安装完成后,会有一个默认的防火墙规则,下面做一下简单的说明
运行命令查看默认规则:iptables -t filter -L   iptables -t nat -L iptables -t mangle -L iptables -t raw -L 结果输出:
[root@test6 ~]# iptables -t filter -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain RH-Firewall-1-INPUT (2 references)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     esp  --  anywhere             anywhere            
ACCEPT     ah   --  anywhere             anywhere            
ACCEPT     udp  --  anywhere             224.0.0.251         udp dpt:mdns
ACCEPT     udp  --  anywhere             anywhere            udp dpt:ipp
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ipp
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-proto-unreachable
[root@test6 ~]# iptables -t mangle -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
[root@test6 ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@test6 ~]# iptables -t raw -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
从结果中可以看出,只有filter chain 中存在默认的规则,其他chain中没有,在此我们解读一下,这些默认的规则:
默认的规则的配置文件在/etc/sysconfig/iptables文件中
[root@test6 ~]# cat /etc/sysconfig/iptables
 1 # Generated by iptables-save v1.3.5 on Thu Jun 24 23:27:52 2010
      2 *filter
      3 :INPUT ACCEPT [0:0]
      4 :FORWARD ACCEPT [0:0]
      5 :OUTPUT ACCEPT [1201:112169]
      6 :RH-Firewall-1-INPUT - [0:0]
      7 -A INPUT -j RH-Firewall-1-INPUT
      8 -A FORWARD -j RH-Firewall-1-INPUT
      9 -A RH-Firewall-1-INPUT -i lo -j ACCEPT
     10 -A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
     11 -A RH-Firewall-1-INPUT -p esp -j ACCEPT
     12 -A RH-Firewall-1-INPUT -p ah -j ACCEPT
     13 -A RH-Firewall-1-INPUT -d 224.0.0.251 -p udp -m udp --dport 5353 -j ACCEPT
     14 -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
     15 -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
     16 -A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
     17 -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
     18 -A RH-Firewall-1-INPUT -j REJECT --reject-with  icmp-proto-unreachable
     19 COMMIT
     20 # Completed on Thu Jun 24 23:27:52 2010
我们根据配置文件来说明一下相关的规则
首先第一行说明:防火墙最后一次更改后的保存时间
2,默认table
3-5定义INPUT,FORWARD,OUTPUT chain的默认规则ACCEPT 等价  iptables -t filter -P INPUT ACCEPT,iptables -t filter -P FORWARD ACCEPT,iptables -t filter -P OUTPUT

ACCEPT 这三句规则
6 定义新的chain 该定义chain 应该是写在另外已配置文件中,=  iptables -n RH-Firewall-1-INPUT
7-9 7-8是关联相关链,就是把默认的进入INPUT FORWARD chain中的数据包,都发送到定义的新chain中RH-Firewall-1-INPUT
9 设置回环地址关联链
10 以下的规则都是增加到 RH-Firewall-1-INPUT该链中的,增加规则,接受任何类型的ping包
11-12 规则,接受协议为ah 和esp的数据包 iptables 匹配的协议可以在 /etc/protocol中查询
cat /etc/protocols |grep ah
ah      51      AH              # Authentication Header
[root@test6 ~]# cat /etc/protocols |grep esp
esp     50      ESP             # Encap Security Payload
这两个协议为IP sec中的加密通信协议AH(Authentication Header) ESP(Encap Security Payload);
13 表示目的地址是224.0.0.251,目的端口是mdns的UDP数据包允许通过。 224.0.0.251是一种组播地址,mdns是端口号的一种名称。如果执行iptables命令时加了-n选项,则会显

示数字5353,它是组播地址的DNS端口
14-15 规则是用来接受udp tcp网络打印服务的数据包
可以用以下命令得知:
[root@test6 ~]# lsof -i:631
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
cupsd   1448 root    3u  IPv4   4487       TCP localhost.localdomain:ipp (LISTEN)
cupsd   1448 root    5u  IPv4   4490       UDP *:ipp
其中IPP指的是Internet Printing Protocol
16 规则 是 防火墙接受封包状态为RELATED,ESTABLISHED的数据包
17 规则是指,接受ssh客户端的链接
18 规则是 防火墙拒绝说有的数据包,且返回来源地址一个ICMP错误包,其中reject-with 是用来定义返回的ICMP错误包的类型
Valid reject types:
    icmp-net-unreachable        ICMP network unreachable
    net-unreach                 alias
    icmp-host-unreachable       ICMP host unreachable
    host-unreach                alias
    icmp-proto-unreachable      ICMP protocol unreachable
    proto-unreach               alias
    icmp-port-unreachable       ICMP port unreachable (default)
    port-unreach                alias
    icmp-net-prohibited         ICMP network prohibited
    net-prohib                  alias
    icmp-host-prohibited        ICMP host prohibited
    host-prohib                 alias
    tcp-reset                   TCP RST packet
    tcp-rst                     alias
    icmp-admin-prohibited       ICMP administratively prohibited (*)
    admin-prohib                alias
也可以查看RFC-792文档,可以较为详尽的知道哪些ICMP错误返回类型。


阅读(1813) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~