zoukankan      html  css  js  c++  java
  • 关于linux防火墙

      1.防火墙是什么:防火墙就是用于实现Linux下访问控制的功能的,它分为硬件的或者软件的防火墙两种。无论是在哪个网络中,防火墙工作的地方一定是在网络的边缘。而我们的任务就是需要去定义到底防火墙如何工作,这就是防火墙的策略,规则,以达到让它对出入网络的IP、数据进行检测。现在比较常见的防火墙一般是网络层的防火墙,它会在这层对源地址和目标地址进行检测。

      2.防火墙的原理:防火墙策略一般分为两种,一种叫“通”策略,一种叫“堵”策略。通策略,默认门是关着的,必须要定义谁能进。堵策略则是,大门是洞开的,但是你必须有身份认证,否则不能进。所以我们要定义,让进来的进来,让出去的出去,所以通,是要全通,而堵,则是要选择。

      3.主要说以下centos7防火墙的关闭及打开

    centos7采用的是iptables防火墙,CentOS 7.2关闭防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。

    firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

    [root@iz2ze1kx4vh0ixw2gnivtsz ~]# firewall-cmd --state
    running
    

       检查防火墙的状态:

    从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig。

    [root@iz2ze1kx4vh0ixw2gnivtsz ~]# systemctl list-unit-files|grep firewalld.service    
    firewalld.service                             enabled    --防火墙处于打开状态
    

      或者

    [root@iz2ze1kx4vh0ixw2gnivtsz ~]# systemctl status firewalld.service
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2018-05-03 17:58:41 CST; 53min ago      --running为开启状态以及时间
         Docs: man:firewalld(1)
     Main PID: 478 (firewalld)
       CGroup: /system.slice/firewalld.service
               └─478 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
    
    May 03 17:58:40 iz2ze1kx4vh0ixw2gnivtsz systemd[1]: Starting firewalld - dynamic firewall daemon...
    May 03 17:58:41 iz2ze1kx4vh0ixw2gnivtsz systemd[1]: Started firewalld - dynamic firewall daemon.

       关闭防火墙:

    systemctl stop firewalld.service #停止firewall
    systemctl disable firewalld.service #禁止firewall开机启动

     其他命令

    启动一个服务:systemctl start firewalld.service
    关闭一个服务:systemctl stop firewalld.service
    重启一个服务:systemctl restart firewalld.service
    显示一个服务的状态:systemctl status firewalld.service
    在开机时启用一个服务:systemctl enable firewalld.service
    在开机时禁用一个服务:systemctl disable firewalld.service
    查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?
    查看已启动的服务列表:systemctl list-unit-files|grep enabled
    

    Centos 7 firewall 命令:

    查看已经开放的端口:

    firewall-cmd --list-ports

    开启端口

    firewall-cmd --zone=public --add-port=80/tcp --permanent

      命令含义:

      –zone #作用域

      –add-port=80/tcp #添加端口,格式为:端口/通讯协议

      –permanent #永久生效,没有此参数重启后失效

    重启防火墙

    firewall-cmd --reload #重启firewall
    systemctl stop firewalld.service #停止firewall
    systemctl disable firewalld.service #禁止firewall开机启动
    firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)


    注意:如果请求服务器无响应,且ip能ping通的话,就需要检查该服务器的端口是否开启

    [root@iz2ze1kx4vh0ixw2gnivtsz ~]# firewall-cmd --list-ports
    3306/tcp 8080/tcp

      --这个就是我开启了3306和8080端口

  • 相关阅读:
    [LeetCode] Search a 2D Matrix
    [LeetCode] Merge Sorted Array
    [LeetCode] Remove Duplicates from Sorted Array
    [LeetCode] Convert Sorted Array to Binary Search Tree
    [LeetCode] Remove Element
    [LeetCode] Search Insert Position
    [LeetCode] Remove Duplicates from Sorted List
    [LeetCode] Merge Two Sorted Lists
    [LeetCode] Best Time to Buy and Sell Stock II
    [LeetCode] Reverse Integer
  • 原文地址:https://www.cnblogs.com/chen1carpolite/p/8987011.html
Copyright © 2011-2022 走看看