linux下的iptables & ping

在linux下,要想實現禁用ping有兩種方法。

方法一:

    echo “1″ > /proc/sys/net/ipv4/icmp_echo_ignore_all

方法二:      

        iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -j DROP

        iptables -A INPUT -p icmp –icmp-type 0 -s 0/0 -j DROP

        iptables -A OUTPUT -p icmp –icmp-type 0 -s 192.168.29.1 -j DROP

        iptables -A OUTPUT -p icmp –icmp-type 8 -s 192.168.29.1 -j DROP

如果要實現能ping通對方的主機,對方的主機不能ping自己

       iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -j DROP

        iptables -A INPUT -p icmp –icmp-type 0 -s 0/0 -j ACCEPT

        iptables -A OUTPUT -p icmp –icmp-type 0 -s 192.168.29.1 -j DROP

        iptables -A OUTPUT -p icmp –icmp-type 8 -s 192.168.29.1 -j ACCEPT



參照如下:

iptables -p icmp -h 查看幫助

ICMP類型

TYPECODEDescriptionQueryError
00Echo Reply——回顯應答(Ping應答)x
30Network Unreachable——網絡不可達
x
31Host Unreachable——主機不可達
x
32Protocol Unreachable——協議不可達
x
33Port Unreachable——端口不可達
x
34Fragmentation needed but no frag. bit set——需要進行分片但設置不分片比特
x
35Source routing failed——源站選路失敗
x
36Destination network unknown——目的網絡未知
x
37Destination host unknown——目的主機未知
x
38Source host isolated (obsolete)——源主機被隔離(作廢不用)
x
39Destination network administratively prohibited——目的網絡被強制禁止
x
310Destination host administratively prohibited——目的主機被強制禁止
x
311Network unreachable for TOS——由於服務類型TOS,網絡不可達
x
312Host unreachable for TOS——由於服務類型TOS,主機不可達
x
313Communication administratively prohibited by filtering——由於過濾,通信被強制禁止
x
314Host precedence violation——主機越權
x
315Precedence cutoff in effect——優先中止生效
x
40Source quench——源端被關閉(基本流控制)

50Redirect for network——對網絡重定向

51Redirect for host——對主機重定向

52Redirect for TOS and network——對服務類型和網絡重定向

53Redirect for TOS and host——對服務類型和主機重定向

80Echo request——回顯請求(Ping請求)x
90Router advertisement——路由器通告

100Route solicitation——路由器請求

110TTL equals 0 during transit——傳輸期間生存時間爲0
x
111TTL equals 0 during reassembly——在數據報組裝期間生存時間爲0
x
120IP header bad (catchall error)——壞的IP首部(包括各種差錯)
x
121Required options missing——缺少必需的選項
x
130Timestamp request (obsolete)——時間戳請求(作廢不用)x
14
Timestamp reply (obsolete)——時間戳應答(作廢不用)x
150Information request (obsolete)——信息請求(作廢不用)x
160Information reply (obsolete)——信息應答(作廢不用)x
170Address mask request——地址掩碼請求x
180Address mask reply——地址掩碼應答


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章