标签:with 请求 mod 最大 ali get ecc nat min
一、显示扩展显示扩展必须使用-m选项指定使用的扩展, 必须显示指明使用的扩展模块用如下方式查看:
$ rpm -ql iptables | grep "\.so"
查看显示扩展使用说明:
# CentOS 6
$ man iptables
# CentOS 7
$ man iptables-extension
以离散方式定义多端口匹配, 最多指定15个端口.
示例: 放行其他主机对192.168.123.101主机22号端口和80端口的访问
$ iptables -t filter -I INPUT -s 0.0.0.0/0 -d 192.168.123.101 -p tcp -m multiport --dports 22,80 -j ACCEPT
$ iptables -t filter -I OUTPUT -d 0.0.0.0/0 -s 192.168.123.101 -p tcp -m multiport --sports 22,80 -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
378 42192 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101 multiport dports 22,80
...
Chain OUTPUT (policy DROP 2 packets, 152 bytes)
pkts bytes target prot opt in out source destination
135 19800 ACCEPT tcp -- * * 192.168.123.101 0.0.0.0/0 multiport sports 22,80
指明连续(但一般是不能扩展为整个网络)IP地址范围时使用.
示例: 仅允许192.168.123.1至192.168.123.10来访问192.168.123.101主机的22号端口和80端口
$ iptables -t filter -I INPUT -d 192.168.123.101 -p tcp -m multiport --dports 22:23,80 -m iprange --src-range 192.168.123.1-192.168.123.10 -j ACCEPT
$ iptables -t filter -I OUTPUT -s 192.168.123.101 -p tcp -m multiport --sports 22:23,80 -m iprange --dst-range 192.168.123.1-192.168.123.10 -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
271 29080 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101 multiport dports 22:23,80 source IP range 192.168.123.1-192.168.123.10
...
...
Chain OUTPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
23 3288 ACCEPT tcp -- * * 192.168.123.101 0.0.0.0/0 multiport sports 22:23,80 destination IP range
...
检查报文中出现的字符串.
示例: 如果192.168.123.101主机网页的响应报文中带有“movie”字符, 就拒绝响应
$ iptables -t filter -I OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -m string --algo bm --string "movie" -j REJECT
根据报文到达的时间与指定时间范围进行匹配.
示例: 禁止在下午14点至16点之间访问192.168.123.101主机的80端口
$ iptables -t filter -I INPUT -d 192.168.123.101 -s 0.0.0.0/0 -p tcp --dport 80 -m time --timestart 14:00 --timestop 16:00 -j REJECT
$ iptables -L -n -v
Chain INPUT (policy ACCEPT 3 packets, 228 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT tcp -- * * 0.0.0.0/0 192.168.123.101 tcp dpt:80 TIME from 14:00:00 to 16:00:00 UTC reject-with icmp-port-unreachable
...
根据每个客户端IP(也可以是地址块)做并发连接数数量匹配.
示例: 当其他的主机对192.168.123.101主机22号端口的连接大于3个, 则拒绝后面的连接.
$ iptables -t filter -I INPUT -d 192.168.123.101 -s 0.0.0.0/0 -p tcp --dport 22 -m connlimit --connlimit-above 3 -j REJECT
$ iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
REJECT tcp -- 0.0.0.0/0 192.168.123.101 tcp dpt:22 #conn src/32 > 3 reject-with icmp-port-unreachable
...
基于手法报文的速率做检查.
令牌桶过滤器:
示例: 其他主机对192.168.123.100主机的icmp请求每秒上线最多5个, 一分钟最多30个
$ iptables -t filter -A OUTPUT -d 0.0.0.0/0 -s 192.168.123.101 -p icmp --icmp-type 0 -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT icmp -- * * 0.0.0.0/0 192.168.123.101 icmptype 8 limit: avg 30/min burst 5
...
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT icmp -- * * 192.168.123.101 0.0.0.0/0 icmptype 0
根据连接追踪机制检查连接的状态.
$ cat /proc/sys/net/nf_conntrack_max
31248
$ echo "65535" > /proc/sys/net/nf_conntrack_max
$ cat /proc/sys/net/nf_conntrack_max
65535
$ cat /proc/net/nf_conntrack
ipv4 2 udp 17 19 src=192.168.123.101 dst=202.112.29.82 sport=55386 dport=123 src=202.112.29.82 dst=192.168.123.101 sport=123 dport=55386 mark=0 secctx=system_u:object_r:unlabeled_t:s0 zone=0 use=2
ipv4 2 udp 17 19 src=192.168.123.101 dst=5.103.139.163 sport=35028 dport=123 src=5.103.139.163 dst=192.168.123.101 sport=123 dport=35028 mark=0 secctx=system_u:object_r:unlabeled_t:s0 zone=0 use=2
ipv4 2 udp 17 18 src=192.168.123.101 dst=202.112.31.197 sport=41850 dport=123 src=202.112.31.197 dst=192.168.123.101 sport=123 dport=41850 mark=0 secctx=system_u:object_r:unlabeled_t:s0 zone=0 use=2
ipv4 2 tcp 6 299 ESTABLISHED src=192.168.123.101 dst=192.168.123.1 sport=22 dport=1214 src=192.168.123.1 dst=192.168.123.101 sport=1214 dport=22 [ASSURED] mark=0 secctx=system_u:object_r:unlabeled_t:s0 zone=0 use=2
ipv4 2 udp 17 17 src=192.168.123.101 dst=5.79.108.34 sport=56947 dport=123 src=5.79.108.34 dst=192.168.123.101 sport=123 dport=56947 mark=0 secctx=system_u:object_r:unlabeled_t:s0 zone=0 use=2
示例1: 其他主机对192.168.123.101主机的22和80端口访问的状态NEW和ESTABLESHED时, 运行访问.
$ iptables -t filter -I INPUT -d 192.168.123.101 -s 0.0.0.0/0 -p tcp -m multiport --dports 22,80 -m state --state NEW,ESTABLISHED -j ACCEPT
$ iptables -t filter -I OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -p tcp -m multiport --sports 22,80 -m state --state ESTABLISHED -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
398 42224 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101 multiport dports 22,80 state NEW,ESTABLISHED
...
...
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
6 1104 ACCEPT tcp -- * * 192.168.123.101 0.0.0.0/0 multiport sports 22,80 state ESTABLISHED
...
示例2: 在192.168.123.101主机上放开被动模式的ftp服务
$ lsmod | grep ftp
$ modprobe nf_conntrack_ftp
$ lsmod | grep ftp
nf_conntrack_ftp 18638 0
nf_conntrack 111302 4 xt_connlimit,xt_conntrack,nf_conntrack_ftp,nf_conntrack_ipv4
$ iptables -t filter -A INPUT -d 192.168.123.101 -s 0.0.0.0/0 -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
$ iptables -t filter -A INPUT -d 192.168.123.101 -s 0.0.0.0/0 -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
$ iptables -t filter -A OUTPUT -s 192.168.123.101 -d 0.0.0.0/0 -p tcp -m state --state ESTABLISHED -j ACCEPT
$ iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101 tcp dpt:21 state NEW,ESTABLISHED
0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.123.101 state RELATED,ESTABLISHED
...
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
...
0 0 ACCEPT tcp -- * * 192.168.123.101 0.0.0.0/0 state ESTABLISHED
标签:with 请求 mod 最大 ali get ecc nat min
原文地址:http://blog.51cto.com/13501622/2143959