zoukankan      html  css  js  c++  java
  • 解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory.

    CentOS7中执行
    1. service iptables start/stop  
    service iptables start/stop

    会报错Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.

    在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理,

    如果要添加范围例外端口 如 1000-2000
    语法命令如下:启用区域端口和协议组合
    firewall-cmd [–zone=<zone>] –add-port=<port>[-<port>]/<protocol> [–timeout=<seconds>]
    此举将启用端口和协议的组合。端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port> 。协议可以是 tcp 或 udp。
    实际命令如下:

    添加

    firewall-cmd –zone=public –add-port=80/tcp –permanent (–permanent永久生效,没有此参数重启后失效)

    firewall-cmd –zone=public –add-port=1000-2000/tcp –permanent 

    重新载入
    firewall-cmd –reload
    查看
    firewall-cmd –zone= public –query-port=80/tcp
    删除
    firewall-cmd –zone= public –remove-port=80/tcp –permanent


    当然你可以还原传统的管理方式。

    执行一下命令:

    1. systemctl stop firewalld  
    2. systemctl mask firewalld  
    systemctl stop firewalld
    systemctl mask firewalld

    并且安装iptables-services:

    1. yum install iptables-services  
    yum install iptables-services

    设置开机启动:

    1. systemctl enable iptables  
    systemctl enable iptables

    1. systemctl stop iptables  
    2. systemctl start iptables  
    3. systemctl restart iptables  
    4. systemctl reload iptables  
    systemctl stop iptables
    systemctl start iptables
    systemctl restart iptables
    systemctl reload iptables

    保存设置:

    1. service iptables save  
    service iptables save

    OK,再试一下应该就好使了


    开放某个端口 在/etc/sysconfig/iptables里添加

    -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT


    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    基于范围的for循环
    ML.NET技术研究系列-2聚类算法KMeans
    SQLServer常用运维SQL整理
    ML.NET技术研究系列-1入门篇
    Kafka基本知识整理
    .NetCore技术研究-EntityFramework Core 3.0 Preview
    容器技术研究-Kubernetes基本概念
    特来电混沌工程实践-混沌事件注入
    .Net Core技术研究-Span<T>和ValueTuple<T>
    Visual Studio Git本地Repos和GitHub远程Repos互操作
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10326929.html
Copyright © 2011-2022 走看看