Linux防火墙主要使用iptables命令进行配置和管理。以下是一些常用的Linux防火墙命令:

  1. 显示防火墙规则:

    iptables -L
    
  2. 清除所有防火墙规则:

    iptables -F
    
  3. 允许某个IP地址访问特定端口:

    iptables -A INPUT -s <IP地址> -p <协议> --dport <端口号> -j ACCEPT
    
  4. 允许某个IP地址范围访问特定端口:

    iptables -A INPUT -m iprange --src-range <起始IP地址>-<结束IP地址> -p <协议> --dport <端口号> -j ACCEPT
    
  5. 允许某个IP地址访问所有端口:

    iptables -A INPUT -s <IP地址> -j ACCEPT
    
  6. 拒绝某个IP地址访问特定端口:

    iptables -A INPUT -s <IP地址> -p <协议> --dport <端口号> -j DROP
    
  7. 拒绝某个IP地址范围访问特定端口:

    iptables -A INPUT -m iprange --src-range <起始IP地址>-<结束IP地址> -p <协议> --dport <端口号> -j DROP
    
  8. 允许某个端口的所有连接:

    iptables -A INPUT -p <协议> --dport <端口号> -j ACCEPT
    
  9. 允许某个范围的端口的所有连接:

    iptables -A INPUT -p <协议> --dport <起始端口号>:<结束端口号> -j ACCEPT
    
  10. 允许特定IP地址的所有连接通过:

    iptables -A INPUT -s <IP地址> -j ACCEPT
    
  11. 允许特定IP地址范围的所有连接通过:

    iptables -A INPUT -m iprange --src-range <起始IP地址>-<结束IP地址> -j ACCEPT
    
  12. 拒绝所有连接:

    iptables -P INPUT DROP
    
  13. 允许所有连接:

    iptables -P INPUT ACCEPT
    

请注意,这些命令仅在当前会话中生效,如果希望永久保存防火墙规则,需要将规则保存到防火墙配置文件中。具体的保存方法可能因Linux发行版的不同而有所不同

linux 防火墙命令

原文地址: https://www.cveoy.top/t/topic/h5sC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录