阿里云服务器遇到80端口能访问,而添加的8890、88901等端口不能访问的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wm9028/article/details/83753994

阿里云服务器遇到80端口能访问,而添加的8890、88901等端口不能访问的问题

以linux服务器为例,解决思路如下,其他服务器检查流程一致

  1. 确定本地是否可以访问

    curl http://127.0.0.1:8890
    

    output:

    hello<网页的内容>
    

    说明是正常的
    检查是否开启8890端口

    netstat -an | grep 8890
    
    

    output

    tcp        0      0 0.0.0.0:8890            0.0.0.0:*               LISTEN  
    
  2. 检查防火墙是否关闭
    ubuntu:

    sudo ufw status
    

    output:

    Status: inactive //关闭
    Status: active//开启
    

    centos

    $firewall-cmd --state
    
    not running
    
  3. 检查iptables规则
    查看所有规则

    iptables -L
    

    清楚所有规则

    扫描二维码关注公众号,回复: 5576243 查看本文章
    iptables -F
    
  4. 查看阿里云的安全网组的设置

到此踩坑完毕!

如果开启的防火墙,那就把添加的端口加到iptables规则里面

添加iptables规则

centos

  1. 使用命令增加:
    首先用命令增加规则:

    iptables  -A INPUT -p tcp -m state --state NEW -m tcp --dport 82 -j ACCEPT
    

    上面的命令即时生效,但是重启iptables服务后就消失了。如何永久生效呢?

    [root@localhost ~]# service iptables save
    iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
    

    然后看下配置文件里,是有的。以后重启iptables服务,或者重启系统这条规则都会生效。

    [root@localhost ~]# cat /etc/sysconfig/iptables | grep 82
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 82 -j ACCEPT
    
  2. 直接编辑iptables配置文件

    vim /etc/sysconfig/iptables
    

    将上面的语句-A INPUT -p tcp -m state --state NEW -m tcp --dport 82 -j ACCEPT直接插入到上述文件中。
    这时候规则是不生效的,需要重启服务service iptables restart。之后这条规则就永久生效了。

猜你喜欢

转载自blog.csdn.net/wm9028/article/details/83753994