• Linux Centos7配置防火墙开启端口


    在使用centos7安装完mysql、tomcat、nginx后,都需要配置防火墙才能正常访问。

    下面系统的学习一下防火墙的配置。

    centos7默认使用firewall,需要关闭,然后使用iptable

    一、关闭firewall

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

    二、安装iptable iptable-service

      #先检查是否安装了iptables
      service iptables status
      #安装iptables
      yum install -y iptables
      #升级iptables(安装的最新版本则不需要)
      yum update iptables 
      #安装iptables-services
      yum install iptables-services

    三、设置现有规则

      #查看iptables现有规则

      iptables -L -n

      #先允许所有,不然有可能会杯具

      iptables -P INPUT ACCEPT

      #清空所有默认规则

      iptables -F

      #清空所有自定义规则

      iptables -X

      #所有计数器归0

      iptables -Z

      #允许来自于lo接口的数据包(本地访问)

      iptables -A INPUT -i lo -j ACCEPT

      #开放22端口

      iptables -A INPUT -p tcp --dport 22 -j ACCEPT

      #开放21端口(FTP)

      iptables -A INPUT -p tcp --dport 21 -j ACCEPT

      #开放80端口(HTTP)

      iptables -A INPUT -p tcp --dport 80 -j ACCEPT

      #开放443端口(HTTPS)

      iptables -A INPUT -p tcp --dport 443 -j ACCEPT

      #允许ping

      iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT

      #允许接受本机请求之后的返回数据 RELATED,是为FTP设置的

      iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT

      #其他入站一律丢弃

      iptables -P INPUT DROP

      #所有出站一律绿灯

      iptables -P OUTPUT ACCEPT

      #所有转发一律丢弃

      iptables -P FORWARD DROP

    四、其他规则

      #如果要添加内网ip信任(接受其所有TCP请求)

      iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT

      #过滤所有非以上规则的请求

      iptables -P INPUT DROP

      #要封停一个IP,使用下面这条命令:

      iptables -I INPUT -s ***.***.***.*** -j DROP

      #要解封一个IP,使用下面这条命令:

      iptables -D INPUT -s ***.***.***.*** -j DROP

    五、保存规则

      #保存上述规则

      service iptables save

    六、开启iptables服务

      #注册iptables服务

      #相当于以前的chkconfig iptables on

      systemctl enable iptables.service

      #开启服务

      systemctl start iptables.service

      #查看状态

      systemctl status iptables.service

    七、映射端口(如将mysql默认的3306端口映射成1306对外提供服务)

      iptables -t mangle -I PREROUTING -p tcp --dport 1306 -j MARK --set-mark 883306 
      iptables -t nat -I PREROUTING -p tcp --dport 1306 -j REDIRECT --to-ports 3306 
    i  ptables -I INPUT -p tcp --dport 3306 -m mark --mark 883306 -j ACCEPT

  • 相关阅读:
    vue学习03 v-html
    [spring guides]网关入门
    记一次公司mssql server密码频繁被改的事件
    重构 maixpy 的 board_info + config.json 从而自适应硬件版型。
    介绍 MaixUI 系列(一)如何食用?
    (旧文)在 micropython / esp-at / arduino 中实现 软串口(software-serial) 的参考
    以优化 MaixPy 的启动速度为例,说说 K210 的双核使用及原子操作。
    我是如何在 Win + VSCode 上开发 Keil for GD32 实现 I2C 从机的游戏机手柄。
    为 MaixPy 加入软 SPI 接口(移植 MicroPython 的 SPI)
    为 MaixPy 加入软 I2C 接口(移植 MicroPython 的 I2C)
  • 原文地址:https://www.cnblogs.com/chenkeyu/p/7998104.html
Copyright © 2020-2023  润新知