zoukankan      html  css  js  c++  java
  • Linux CentOS 7 防火墙与端口设置操作

    CentOS升级到7之后用firewall代替了iptables来设置Linux端口,

    下面是具体的设置方法:

    []:选填

    <>:必填

    [<zone>]:作用域(block、dmz、drop、external、home、internal、public、trusted、work)

    <port>:端口号

    [-<port>]:或者端口范围

    <protocol>:端口协议(tcp、udp)协议目前支持这四种类型

    [<seconds>]:过期时间,使用N秒后自动关闭(秒)

    [--permanent]:永久设置,在重启后依然保证设置可用,如果不加此项,重启后端口会恢复关闭状态

    注:设置端口后要重启防火墙使其生效 firewall-cmd --complete-reload

    1、检查端口状态

    yes:已开通 

    no:未开通 

    firewall-cmd --query-port=<port>[-<port>]/<protocol>
    firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>
    firewall-cmd [--permanent] [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

    查看已开放的端口

    firewall-cmd --zone=public --list-ports

    2、启用端口

    success:执行成功

    warning:警告xxx

    firewall-cmd --add-port=<port>[-<port>]/<protocol>
    firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
    firewall-cmd [--permanent] [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>

    3、禁用端口 

    success:执行成功

    warning:警告xxx

    firewall-cmd --remove-port=<port>[-<port>]/<protocol>
    firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
    firewall-cmd [--permanent] [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

     

    4、防火墙重启

    --reload:不改变状态的条件下重启防火墙

    --complete-reload:状态信息将会丢失,当防火墙有问题时可以使用,如,状态信息和防火墙规则都正常却无法建立任何链接的情况等

    firewall-cmd --reload
    firewall-cmd --complete-reload
    例子

    6、查看防火墙状态

    命令1:firewall-cmd --state

    命令2:systemctl status firewalld

    7、查看、打开、关闭应急模式

    (应急模式阻断所有网络连接,防止出现紧急状况)

    firewall-cmd --query-panic

    firewall-cmd --panic-on

     firewall-cmd --panic-off

    8、打开、关闭、重启防火墙 

    systemctl stop firewalld
    systemctl start firewalld
    systemctl restart firewalld

     9、开启/关闭 开机自启动防火墙

    systemctl enable firewalld
    systemctl disable firewalld

    查询防火墙服务是否开机启动:
    systemctl is-enabled firewalld

    10、其他操作

    查看版本: firewall-cmd --version
    查看帮助: firewall-cmd --help
    查看区域信息:  firewall-cmd --get-active-zones
    查看指定接口所属区域: firewall-cmd --get-zone-of-interface=网卡名称
    查询已经启动的服务列表:systemctl list-unit-files|grep enabled
     

     查询启动失败的服务列表:systemctl --failed

     
     
    
    
    
    
    
    
  • 相关阅读:
    idea插件-RestfulToolkit
    java 调试技巧
    js foreach 不能中断的现象及理解
    SpringBoot 内嵌Tomcat的默认线程配置
    SpringMVC中从doDispatch如何一步步调用到controller的方法
    干掉hao123的第n+1种方法
    查找——二叉排序树(代码超详细注释)
    为什么单螺旋桨飞机会左偏?
    【转】Python 魔法方法大全
    通俗的讲解Python中的__new__()方法
  • 原文地址:https://www.cnblogs.com/brankoliu/p/10848811.html
Copyright © 2011-2022 走看看