• RHCE之路防火墙,iptables


    第十二天

    iptables

    [root@localhost ~]# mount /dev/sr0 /mnt

    [root@localhost ~]# systemctl stop firewalld

    [root@localhost ~]# yum install iptables-services.x86_64 -y

    [root@localhost ~]# systemctl restart iptables.service
    [root@localhost ~]# iptables -L

    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
    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

    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination

    [root@localhost ~]# iptables -F --- 将默认的数据清空
    [root@localhost ~]# iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         

    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         

    Chain OUTPUT (policy ACCEPT)
    target     prot opt source

    [root@localhost ~]# iptables -t filter -A INPUT -p tcp --dport 22 -s 192.168.10.0/24 -d 192.168.10.129 -j REJECT

    过滤操作,在INPUT里,协议类型为tcp,目标端口为22,源ip网段为10/24,目的ip为192.168.10.129,做拒绝操作

    以下在vm图形界面操作

    [root@localhost ~]# iptables -nL
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    REJECT     tcp  --  192.168.10.0/24      192.168.10.129       tcp dpt:22 reject-with icmp-port-unreachable

    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         

    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination   

    [root@localhost ~]# iptables -t filter -I INPUT -p tcp --dport 22 -j ACCEPT --- 做允许操作

    [root@localhost ~]# iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SsH

    [root@localhost ~]# iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 3 --name SsH -j DROP

    在60秒内最多进行3个会话

    [root@localhost ~]# iptables --line-numbers -nL -- 查看已有的规则编号
    Chain INPUT (policy ACCEPT)
    num  target     prot opt source               destination         
    1               tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:22 state NEW recent: SET name: SsH side: source mask: 255.255.255.255
    2    REJECT     tcp  --  192.168.10.0/24      192.168.10.129       tcp dpt:22 reject-with icmp-port-unreachable

    Chain FORWARD (policy ACCEPT)
    num  target     prot opt source               destination         

    Chain OUTPUT (policy ACCEPT)
    num  target     prot opt source               destination         

    Chain L (0 references)
    num  target     prot opt source               destination         
    [root@localhost ~]# iptables -D INPUT 2 --- 删除INPUT里编号为2的规则

    [root@localhost ~]# iptables -I INPUT -p icmp --icmp-type 8 -j REJECT --- 禁用ping命令

    注:以上的iptables的操作均为临时修改

    [root@localhost ~]# systemctl restart iptables.service 后配置全都清空

    四表五链

  • 相关阅读:
    【JavaScript】写程序编程基础入门
    OpenHarmony源码(十):编译子系统
    自动化测试:yaml结合ddt实现数据驱动!
    【云原生】容器编排工具Kubernetes
    二维数组前缀和(JAVA)
    为了沙漠中的奋进者:“视人为人”的陕煤曹家滩 智慧矿区
    操作系统——进程间通信——共享内存、消息队列、信号量
    磁盘的工作方式
    C++ Reference: Standard C++ Library reference: C Library: cwchar: vfwscanf
    「Python循环结构」阿凡提拿工资
  • 原文地址:https://blog.csdn.net/qq_39744805/article/details/127755862