iptables防火墙
 
内外网IP使用安全策略及防火墙故障问题
iptables防火墙关闭两项功能
1、selinux关闭,也会做ids***检测。类似MD5指纹检测。
2、iptables(生产中看情况,内网关闭,外网开启)
大并发情况下,不能开iptables,影响应能,硬件防火墙(也有吞吐量)。
 
安全优化:
1、尽可能不给服务器配置外网IP。可以通过代理转发
2、并发不是特别大情况再外网ip的环境,开启防火墙。
 
iptables防火墙介绍及名词术语讲解-表和链知识
基于包过滤的。对数据包的流出流进精细控制
iptables利用一台普通PC机做路由器,性能能比5W路由器
 
iptables主要工作在OSI七层的二、三、四层,
iptables也可以工作在七层上(最好用squid控制+iptables)
 
iptables名词和术语
容器:包含或者被包含关系
Netfilter/iptables是表的容器,iptables包含的各个表:-t指定表
表:(tables):/nat/mangle/raw(raw很少用)表,最常用两个表filter,nat表
 默认防火墙。NAT 代理上网转发 mangle
 
iptables的表又是链的容器
链:(chains):INPUT,OUTPUT,FORWARD,PREROUTING,POSTROUTING(出去路由)
 
链是规则的容器
规则(Policy):一条条过滤的语句。
 
iptables防火墙filter表及对应链知识详解
提示:所有的链名都要大写     iptabales -L -n 查看表        -t 指定表
filter表是真正负责主机防火墙功能的(过滤流入流出功能),filter是iptables默认使用的表。这个表定义了三个链Chain:(企业场景:主机防火墙)
 
INPUT:过滤所有进入主机的数据包       (主要控制进)
FORWARD:负责转发流经主机数据包的。   LVS NAT模式。 net.ipv4.ip_forward=0
OUTPUT:就是处理出去所有主机的数据包
强调:对于filter表的控制是我们实现防火墙的\
NAT:  功能:交换机 acl    网络地址转换 ,局域网共享上网,端口以及IP的映射。
 
filter      #过滤器input      #输入(流入)forward        #前进(流经)output        #输出(流出) 
小结:
1、防火墙是层层过滤的。实际上是按照配置文件的书序从上到下,从前到后进行过滤的
2、如果匹配上规则,即明确表明是阻止还是通过,数据包就不在向下匹配新规则了。
3、如果所有规则中没有明确表明是阻止还是通过,也就是没有匹配规则,向下进行屁屁额指导匹配默认规则得到明确的阻止还是通过。
4、防火墙默认规则是对应链的所有规则执行完才会执行。
 
提示:
         重点:匹配了拒绝规则也是匹配,
iptables内部表和链的核心原理讲解
 iptables命令及参数实战演练1
[root@test ~]# iptables -V
iptables v1.4.7
[root@test ~]# iptables -h
iptables v1.4.7
 
Usage: iptables -[AD] chain rule-specification [options]
       iptables -I chain [rulenum] rule-specification [options]
       iptables -R chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LS] [chain [rulenum]] [options]
       iptables -[FZ] [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
  --delete  -D chain            Delete matching rule from chain
  --delete  -D chain rulenum
                                Delete rule rulenum (1 = first) from chain
  --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 [rulenum]]
                                List the rules in a chain or all chains
  --list-rules -S [chain [rulenum]]
                                Print the rules in a chain or all chains
  --flush   -F [chain]          Delete all rules in  chain or all chains
  --zero    -Z [chain [rulenum]]
                                Zero counters in chain or all chains
  --new     -N chain            Create a new user-defined chain
  --delete-chain
            -X [chain]          Delete a user-defined chain
  --policy  -P chain target
                                Change policy on chain to target
  --rename-chain
            -E old-chain new-chain
                                Change chain name, (moving any references)
