iptables 生效_iptables详解-2

[root@wwww ~]# iptables -nvL

1a6b70b9c1cf427f935f74e6316d326b.png

pkts bytes target prot opt in out source destination

27(包的数量) 1368(包的大小) REJECT(拒绝) tcp(指定tcp) -- * * 192.168.0.105(来源ip) 0.0.0.0/0 (目标ip) tcp dpt:80(到80端口) reject(最终的行为为拒绝)-with icmp-port-unreachable

DROP(扔掉连管都不管) REJECT(杰克)(拿包过来看一下再拒绝) ACCEPT(饿多涉)(接受)

如果前面匹配到了,后面的匹配的就不管了。

越往上的规则越先生效。

[root@wwww ~]# iptables -Z //清除访问数据

[root@wwww ~]# iptables -nvL //都变0了

fc36e2680eccc552b741063ff7b78ef1.png

[root@wwww ~]# iptables -F //清除所有的规则

[root@wwww ~]# iptables -nvL

d73f4f35870643cc6fb7ec668dda3de0.png

添加规则 删除规则 清除规则 清除访问数据包 都是默认filterb表

如果要操作别的表 就指定-t 表名

如果加指定的端口 必须需要加tcp ucp协议 才能行

重要:如果添加了规则,那么要保存一下规则,如果不保存下次重启服务器,还是重启防火墙,规则就会自动清空。

[root@wwww ~]# service iptables restart //重启防火墙测试

[root@wwww ~]# iptables -nvL //在查看规则 回到之前刚刚起的规则

c79891310ebd5a690fe008a55e8edc64.png

[root@wwww ~]# iptables -F

[root@wwww ~]# iptables -I INPUT -p tcp --dport 80 -j DROP

[root@wwww ~]# service iptables save //保存规则到这个文件里面来

4a66f441a7244b4d754370cae677704f.png

[root@wwww ~]# cat /etc/sysconfig/iptables //就能查看到规则被保存到里面去

093fd085fb79c9d483fdbeb0f118a9fd.png

[root@wwww ~]# service iptables restart //重启测试

[root@wwww ~]# iptables -nvL //查看规则 已经保存了

547c5706aa574238c290412359e1d90c.png

[root@wwww ~]# iptables-save > 1.ipt //把规则重定向给文件 这叫备份

[root@wwww ~]# iptables -F //清空一下

[root@wwww ~]# iptables-restore < 1.ipt //恢复规则

[root@wwww ~]# iptables -nvL //有默认的防火墙规则

7eb70dda7f5e508194b065eea3a86042.png

pkts bytes

(大小) (字节)

iptables -Z (清除大小和字节) -F(删除所有的规则)

service iptables restart (重启防火墙)

ACCEPT(接收)

service iptables save 将防火墙规则保存到 /etc/sysconfig/iptables

iptables-save > 1.ipt 保存到指定的文件里去

iptables-restore < 1.ipt 还原规则

[root@tufei ~]# iptables -F (清空所有规则)

[root@tufei ~]# service iptables save

删除规则 再保存

总结:可以把防火墙的规则保存起来,下次重启也会自动生成,也可以重定向到一个文件里面,使用这个文件来恢复。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值