iptables防火墙基本操作配置

iptables 防火墙练习

操作

  1. 禁ping 网关

  2. 只让srv1 ping 网关

  3. 开放dns 服务

  4. 防火墙规则备份

  5. 重启

  6. 防火墙规则还原

操作过程

开启防火墙

[root@localhost ~]# systemctl start firewalld.service
  1. 禁ping网关

    [root@localhost ~]# iptables -t filter -I INPUT -p icmp -s 0.0.0.0/0 -j REJECT
    

    禁ping前

    image-20231012171612216

    禁ping后

    image-20231012171738194

  2. 只让srv1 ping 网关

    [root@localhost ~]# iptables -t filter -I INPUT -p icmp -s 172.16.1.100 -j ACCEPT
    

    添加后

    image-20231012171908585

  3. 开放dns 服务

    此处禁用dns仅演示,实际操作时不禁用也无法解析dns

    [root@localhost ~]# iptables -t filter -I INPUT -p udp --dport 53 -j REJECT
    

    禁用dns后,无法解析

    image-20231012173302563

    删除禁用dns

    删除禁用服务
    [root@localhost ~]# iptables -nvL --line-numbers
    
    [root@localhost ~]# iptables -t filter -D INPUT 1
    

    开启dns服务

    [root@localhost ~]# iptables -t filter -I INPUT -p udp --dport 53 -j ACCEPT
    

    image-20231012173345762

  4. 防火墙规则备份

    [root@localhost ~]# iptables-save > /tmp/iprules_all.txt
    

    image-20231012173941821

  5. 重启gw

    init6
    
  6. 防火墙规则还原

    [root@localhost ~]# systemctl start firewalld.service
    
    [root@localhost ~]# iptables-restore < /tmp/iprules_all.txt 
    
    [root@localhost ~]# iptables -nvL --line-numbers
    

    image-20231012174845050

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值