Options:
[!] --proto     -p proto        protocol: by number or name, eg. `tcp'
[!] --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)
  --goto      -g chain
                              jump to chain with no return
  --match       -m match
                                extended match (may load extension)
  --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.
 
实际测试iptables规则
启动和查看iptables的状态命令
/etc/init.d/iptables start
iptables -L -n 
iptables -L -n -v -x
[root@test ~]# /etc/init.d/iptables restart
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
 
[root@test ~]# /etc/init.d/iptables start
iptables:应用防火墙规则:                                 [确定]
[root@test ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
 
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
 
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@test ~]# iptables -L -n -v -x      
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
      45     3012 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
       1       48 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
     101     8128 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
 
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
 
Chain OUTPUT (policy ACCEPT 27 packets, 3368 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
 
启动成功的状态
[root@test ~]# /etc/init.d/iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
 
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
 
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination  
启动不成功的解决办法:
虚拟机上面执行setup 配置步骤
解决办法----->     setup -->Firewall configuration -->enable
 
iptables默认加载的是内核的模块
[root@test ~]# lsmod |egrep "nat|filter"
iptable_filter          2793  1 
ip_tables              17831  1 iptable_filter
[root@test ~]# lsmod |egrep "nat|filter|ipt"
iptable_filter          2793  1 
ip_tables              17831  1 iptable_filter
ipt_REJECT              2351  2
需要加载以下模块*(否则不成功)
modprobe ip_tables
modprobe iptable_filter
 modprobe iptable_nat
 modprobe ip_conntrack
modprobe ip_conntrack_ftp
 modprobe ip_nat_ftp
 modprobe ipt_state
加载模块之后的结果显示
[root@test ~]# lsmod |egrep "nat|filter|ipt"
nf_nat_ftp              3507  0 
nf_conntrack_ftp       12913  1 nf_nat_ftp
iptable_nat             6051  0 
nf_nat                 23316  2 nf_nat_ftp,iptable_nat
nf_conntrack_ipv4       9506  5 iptable_nat,nf_nat
nf_conntrack           80390  6 nf_nat_ftp,nf_conntrack_ftp,iptable_nat,nf_nat,nf_conntrack_ipv4,xt_state
iptable_filter          2793  1 
ip_tables              17831  2 iptable_nat,iptable_filter
ipt_REJECT              2351  2
 
清除默认的规则
iptables -F    //清除所有的规则,不会处理默认的规则
iptables -X    //删除用户自定义的链
iptables -Z    //链的记录器清零
iptables -N   //创建自定义的链
 
iptables -F实操:
[root@test ~]# iptables -F 
[root@test ~]# iptables -L -n    依旧显示默认的规则         
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  
iptables -X实操:
[root@test ~]# iptables -X
[root@test ~]# iptables -L -n
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         
iptables -Z实操:
[root@test ~]# iptables -Z
[root@test ~]# iptables -L -n
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  
 
禁止规则(自杀)
22端口转换成52113端口 。
 
[root@ipt ~]# vim /etc/ssh/sshd_config
####by Frank#2015-07-10##Port 52113PermitRootLogin noPermitEmptyPasswords noUseDNS noGSSAPIAuthentication no 
 
#禁止SSH端口
(1)找出当前机器的ssh 的端口
[root@test ~]# netstat -lntup|grep ssh  (第一种方法)
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      949/sshd            
tcp        0      0 :::22                       :::*                        LISTEN      949/sshd  
(2)禁止掉当前SSH端口 这里的是默认的22端口
 
[root@test ~]# ss -lntup|grep ssh     (第二种方法)
tcp    LISTEN     0      128                   :::22                   :::*      users:(("sshd",949,4))
tcp    LISTEN     0      128                    *:22                    *:*      users:(("sshd",949,3))
 
CRT界面链接执行下面命令直接就退出连接不上==自杀行动
[root@ipt ~]# iptables -t filter -A INPUT -p tcp --dport 22 -j DROP
命令参数--见iptables详细文档(共享文件夹>96文件里面)
语法格式: iptables [-t table] -[AD] chain rule-specification [options]
解释格式:iptables -t 指定的表(有4个表) -A (增加规则 )-D(减少规则)链的规则 tcp udp acp all这几种写法 目的端口
处理方式 -j 行为
详细命令:见 iptables word 的命令解析文档
解决办法 :
①进到虚拟机 iptables -F 清除所有的规则 再此重新连接就OK
②自己有远程管理卡清理
③机房人员帮忙清理
④写个定时任务 ,定时清理配置防火墙的时候每5分钟执行一次
⑤登录虚拟终端清除
⑥iptables -t filter -D INPUT -p tcp --dport 22 -j DROP
⑦iptables -F /etc/init.d/iptabales stop 
 
(2)禁止掉当前SSH端口,这里是22
语法:
Usage: 
iptables -t [table] -[AD] chain rule-specification [options]
具体命令:
iptables           -A INPUT -p tcp --dport 52113 -j DROP
iptables -t filter -A INPUT -p tcp --dport 52113 -j DROP
注:
1.iptables默认用的就是filter表,因此,以上两条命令等价。
2. 其中的INPUT DROP要大写。
3. --jump        -j target
   target for rule (may load target extension)
基本的处理行为:ACCEPT(接受)、DROP(丢弃)、REJECT(拒绝)
比较:DROP好于REJECT
命令的规则仅仅是在内存中生效。
 
练习一下:禁止用户访问80端口或者是3306端口 
[root@ipt ~]# iptables -t filter -A INPUT -p tcp --dport 80 -j DROP  #添加
[root@ipt ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80  #添加成功
 
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
 
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@ipt ~]# iptables -t filter -D INPUT -p tcp --dport 80 -j DROP  #删除
[root@ipt ~]# iptables -L -n
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        
 
增加序号并删除序号方法
[root@ipt ~]# iptables -L -n --line-numbers  #添加一个序号
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 
 
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
 
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         
[root@ipt ~]#  iptables -t filter -D INPUT 1  #删除直接指定序号
 
添加规则
参数中的 -A -I 的区别,防火墙的过滤是根据规则顺序。
-A 是添加到规则到指定链的结尾,也就是最后一条(可以这么理解:叠加到最后一行)
iptables -t filter -A INPUT -p tcp --dport 80 -j DROP
-I 是添加到规则到指定链的开头,也就是第一条   (可以这么理解:叠加到开头一行)
iptables -t filter -I INPUT -p tcp --dport 80 -j DROP    
 
分析网路连接数日PV比较大的时候怎么封IP
根据源地址封IP 需要用-I 
iptables -I INPUT  -p tcp --dport 8080 -j DROP
 
封端口用-A 
iptables -A INPUT -p tcp --dport 9001 -j DROP
 
分析aphace日志并且封IP:
[root@ipt ~]# awk '{print $1}' /app/log/access_log |sort|uniq -c|sort -rn -k1
找到访问最多的去封:
封的方法
iptables -A INPUT -p tcp -s 10.0.0.108 --dport 80 -j DROP
 
指定插入的行数添加
iptables -I INPUT 2 -p tcp --dport 8080 -j DROP
 
97-08-iptables命令及参数实战演练2
根据网段和IP封的方法
iptables -s(封源地址)
iptables -i  表示进入的接口
格式:网段封是您源地址,也就是Windows的地址连接CRT的ifconfig
[root@ipt ~]# iptables -t filter -A INPUT -i eth0 -s 192.168.204./24 -j DROP  
开封:IP段封
[root@ipt ~]# iptables -t filter -A INPUT -i eth0 -s 192.168.204.1 -j DROP
 
结果:执行了以上命令结果就会 ① ping不通   ② CRT也连接不上。
 
解决办法:
登录虚拟机执行以下命令。
①完整的删除 :
[root@ipt ~]# iptables -t filter -D INPUT -i eth0 -s 192.168.204.1 -j DROP 
②根据链的序列号删除 ,每条链都是各自从1开始删除
iptables -t filter -D INPUT 1
③ iptables -F 清掉 (常用)
 
(一)获取源地址的方法:
Windows上执行 ipconfig 出现
ipconfig
 
以太网适配器 VMware Network Adapter VMnet8:
 
   连接特定的 DNS 后缀 . . . . . . . : localdomain
   本地链接 IPv6 地址. . . . . . . . : fe80::d417:f822:93d9:d26f%61
   IPv4 地址 . . . . . . . . . . . . : 192.168.204.1   #Windows源地址 封这个地址。
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . :
 
封其他的机器方法:
需要添加!才可以。
区别是 一个Centos5.8的!在前 Centos6.4的!在后面。可以封网段或者是IP
Centos5.8版本
iptables -t filter  -I INPUT -p icmp --icmp-type 8 -i eth0 -s ! 192.168.204/24 -j DROP
 
Centos6.4版本或者更高;
iptables -t filter -A INPUT -i eth0 ! -s 192.168.204.1   -j DROP  
 
iptables -A INPUT -s 10.0.1.0/24 -j DROP   网段iptables -A INPUT ! -s 10.0.1.41 -j DROP   ip
 
封icmp方法:
(一)以网段封:
iptables -t filter  -I INPUT -p icmp --icmp-type 8 -i eth0 ! -s 192.168.204/24  -j DROP
 
解释:除了10网段不能ping 其他的都可以ping  
 
(二)禁止ping 所有的网段禁止ping 
iptables -t filter  -I INPUT -p icmp --icmp-type 8 -i eth0 -s 192.168.204/24   -j DROP
 
解释:去掉!就可以了、
 
封堵SSH端口root端口
iptables -t filter  -I INPUT -p tcp --dorp 52113 ! -s 192.168.204/24  -j DROP
 
网段封堵但是自己还是可以连接的。
 
企业中的应用。
① ×××服务 拨号拨到×××上,以×××的内网地址去访问内部服务器
② 前端对外提供服务的机器SSH禁止外部IP访问。可以开启后端或者不对外提供服务器。保留SSH服务,然后连接这台机器,
③ 流量特别大的时候外网服务器不要开启防火墙。影响性能。
 
封掉3306端口
iptables -A INPUT -p tcp  --dport 3306 -j DROP
 
匹配指定协议的协议 
iptables -A INPUT -p  tcp   -s 192.168.204.129 -j DROP #指定地址
 
匹配指定协议外的所有协议 
iptables -A INPUT -p ! tcp    -s 192.168.204.129 -j DROP #指定地址
匹配主机源IP
iptables -A INPUT -s 10.0.0.14
iptables -A INPUT -s ! 10.0.0.14
 
匹配网段
iptables -A INPUT -s 10.0.0.0/24
iptables -A INPUT -s ! 10.0.0.0/24
匹配单一端口封源端口NDS封堵
iptables -A INPUT -p tcp --sport 53
iptables -A INPUT -p udp --dport 53
 
匹配指定端口之外的端口
iptables -A INPUT -p tcp --dport ! 22 
iptables -I INPUT -p tcp ! --dport 22  -s 10.0.0.123 -j DROP
 
匹配单一端口
iptables -A INPUT -p tcp --sport 53
iptables -A INPUT -p udp --dport 53
 
匹配端口范围:******
冒号隔开封范围
iptables -A INPUT -p tcp --sport 22:80
iptables -I INPUT -p tcp --dport 21,22,23,24 -j ACCEPT===》错误语法
iptables -I INPUT -p tcp -m multiport --dport 21,22,23,24 -j ACCEPT
iptables -I INPUT -p tcp --dport 3306:8809 -j ACCEPT
iptables -I INPUT -p tcp --dport 18:80 -j DROP        #22      SSH端口
iptables -I INPUT -p tcp --dport 52000:53000 -j DROP  #52113   SSH端口
匹配ICMP类型
iptables -A INPUT -p icmp --icmp-type 8 
例:iptables -A INPUT -p icmp --icmp-type 8 -j DROP         ##常用的禁止ping的命令
iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT  #any 代表是所有
iptables -A FORWORD -s 192.168.147.0/24 -p icmp -m icmp --icmp-type any -j ACCEPT
 
匹配指定的网络接口
iptables -A INPUT -i eth0
iptables -A FORWARD -o eth0
 
记忆方法:
--in-interface -i [!] input name[+]
                                network interface name ([+] for wildcard)
--out-interface -o [!] output name[+]
                                network interface name ([+] for wildcard)
匹配网络状态  FTP常用。
-m state --state
    NEW:           已经或将启动新的连接
    ESTABLISHED:   已建立的连接
    RELATED:       正在启动新连接
    INVALID:       非法或无法识别的
 
 常用的:FTP服务是特殊的,需要配状态连接。
 
●7.允许关联的状态包通过(web服务不要使用FTP服务)
#others RELATED ftp协议
#允许关联的状态包
iptables -A INPUT  -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#___________________________ ipconfig conf end _______________________________
比喻:看电影出去WC或者接个电话,回来也得允许进去。
 
控制包的速率设置时间段和并发
-m limit  限制指定时间包的允许通过数量及并发数
 
--limit n/{second/minute/hour}:指定时间内的请求速率"n"为速率,后面为时间分别为:秒、分、时    
 
--limit-burst [n]:在同一时间内允许通过的请求"n"为数字,不指定默认为5
 
fg:本机地址:172.16.14.1,允许172.16.0.0/16网络ping本机,但限制每分钟请求不能超过20,每次并发不能超过6个
 
iptables -A INPUT -s 172.16.0.0/16 -d 172.16.14.1 -p icmp --icmp-type 8 -m limit --limit 20/min --limit-burst 6 -j ACCEPT
 
iptables -A OUTPUT -s 172.16.14.1 -d 172.16.0.0/16 -p icmp --icmp-type 0 -j ACCEPT
 
-m state --state    NEW:已经或将启动新的连接    ESTABLISHED:已建立的连接    RELATED:正在启动的新连接    INVALID:非法或无法识别的 
 
 
 97-09-生产案例1:企业服务器防火墙功能部署实战演练
生产中常见的模式有两种:
企业配置上网网关路由 (公园模式)    不安全
服务器主机防火墙     (电影院模式)  相对安全
 
防火墙部署实战
1、清空之前的部署。
iptables -F
iptables -X
iptables -Z
2、让自己的SSH 的端口通过(源地址)连接CRT的ifconfig的地址即可、
iptables -A INPUT -p tcp  --dport 22 -s 192.168.204.0/24  -j ACCEPT 
 
ADSL拨号的网操作以下命令
iptables -A INPUT -p tcp  --dport 22  -j ACCEPT 
 
3、设置本机lo的通讯规则
iptables -A INPUT -i lo -j ACCEPT 
iptables -A OUTPUT -o lo -j ACCEPT
4、设置默认的防火墙禁止和允许
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP   
5、开启信任的IP网段(内部的网段)
#允许IDC LAN /WAN和办公网IP的访问,及对外合作机构的访问 
iptables -A INPUT -s 124.43.62.96/27 -p all -j ACCEP ←办公室固定的IP段
iptables -A INPUT -s 192.168.1.0/24 -p all -j ACCEPT  ←IDC机房的内网网段
iptables -A INPUT -s 10.0.0.0/24 -p all -j ACCEPT     ←其他机房的内网网段
iptables -A INPUT -s 203.83.24.0/24 -p all -j ACCEPT  ←IDC机房的外网网段
iptables -A INPUT -s 201.82.34.0/24 -p all -j ACCEPT  ←其他IDC机房的外网网段
iptables -A INPUT -p icmp --icmp-type 8  -j ACCEPT  #允许外面的人ping通。可以不设定。看需求。
6、WEB服务允许业务服务端口对外访问(允许http服务无条件通过)
#outer server|允许用户的外部服务80
iptables -A INPUT -p tcp  --dport 80 -j ACCEPT
 
7、允许icmp类型协议通过
iptables -A INPUT -p icmp --icmp-type 8  -j ACCEPT  #像百度服务器一样 对外可以ping
不想开就不开。那就不用执行这条命令了。
iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT 
 
如果对内开启,对外不开就用下面的形式。
iptables -A INPUT -p icmp -s 10.0.0.0/24 -m icmp --icmp-type any -j ACCEPT  #对内可以ping 对外不可以ping
#iptables -A INPUT -p icmp --icmp-type 8  -j ACCEPT #允许外面的人ping通可以不设定
8、允许关联的状态包通过 (web服务不要使用ftp服务。)有的话添加以下内容、
#others RELATED FTP 协议
#允许关联我的数据包
iptables -A INPUT  -m state --state ESTABLISHED,RELATED -j ACCEPT  允许关联的包进入
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  允许关联的包出去
 
[root@test ~]# nmap 192.168.204.129 -p 1-65535    扫描端口命令 
[root@lamp01 ~]# nmap 10.0.1.9 -p 20-100Starting Nmap 5.51 (http://nmap.org ) at 2015-09-18 15:36 CSTNmap scan report for bogon (10.0.1.9)Host is up (0.00031s latency).Not shown: 79 filtered portsPORT   STATE SERVICE22/tcp open  ssh80/tcp open  httpMAC Address: 00:0C:29:15:C5:87 (VMware)Nmap done: 1 IP address (1 host up) scanned in 8.35 seconds[root@lamp01 ~]# netstat -lntActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State      tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      tcp        0      0 :::22                       :::*                        LISTEN      tcp        0      0 :::10050                    :::*                        LISTEN      [root@lamp01 ~]# nmap 10.0.1.9 -p 3306Starting Nmap 5.51 (http://nmap.org ) at 2015-09-18 15:37 CSTNmap scan report for bogon (10.0.1.9)Host is up (0.00029s latency).PORT     STATE    SERVICE3306/tcp filtered mysqlMAC Address: 00:0C:29:15:C5:87 (VMware)Nmap done: 1 IP address (1 host up) scanned in 6.76 seconds
 
练习扫描51CTO的服务器端口
[root@lamp01 ~]# nmap blog.51cto.com -p 22,80,443,3306,161,25Starting Nmap 5.51 (http://nmap.org ) at 2015-09-18 15:39 CSTNmap scan report for blog.51cto.com (118.144.78.52)Host is up (0.0084s latency).Other addresses for blog.51cto.com (not scanned): 118.144.78.54PORT     STATE  SERVICE22/tcp   closed ssh25/tcp   closed smtp80/tcp   open   http161/tcp  closed snmp443/tcp  closed https3306/tcp closed mysql
 
 
 
注意:以上的配置是执行在内存中。 
 
防火墙的配置全部变成文件保存。
[root@test ~]# cp /etc/sysconfig/iptables  /etc/sysconfig/iptables.org # 原始org 
 
方法(一)永久保存变成配置文件:
[root@test ~]# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:     [确定]
方法(二)永久保存变成配置文件:
 [root@test ~]# iptables-save >/sysconfig/iptables  
注意的是:  ①:/etc/sysconfig/iptables 是iptables的默认配置文件。
    ②:第一次保存可以覆盖。以后就是追加。
 
[root@test ~]# cat /etc/sysconfig/iptables  #生成的默认配置文件
# Generated by iptables-save v1.4.7 on Thu Sep 17 23:00:39 2015
*filter
:INPUT DROP [53533:2367508]    #默认的规则
:FORWARD DROP [0:0]#默认的规则
:OUTPUT ACCEPT [21:1920]#默认的规则
-A INPUT -s 192.168.204.0/24 -p tcp -m tcp --dport 22 -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -s 192.168.1.0/24 -j ACCEPT 
-A INPUT -s 10.0.0.0/24 -j ACCEPT 
-A INPUT -s 203.83.24.0/24 -j ACCEPT 
-A INPUT -s 201.82.34.0/24 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT 
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT 
-A INPUT -s 192.168.204.0/24 -p icmp -m icmp --icmp-type any -j ACCEPT 
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT 
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A OUTPUT -o lo -j ACCEPT 
-A OUTPUT -o lo -j ACCEPT 
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
COMMIT
# Completed on Thu Sep 17 23:00:39 2015
 
97-10-企业场景如何维护防火墙及对应面试题
企业iptables面试题:自定义链处理syn***
iptables -N syn-flood
     # 自定义一个链 名字叫syn-flood
iptables -A INPUT -i eth0 -syn -j syn-flood
# 从etho进来的并且符合syn-fiood。网络状态只发syn的就是***,搞满连接池
iptables -A syn-flood -m limit -limit 5000/s -limit-burst 200 -j RETURN 
     #针对syn-flood处理 ,符合这样的东西并限制5000s 并发只能200
iptables -A syn-flood -j DROP
     # 并且丢弃
    首先是一个syn-flood的***、
 
97-11-企业场景如何维护防火墙详解
一般情况。第一次维护连接的话就是修改配置文件或者添加脚本。
 
(一)实战操作:演练添加一个端口873:。
[root@test ~]# vi /etc/sysconfig/iptables  #编辑配置文件
# Generated by iptables-save v1.4.7 on Thu Sep 17 23:00:39 2015
*filter
:INPUT DROP [53533:2367508]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [21:1920]
-A INPUT -s 192.168.204.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -s 192.168.1.0/24 -j ACCEPT
-A INPUT -s 10.0.0.0/24 -j ACCEPT
-A INPUT -s 203.83.24.0/24 -j ACCEPT
-A INPUT -s 201.82.34.0/24 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 873 -j ACCEPT  #添加一个873
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -s 192.168.204.0/24 -p icmp -m icmp --icmp-type any -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Thu Sep 17 23:00:39 2015
~                                                                                                                                     
~                                                                                                                                     
~                                                                                                                                     
"/etc/sysconfig/iptables" 23L, 890C written
 [root@test ~]# /etc/init.d/iptables reload  #有的时候不成功就在start 再reload       
 [root@test ~]# /etc/init.d/iptables start
iptables:应用防火墙规则:                                 [确定]
[root@test ~]# /etc/init.d/iptables reload
iptables: Trying to reload firewall rules:                 [确定]
 [root@test ~]# iptables -L -n               #查看显示结果
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  192.168.204.0/24     0.0.0.0/0           tcp dpt:22 
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  192.168.1.0/24       0.0.0.0/0           
ACCEPT     all  --  10.0.0.0/24          0.0.0.0/0           
ACCEPT     all  --  203.83.24.0/24       0.0.0.0/0           
ACCEPT     all  --  201.82.34.0/24       0.0.0.0/0           
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:873 #表示添加成功
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 8 
ACCEPT     icmp --  192.168.204.0/24     0.0.0.0/0           icmp type 255 
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 8 
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
 
Chain FORWARD (policy DROP)
target     prot opt source               destination         
 
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
 
 
(二)封IP的办法:发现问题是一个IP不断地***服务器或者是BBS里乱发帖、
手动封:
[root@test ~]# iptables -I INPUT -s 10.0.0.116 -j DROP
[root@test ~]# iptables -I INPUT -s 10.0.0.106 -j DROP       #指定IP
[root@test ~]# iptables -I INPUT -p tcp -s 10.0.0.106 --dport 80 -j DROP  #精细 指定IP 指定端口
 
自动封:
访问链接数
访问的日志
详细的见脚本(已经写好并测试)
 
(三)防火墙小问题:
① 企业中硬件和软件的防火墙要不要同时使用?
    答: 可以同时使用。
   企业的防火墙一般放在网关位置。 硬件相当于大厦的入口,楼里的屋子门好比软件防火墙。
② IDC机房部署了防火墙,我们的服务器可以不开防火墙吗?
  答:绝对不可以、
 
部署企业及IDC机房上网配置网关
 
局域网共享的两条命令方法:
方法1:适合于有固定外网地址的:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 10.0.0.7
(1)-s 192.168.1.0/24 办公室或IDC内网网段。
(2)-o eth0 为网关的外网卡接口。
(3)-j SNAT --to-source 10.0.0.19 是网关外网卡IP地址。
方法2:适合变化外网地址(ADSL):
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE 伪装。
 
实战企业上网的网关服务器
1)网关服务器A,首先是能上网,然后setup添加一块网卡,设置内网10.0.0.72)客户服务器B,setup配置IP为10.0.0.8 网关为10.0.0.7,还需要配置DNS3)在网关服务器上编辑文件/etc/sysctl.conf将设置成:net.ipv4.ip_forward = 14)将默认的防火墙转发规则开启:iptables -P FORWARD ACCEPT5)加载内核模块并查看:   modprobe  ip_tables   modprobe  iptable_filter   modprobe  iptable_nat   modprobe  ip_conntrack   modprobe  ip_conntrack_ftp   modprobe  ip_nat_ftp   modprobe  ipt_state
查看:lsmod | grep ^ip6)在网关服务器上配置: iptables -t  nat  -A POSTROUTING  -s 10.0.0.0/24(内网IP) -o eth0 -j SNAT --to-source 192.168.1.1209(外网IP)
 /etc/init.d/iptables save
 如果是ADSL动态的网关IP:iptables -t  nat  -A POSTROUTING  -s 10.0.0.0/24 -o eth0 -j MASQUERADE伪装
  
第一台机器:
首先:添加一个Eth1的
 
 
 
[root@test ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:80:7B:E9  
          inet addr:192.168.204.129  Bcast:192.168.204.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe80:7be9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3370 errors:0 dropped:0 overruns:0 frame:0
          TX packets:960 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:332048 (324.2 KiB)  TX bytes:153963 (150.3 KiB)
 
eth1      Link encap:Ethernet  HWaddr 00:0C:29:80:7B:F3  
          inet addr:192.168.1.7  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe80:7bf3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:566 (566.0 b)
 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
 
[root@test ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.204.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth1
0.0.0.0         192.168.204.2   0.0.0.0         UG    0      0        0 eth0
 
第二台机器:
1.8的是第二台  1.7的是第一台 给网关用于上网
第一步:vi /etc/sysctl.conf
    net.ipv4.ip_forward = 1
 
第二步:
       [root@test ~]# iptables -L -n
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   
 
[root@test ~]# iptables -L -n              
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  192.168.204.0/24     0.0.0.0/0           tcp dpt:22 
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  192.168.1.0/24       0.0.0.0/0           
ACCEPT     all  --  10.0.0.0/24          0.0.0.0/0           
ACCEPT     all  --  203.83.24.0/24       0.0.0.0/0           
ACCEPT     all  --  201.82.34.0/24       0.0.0.0/0           
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
 
Chain FORWARD (policy DROP)
target     prot opt source               destination         
 
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
[root@test ~]# iptables -P INPUT ACCEPT
[root@test ~]# iptables -F
[root@test ~]# 
[root@test ~]# 
[root@test ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
 
Chain FORWARD (policy DROP)
target     prot opt source               destination         
 
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination   
[root@test ~]# iptables -P FORWARD ACCEPT 
[root@test ~]# 
[root@test ~]# iptables -L -n
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   
[root@test ~]# /etc/sysconfig/iptables  stop
[root@ipt ~]# lsmod|egrep ^ipipt_REJECT              2351  0 ipv6                  318183  90 
没有模块的话需要载入模块。
modprobe ip_tablesmodprobe iptable_filtermodprobe iptable_natmodprobe ip_conntrackmodprobe ip_conntrack_ftpmodprobe ip_nat_ftpmodprobe ipt_state
 
[root@test ~]# lsmod|egrep ^ip
iptable_nat             6051  0 
ipt_REJECT              2351  0 
iptable_filter          2793  0 
ip_tables              17831  2 iptable_nat,iptable_filter
ipv6                  334932  72
 
[root@test ~]# ping 192.168.1.7  互相ping(第二台ping)
PING 192.168.1.7 (192.168.1.7) 56(84) bytes of data.
64 bytes from 192.168.1.7: icmp_seq=1 ttl=128 time=0.999 ms
64 bytes from 192.168.1.7: icmp_seq=2 ttl=128 time=0.922 ms
64 bytes from 192.168.1.7: icmp_seq=3 ttl=128 time=0.729 ms
^C
--- 192.168.1.7 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2117ms
rtt min/avg/max/mdev = 0.729/0.883/0.999/0.116 ms
.8机器不可以上网
 
 
[root@test ~]# ping 192.168.1.8   互相ping(第一台ping)
PING 192.168.1.8 (192.168.1.8) 56(84) bytes of data.
From 192.168.1.7 icmp_seq=2 Destination Host Unreachable
From 192.168.1.7 icmp_seq=3 Destination Host Unreachable
From 192.168.1.7 icmp_seq=4 Destination Host Unreachable
From 192.168.1.7 icmp_seq=6 Destination Host Unreachable
From 192.168.1.7 icmp_seq=7 Destination Host Unreachable
From 192.168.1.7 icmp_seq=8 Destination Host Unreachable
^C
--- 192.168.1.8 ping statistics ---
8 packets transmitted, 0 received, +6 errors, 100% packet loss, time 7750ms
pipe 3
在.8上执行以下命令;
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 10.0.0.7
 
iptables的生产常用场景:
1)实现服务器本身防火墙功能,使用filter表。
 
-A INPUT -s 192.168.204.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
 
2)实现局域网上网网关,使用nat表,(POSTROUTING)网关上也可以同时用filter表做防火墙。
 
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 10.0.0.7
 
 
3)实现NAT功能,如:由外部IP映射到内部服务器IP(包括端口),使用nat表,PREROUTING的链。
iptables -t nat -A PREROUTING -d 10.0.0.7 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.8:9000
4)其他。。。略。
 
企业应用场景:1) 把访问外网IP及端口的请求映射到内网某个服务器及端口(企业内部)。2) 硬件防火墙,把访问LVS/nginx外网VIP及80端口的请求映射到IDC 负载均衡服务器内部IP及端口上(IDC机房的操作)
 
97-13-企业案例3:外网地址及端口映射到内网服务器
网关服务器上执行以下命令。映射命令 
 
 
iptables -t nat -A PREROUTING -d 10.0.0.7 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.8:9000
 
上网的命令
 
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 10.0.0.7
 
 
 
链接地址 == 企业面试题:(案例)
1)生产环境大于254台机器网段划分及路由解决方案详解01 
   http://v.youku.com/v_show/id_XNTAyMjAwMzI0.html
(2)linux route命令深入浅出与实战案例精讲
   http://oldboy.blog.51cto.com/2561410/1119453
4)办公路由器+网关功能(zebra路由+iptables过滤及NAT+squid正向透明代理80+ntop/iftop/iptraf流量查看+tc流量控制限速)。
7 映射多个外网IP上网
 
iptables -t nat -A POSTROUTING -s 10.0.0.0/255.255.240.0 -o eth0 -j SNAT --to-source 124.42.60.11-124.42.60.16iptables -t nat -A POSTROUTING -s 172.16.1.0/255.255.255.0 -o eth0 -j SNAT --to-source 124.42.60.103-124.42.60.1067 映射多个外网IP上网iptables -t nat -A POSTROUTING -s 10.0.0.0/255.255.240.0 -o eth0 -j SNAT --to-source 124.42.60.11-124.42.60.16iptables -t nat -A POSTROUTING -s 172.16.1.0/255.255.255.0 -o eth0 -j SNAT --to-source 124.42.60.103-124.42.60.106#iptables -t nat -A POSTROUTING -s 192.168.1.0/22 -o eth0 -j SNAT --to-source 10.0.0.241-10.0.0.249
 
iptables 的内核优化企业面试题
#5、dmesg里面显示 ip_conntrack: table full, dropping packet.的错误提示.如何解决。 
 
 
C64:
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
 
优化常常出现以下的错误:
http://oldboy.blog.51cto.com/2561410/1336488
 
1、5.8版本上
error: "net.ipv4.ip_conntrack_max"is an unknown key 
error: "net.ipv4.netfilter.ip_conntrack_max"is an unknown key 
error: "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established"is an unknown key 
error: "net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait"is an unknown key 
error: "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait"is an unknown key 
error: "net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait"is an unknown key
 
这个错误可能是你的防火墙没有开启或者自动处理可载入的模块ip_conntrack没有自动载入,解决办法有二,一是开启防火墙,二是自动处理开载入的模块ip_conntrack
解决办法:
modprobe ip_conntrack 
echo "modprobe ip_conntrack">> /etc/rc.local
2、6.4版本上
error: "net.nf_conntrack_max"isan unknown key 
error: "net.netfilter.nf_conntrack_max"isan unknown key 
error: "net.netfilter.nf_conntrack_tcp_timeout_established"isan unknown key 
error: "net.netfilter.nf_conntrack_tcp_timeout_time_wait"isan unknown key 
error: "net.netfilter.nf_conntrack_tcp_timeout_close_wait"isan unknown key 
error: "net.netfilter.nf_conntrack_tcp_timeout_fin_wait"isan unknown key
 
这个错误可能是你的防火墙没有开启或者自动处理可载入的模块ip_conntrack没有自动载入,解决办法有二,一是开启防火墙,二是自动处理开载入的模块ip_conntrack
解决办法:
modprobe nf_conntrack 
echo "modprobe nf_conntrack">> /etc/rc.local
6.4版本上
error: "net.bridge.bridge-nf-call-ip6tables"isan unknown key 
error: "net.bridge.bridge-nf-call-iptables"isan unknown key 
error: "net.bridge.bridge-nf-call-arptables"isan unknown key
 
这个错误是由于自动处理可载入的模块bridge没有自动载入,解决办法是自动处理开载入的模块ip_conntrack
解决办法:
modprobe bridge 
echo "modprobe bridge">> /etc/rc.local
 
 [root@test ~]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
解决办法:
modprobe bridge 
echo "modprobe bridge">> /etc/rc.local
 
zebra路由:Linux上配置软件常用的地方
①大厦帮你做路由了。我们直接配置Linux网关
 
②企业级的光纤。光环人家的自己必须配置路由器因为 给你的地址以下的:必须使用zebra
 
路由连接地址为10.1.34.81/24  #内网地址ip配成81
默认路由:10.1.34.1            #网关配成.1
分配的公网ip地址:110.233.24.96/27 255.255.255.224  #运营商上梁已经控制了 光环,电信通之类的,在上移动联通大网了
 
购买企业级路由器:
 
配置信息:
client(config)#int eth0
client(config-if)#ip add 10.1.34.81 255.255.255.0
client(config-if)#int eth1
client(config-if)#ip add 110.233.24.96 255.255.255.224
client(config)#ip route 0.0.0.0 0.0.0.0 10.1.32.1
client(config)#ip route 110.233.24.96/27 eth1