zoukankan      html  css  js  c++  java
  • RedHat linux服务器对外开放指定端口

    为了能够远程访问这台机器上的MySQL,需要开放3306端口:

    [root@localhost ~]# service iptables status
    Redirecting to /bin/systemctl status  iptables.service
    Unit iptables.service could not be found.

    安装 iptables-services:

    yum install iptables-services

    启动  iptables:

    service iptables start

    编辑配置文件,将3306端口添加到22端口下:

    vi /etc/sysconfig/iptables

    # sample configuration for iptables service
    # you can edit this manually or use system-config-firewall
    # please do not ask us to add additional ports/services to this default configuration
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT

    重启:

    service iptables restart

    查看开放端口:

    [root@localhost ~]# /sbin/iptables -L -n
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:3306
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    [root@localhost ~]#

     远端就能通过telnet 测试访问了:

    telnet 192.168.1.27 3306 
  • 相关阅读:
    9ch
    thymeleaf 的使用(三)--举例使用
    thymeleaf 的使用(二)--基本语法
    thymeleaf 的使用(一)--导入和基本操作
    SpringBoot对静态资源的映射规则
    第一个Spring Boot项目
    HTML文本换行问题
    判断for(var i=0;i<=3;i++){ setTimeout(function() { console.log(i) }, 10) }
    js的执行机制——宏任务和微任务
    v-if 和 v-show 的区别
  • 原文地址:https://www.cnblogs.com/miaoying/p/11535945.html
Copyright © 2011-2022 走看看