LINUX 安全
一、IP 五元素:
源IP ,目标IP ,源端口 ,目标端口 ,协议号
二、规则表:
iptables [-t table-name] CMD [chain][rule-matcher][-j target]
-A :添加一条规则
-D :删除一条规则
-R :替换一条规则
-L :列出指定链中的所有规则
-F :清除指定链和表中的所有规则
-N :以给定的名字建立一个用户自定义链
-P :后加protocol 如:TCP ,UDP ,ICMP ,ALL
-s ipaddr/mask:指定源地址来确定,允许或拒绝
--sport :根据源端口或是端口范围
-i :根据进接口
-o :根据出接口
--syn :只不允许三次握手的第一次握手
--tcp -flags :只匹配第二次握手
-E :重新命名规则链
-I :插入一条规则在链的首部
-f :匹配IP分片
匹配扩展:
-m multiport :多端口匹配
-m limit :限制
-m mac :MAC地址
例:
iptables -t filter -A INPUT -p icmp -s !192.168.9.100 -j DROP
iptables -t filter -A INPUT -p tcp -s !1.1.1.1 -d 1.1.1.2 --dport 22 -j DROP
iptables -t filter -A INPUT -p icmp -s 1.1.1.1 -i !eth0 -j DROP
iptables -t filter -A INPUT -p tcp -s 1.1.1.1 !--syn -j ACCEPT
iptables -A INPUT -p tcp -s 1.1.1.1 -m multiport --sport 23,22,80,25 -j DROP
iptables -A INPUT -p tcp -s 1.1.1.1 --sport 23:80 -j DROP
iptables -A INPUT -i eth0 -p icmp --icmp-type eth0-request -m limit --limit 1/second -j ACCEPT
iptables -A INPUT -i eth0 -p icmp --icmp-type ech0-request -j DROP
iptables -A INPUT -i eth0 -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT
iptables -A icmp-test -s 0/0 -d 0/0 -p icmp -j DROP
iptables -A INPUT -S 0/0 -d 0/0 -j icmp-test
三、清除所有策略
iptables -F
更改默认策略
iptables -P INPUT DROP
查看规则序号
iptables -L --line -n
删除序号为“1”的规则
iptables -D INPUT 1
清零计数器
iptables -Z
保存零碎的配置
service iptables save
四、ICMP 几个基础
ech0-reply --0
echo-request --8
time-exceeded --11
redirect --5
destination-unreachable --3
network-unreachable
host-unreachable
protocol-unreachable