Linux配置防火墙

CentOS 6

方法一:命令行

  • 使用命令行,允许80端口TCP流量,立即生效

    # iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    
  • 保存

    # /etc/rc.d/init.d/iptables save
    

方法二:配置文件

  • 编辑配置文件,允许80端口TCP流量

    # vim /etc/sysconfig/iptables
    -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    
    • 重新加载配置生效
    # /etc/init.d/iptables reload
    

注:iptables执行顺序为自上向下,匹配后即离开

CentOS 7

  • 允许80端口TCP流量

    # firewall-cmd --add-port=443/tcp --permanent
    
  • 允许来自主机10.0.0.0/24的所有IPv4流量

    # firewall-cmd --add-rich-rule 'rule family="ipv4" source address="10.0.0.0/24" accept' --permanent
    
  • 重新加载配置生效

    # firewall-cmd --reload
    

你可能感兴趣的:(Linux配置防火墙)