iptables设置ping协议ICMP

默认策略为拒绝所有
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lebron_zhb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值