iptables设置ping协议ICMP

版权声明:来自波博 https://blog.csdn.net/qq_42906907/article/details/82663915

默认策略为拒绝所有
iptables -P INPUT DROP
iptables -P OUTPUT DROP

iptables  -A INPUT -p icmp --icmp 8 -j ACCEPT  #允许请求进来
iptables -A OUTPUT  -p icmp --icmp 0 -j ACCEPT  #允许响应出去

执行完上述的命令之后,可在另外一台主机上实现对本机的ping测试
type 8为ping 命令请求信号
type 0为ping 命令响应信号

可与其他协议的使用做对比:
实例,限制sshd的22号端口

iptables  -A INPUT -s 192.168.5.0/24 -d 192.168.5.15/24 -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -s 192.168.5.15/24 -d 192.168.5.0/24 -p tcp --sport 22 -j ACCEPT

即可完成对192.168.5.15主机的防火墙限制。相关的80端口和25、53等都需要做相应的出口和入口限制放行

查询:
iptables -L –line-numbers
根据以上命令查询出来的行数删除一条记录
iptables -D OUTPUT 2

[root@agent1 ~]# iptables -L OUTPUT --line-numbers
Chain OUTPUT (policy DROP)
num  target     prot opt source               destination         
1    ACCEPT     tcp  --  anywhere             10.0.0.0/24         tcp spt:ssh 
2    ACCEPT     tcp  --  anywhere             10.0.0.0/24         tcp spt:ssh 
[root@agent1 ~]# iptables -D OUTPUT 2

完成之后保存

service  iptables save

猜你喜欢

转载自blog.csdn.net/qq_42906907/article/details/82663915