赞
踩
目录
(1)从filter表的INPUT链,添加一条匹配规则:拒绝icmp访问
(2)从filter表的INPUT链中删除指定匹配的规则,添加丢弃规则
(4)只指定链而不指定表添加规则,默认添加到filter表中
按照匹配条件进行分类
使用yum -y install iptables-services命令安装iptables管理工具
使用systemctl start iptables命令启动iptables服务
在INPUT后面加上编号,表示将该规则添加链中的到第几行
- [root@localhost ~]# iptables -t filter -I INPUT -p icmp -j REJECT
-
- [root@localhost ~]# iptables -t filter -I INPUT 3 -p icmp -j REJECT
- [root@localhost ~]# iptables -t filter -D INPUT -p icmp -j REJECT
-
- [root@localhost ~]# iptables -t filter -I INPUT -p icmp -j DROP
删除默认表中INPUT链的第几行规则
[root@localhost ~]# iptables -D INPUT 3
清空默认表
[root@localhost ~]# iptables -F
清空指定表
[root@localhost ~]# iptables -F -t nat
- [root@localhost ~]# iptables -L INPUT
- Chain INPUT (policy ACCEPT)
- target prot opt source destination
- ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
- REJECT icmp -- anywhere anywhere reject-with icmp-port-unreachable
- ACCEPT icmp -- anywhere anywhere
- ACCEPT all -- anywhere anywhere
- ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
- REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
列出指定链中的规则,并显示行号
- [root@localhost ~]# iptables -L INPUT --line-numbers
- Chain INPUT (policy ACCEPT)
- num target prot opt source destination
- 1 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
- 2 REJECT icmp -- anywhere anywhere reject-with icmp-port-unreachable
- 3 ACCEPT icmp -- anywhere anywhere
- 4 ACCEPT all -- anywhere anywhere
- 5 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
- 6 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
列出指定链中的规则,将source以数字形式显示
- [root@localhost ~]# iptables -nL INPUT
- Chain INPUT (policy ACCEPT)
- target prot opt source destination
- ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
- REJECT icmp -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
- ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
- ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
- ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
- REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
[root@localhost ~]# iptables -I INPUT -p icmp -j REJECT
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。