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 
  • 相关阅读:
    js概念理解
    web性能瓶颈
    http协议
    jquery插件开发
    Razor(cshtml)
    从局域网内的其他Linux主机下载文件
    Java多线程学习笔记
    java中String s="abc"及String s=new String("abc")详解
    Object中toString方法
    DAO层,Service层,Controller层、View层、entity层
  • 原文地址:https://www.cnblogs.com/miaoying/p/11535945.html
Copyright © 2011-2022 走看看