码迷,mamicode.com
首页 > 系统相关 > 详细

Linux Firewall ---iptables

时间:2016-07-21 22:11:58      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:iptables

Linux Firewall---iptables

iptables 命令格式:

iptables [-t TABLE] {-OPTION} [chain] [rulenum][rule-sepecification]

TABLE : rawmanglenatfilter

过滤规则应用于filterNAT规则应用于nat、用于修改分组数据的特定规则应用于mangle、而独立于Netfilter连接跟踪子系统起作用的规则应用于raw

 OPTION:

  1. Object:chain

        A(Append)C(Check)D(delete)I(insert)R(replace)L(list)S(list-rules)F(flush)Z(zero)X(delete-chain)P(policy)E(rename-chain)

  1.    OTHER OPTIONS

-v, --verbose -n, --numeric -x,--exact --line-numbers             –modprobe=command

 

Chain: PREROUTING INPUT OUTPUT FORWARD POSTROUTING

 

rule-specification = [matches...] [target]

match = [PARAMETERS]|-m matchname [per-match-options]

target = -j targetname [per-target-options]

 

PARAMETERS:

[!] -p, --protocol protocol [!] -s, --sourceaddress[/mask][,...][!] -d, --destination address[/mask][,...]-j, --jumptarget -g, --goto chain[!] -i, --in-interface name[!] -o,--out-interface name[!] -f, --fragment-c, --set-counters packets bytes

                   MatchNmae:

                            Conntrackicmp iprange limit multiport state string tcp time udp

                                     -ptcp:隐含了-m tcp

[!]--source-port,--sport port[:port]:匹配报文中传输层的源端口;

[!]--destination-port,--dport port[:port]:匹配报文中传输层的目标端口;

                                                                            [!]--tcp-flags mask comp

                                                                           SYNACKFINRSTURGPSH 

                                                                           mask:要检查的标志位列表,以逗号分隔;                                                                               comp:必须为1的标志位,余下的出现在mask                            表中的标志位则必须为0

                                                                          

                                                                           --tcp-flags  SYN,ACK,FIN,RST  SYN

                                                                 [!]--syn

                                                                           相当于--tcp-flags  SYN,ACK,FIN,RST  SYN

                                                        -pudp:隐含了-m udp

[!]--source-port,--sport port[:port]:匹配报文中传输层的源端口;

[!] --destination-port,--dportport[:port]:匹配报文中传输层的目标端口;

                                                        -picmp:隐含了-m icmp:

                                                                  [!] --icmp-type {type[/code]|typename}

                                                                           8echo-request

                                                                           0echo-reply

 

 

 

                                                        1multiport扩展

                                                                 以离散或连续的方式定义多端口匹配条件;

                                                                

 [!] --source-ports,--sports port[,port|,port:port]...:指定多个源端口;

[!]--destination-ports,--dports port[,port|,port:port]...:指定多个目标端口;

                                                                  [!] --ports port[,port|,port:port]...:指定多个端口;

                                                                  

                                                        2iprange扩展

                                                                 以连续的ip地址范围指明连续的多地址匹配条件;

                                                                

                                                                 [!]--src-range from[-to]:源IP地址;

                                                                 [!]--dst-range from[-to]:目标IP地址;

                                                                

                                                        3string扩展

                                                                 对报文中的应用层数据做字符串匹配检测;

                                                       

                                                                 [!]--string pattern:要检测字符串模式;

                                                                 [!]--hex-string pattern:要检测的字符串模式,16进制编码;

                                                                 --algo{bm|kmp}

                                                                

                                                        4time扩展

                                                                  根据报文到达的时间与指定的时间范围进行匹配度检测;

                                                                

                                                                 --datestartYYYY[-MM[-DD[Thh[:mm[:ss]]]]]:起始日期时间;

                                                                 --datestopYYYY[-MM[-DD[Thh[:mm[:ss]]]]]:结束日期时间;

                                                                

                                                                 --timestarthh:mm[:ss]

                                                                 --timestop  hh:mm[:ss]

                                                                

                                                                 [!]--monthdays day[,day...]

                                                                 [!]--weekdays day[,day...]

                                                                

                                                                 ~]#iptables -I INPUT -d 172.16.100.67 -p tcp --dport 23 -m time --timestart09:00:00 --timestop 18:00:00 --weekdays Tue,Thu,Sat -j ACCEPT

                                                                

                                                        5connlimit扩展

                                                                 根据每客户端IP做并发连接数匹配;

                                                                

                                                                 --connlimit-upton:连接数数量小于等于n,此时应该允许;

                                                                 --connlimit-aboven:连接数数量大于n,此时应该拒绝;

                                                                

                                                                 ~]#iptables -A INPUT -d 172.16.100.67 -p tcp --dport 23 -m connlimit--connlimit-upto 2 -j ACCEPT

                                                                

                                                        6limit扩展

                                                                 基于收发报文的速率进行匹配;

                                                                

                                                                 --limitrate[/second|/minute|/hour|/day]:平均速率

                                                                 --limit-burstnumber:峰值速率

                                                                

                                                        7state扩展

                                                                 状态检测;连接追踪机制(conntrack);

                                                                

                                                                  INVALID:无法识别的状态;

                                                                  ESTABLISHED:已建立的连接;

                                                                  NEW:新连接;

                                                                  RELATED:相关联的连接;

                                                                  UNTRACKED:未追踪的连接;

                                                                  

                                                                 nf_conntrack内核模块;

                                                                           追踪到的连接:/proc/net/nf_conntrack文件中;

                                                                          

                                                                           能追踪的最大连接数量定义在:/proc/sys/net/nf_conntrack_max

                                                                                    此值可自行定义,建议必要时调整到足够大;

                                                                                   

                                                                           不同的协议的连接追踪的时长:

                                                                                    /proc/sys/net/netfilter/

                                                                                   

                                                                 [!]--state STATE

                                                                

                                                                 如何开放被模式的ftp服务:

                                                                           (1)装载追踪ftp协议的模块;

                                                                                    #modprobe nf_conntrack_ftp

                                                                                   

                                                                           (2)放行命令连接

                                                                                    ~]# iptables -A INPUT -d 172.16.100.67 -p tcp -m state --state ESTABLISHED -jACCEPT

                                                                                    ~] #iptables -A INPUT -d 172.16.100.67 -p tcp --dport 21 -m state --state NEW -jACCEPT

                                                                          

                                                                           (3)放行数据连接

                                                                                    ~]iptables -A INPUT -d 172.16.100.67 -p tcp -m state --state RELATED -j ACCEPT

 

                   Targetname:

                            DNATLOG MASQUERADE NOTRACK REDIRECT REJECT SNAT

2.


Linux Firewall ---iptables

标签:iptables

原文地址:http://9665476.blog.51cto.com/9655476/1828562

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!