在iptables中, 想要 A 主机 可以ping B 主机 可以如下设置:
[root@localhost ~]# iptables -A INPUT -s IP(B主机) -d IP(A主机) -p icmp --icmp-type 0 -j ACCEPT
[root@localhost ~]# iptables -A OUTPUT -s IP(A主机) -d IP(B主机) -p icmp --icmp-type 8 -j ACCEPT
上述第一行命令的意思是: -A INPUT 表明ping回应的数据是从网卡进入的 ;-s IP(B主机)来源于B 主机 ;-d IP(A主机) 目的是A主机 ;-p icmp --icmp-type 0: ping回应标志;
第二条命令是:-A OUTPUT 表明ping请求数据是从网卡出去的; -s IP(A主机) 来源于A主机;-d IP(B主机)目的是B主机; -p icmp --icmp-type 8 是A 主机的ping请求