常见网络攻击预防
1,避免Ping扫描
ping操作是通过icmp协议进行的,因此可通过Iptables对icmp协议进行过滤:
[simonsun@magic ~]$ sudo iptables -I INPUT -p icmp -j DROP
[simonsun@magic ~]$ sudo /etc/init.d/iptables save
将当前规则保存到 /etc/sysconfig/iptables:???????????????? [确定]
[simonsun@magic ~]$ sudo iptables -t filter -nL
Chain INPUT (policy ACCEPT)
target???? prot opt source?????????????? destination????????
DROP?????? icmp --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
RH-Firewall-1-INPUT? all? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
Chain FORWARD (policy ACCEPT)
target???? prot opt source?????????????? destination????????
RH-Firewall-1-INPUT? all? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
Chain OUTPUT (policy ACCEPT)
target???? prot opt source?????????????? destination????????
Chain RH-Firewall-1-INPUT (2 references)
target???? prot opt source?????????????? destination????????
ACCEPT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
ACCEPT???? icmp --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? icmp type 255
ACCEPT???? esp? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
ACCEPT???? ah?? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
ACCEPT???? udp? --? 0.0.0.0/0??????????? 224.0.0.251???????? udp dpt:5353
ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? udp dpt:631
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? tcp dpt:631
ACCEPT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state RELATED,ESTABLISHED
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:21
ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW udp dpt:137
ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW udp dpt:138
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:139
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:445
ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? state NEW tcp dpt:443
REJECT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? reject-with icmp-host-prohibited
[simonsun@magic ~]$
由于要丢弃所有的ping操作,因此最好将这些规则加在iptables的最顶端,-I INPUT后面没有加入数字,表明在INPUT链的最顶端插入规则。
?
2,预防DDoS——Distributed Denial of service (分布式拒绝服务攻击)
在/etc/sysctl.conf里加入:
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 3
net.ipv4.tcp_syn_retries = 3
并执行sysctl -p 以激活设置,
设置tcp_syncookies为1可以打开SYN Cookie功能,该功能可以防止部分SYN攻击;降低tcp_synack_retries以及tcp_syn_retries的值可以减少syn重试次数也有一定的效果。
?
?
PS:iteye的自动添加tag的功能确实很强,能把所有博客里的文章都自动就加上tag,但偶尔也加的不很准确,像我这篇文章,刚才发现被加的是:.net J#,网络协议, ”网络协议“应该是没错的,单net和j#是真不大对。现在我已经改过来了:linux shell 网络协议 iptables