1、安裝iptables服務
下載安裝包,下載地址 http://mirrors.163.com/centos/7/os/x86_64/Packages/
然后使用 rpm 命令安裝
sudo rpm -Uvh iptables-1.4.21-24.el7.x86_64.rpm
sudo rpm -Uvh iptables-services-1.4.21-24.el7.x86_64.rpm
2、重啟iptables服務
sudo service iptables restart
3、直接在終端命令行輸入如下命令,禁用外來的ICMP timestamp和禁止Traceroute探測
sudo iptables -A INPUT -p ICMP --icmp-type timestamp-request -j DROP
sudo iptables -A INPUT -p ICMP --icmp-type timestamp-reply -j DROP
sudo iptables -A INPUT -p ICMP --icmp-type time-exceeded -j DROP
sudo iptables -A OUTPUT -p ICMP --icmp-type time-exceeded -j DROP
4、執行命令對修改過的規則進行保存,使其永久生效
sudo service iptables save
5、檢查新添加的規則是否生效
sudo iptables -L -n
生效的話會顯示添加下面幾條規則,13,14是ICMP timestamp 請求響應漏洞的規則,11是解決允許Traceroute探測的
DROP icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 13
DROP icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 14
DROP icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 11
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
DROP icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 11
備注:
修改過的規則保存在/etc/sysconfig/iptables文件下
# Generated by iptables-save v1.4.21 on Wed Jan 26 16:31:39 2022
*filter
:INPUT ACCEPT [76:7013]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [35:5448]
-A INPUT -p icmp -m icmp --icmp-type 13 -j DROP
-A INPUT -p icmp -m icmp --icmp-type 14 -j DROP
-A INPUT -p icmp -m icmp --icmp-type 11 -j DROP
-A OUTPUT -p icmp -m icmp --icmp-type 11 -j DROP
COMMIT
# Completed on Wed Jan 26 16:31:39 2022