一、防火墙概念。
二、防火墙种类。
    1、软件防火墙    天网、瑞星、windows自带防火墙、iptables
    2、硬件防火墙    pix、netscreen、防毒墙
[root@localhost root]# service iptables start  
                  service:     服务    
                  iptables:    Linux下软防火墙名称称iptables
                  start:       启动、开启。
 
[root@localhost root]# ntsysv    让Linux在开机时自动启用防火墙。
[root@localhost root]# iptables -A INPUT -p icmp -j DROP    拒绝客户端的ping命令。
[root@localhost root]# iptables -L -n      查看防火墙规则。
[root@localhost root]# iptables --help|less   查看iptables帮助。
iptables v1.2.7a   显示的是防火墙版本。
 
Usage: iptables -[AD] chain rule-specification [options]
 用法  iptables -[RI] chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LFZ] [chain] [options]
       iptables -[NX] chain
       iptables -E old-chain-name new-chain-name
       iptables -P chain target [options]
       iptables -h (print this help information)
 
Commands:
Either long or short options are allowed.
  --append  -A chain            Append to chain    追加一个链,追加一个条件到链里面。chain是链默认的名称:INPUT(进入)、OUTPUT(输出)、forward(转                               发)。
  --delete  -D chain            Delete matching rule from chain    删除
  --delete  -D chain rulenum
                                Delete rule rulenum (1 = first) from chain  删除以rulenum为规则号的链。
  --insert  -I chain [rulenum]                  
                                Insert in chain as rulenum (default 1=first)  插入
  --replace -R chain rulenum
                                Replace rule rulenum (1 = first) in chain     替换
  --list    -L [chain]          List the rules in a chain or all chains       显示链的名称
  --flush   -F [chain]          Delete all rules in  chain or all chains      清空所有的链或指定的链。
  --zero    -Z [chain]          Zero counters in chain or all chains      清除计数器,归零。
  --new     -N chain            Create a new user-defined chain     新建一个用户自定义的链,默认的链只有三个input output forward。
  --delete-chain
            -X [chain]          Delete a user-defined chain         删除用户自定义的链
  --policy  -P chain target
                                Change policy on chain to target   大写P,修改链的默认的策略(链的状态、开启或关闭)
  --rename-chain
            -E old-chain new-chain
                                Change chain name, (moving any references) 
Options:
  --proto       -p [!] proto    protocol: by number or name, eg. `tcp'   小写p,指定一个协议类型tcp、udp、icmp,也可用!排除。
  --source      -s [!] address[/mask]
                                source specification       指定数据包的源地址
  --destination -d [!] address[/mask]
                                destination specification  数据包的目的地地址
  --in-interface -i [!] input name[+]
                                network interface name ([+] for wildcard)   指定进入的接口(可以是网卡)
  --jump        -j target
                                target for rule (may load target extension)   跳转到哪个目标 DROP(丢包)、ACCEPT(接受)、REJECT(拒绝)
  --match       -m match
                                extended match (may load extension)       匹配扩展条件,可以用man命令查看帮助。
  --numeric     -n              numeric output of addresses and ports     以数字形式输出结果。
  --out-interface -o [!] output name[+]
                                network interface name ([+] for wildcard)   匹配一个包出去时候的接口,可以是网卡地址或区域设备地址。
  --table       -t table        table to manipulate (default: `filter')    默认操作的表。
  --verbose     -v              verbose mode                     
  --line-numbers                print line numbers when listing          显示结果前面加上编号。
  --exact       -x              expand numbers (display exact values)
[!] --fragment  -f              match second or further fragments only
  --modprobe=          try to insert modules using this command
  --set-counters PKTS BYTES     set the counter during insert/append
[!] --version   -V              print package version.
 
举例:
1、拒绝本机的FTP服务。(把所有针对于本机的21端口给屏蔽掉)
                     21: 连接端口   
                     20: 传输数据
 
[root@localhost root]# iptables -A INPUT -p tcp -d 10.255.255.88 --dport 21 -j DROP
            
   做服务器:先分析服务器是做什么的,只开有用的端口,其他端口一律关闭。
[root@localhost root]# iptables -P INPUT DROP    将默认输入的规则链策略改为 拒绝
[root@localhost root]# iptables -A INPUT -p tcp -d 10.255.255.88 --dport 22 -j ACCEPT  开启SSH的22端口,让别人能进来
[root@localhost root]# iptables -A OUTPUT -p tcp -s 10.255.255.88 --sport 22 -j ACCEPT  使服务器本身能SSH出去。
[root@localhost root]# iptables -P FORWARD DROP
[root@localhost root]# iptables -P OUTPUT DROP
 
 
[root@localhost root]# iptables -A INPUT -p tcp --dport 80 -j DROP   屏蔽80端口(服务器上)
[root@localhost root]# iptables -A OUTPUT -p tcp --sport 80 -j DROP
       -A:附加一个规则链
       INPUT:输入
       OUTPUT:输出
       -p :  protocol协议   
       --dport:  destination(目的地) port端口。  
       --sport:  source(源头)    源端口。
[root@localhost root]# service iptables save   进行防火墙规则的保存。