zoukankan      html  css  js  c++  java
  • Linux下防火墙开启相关端口及查看已开启端口

    最近利用Apache Mina实现了一个http服务,发布到linux下发现无法访问,通过HttpClient来发送http请求时,报如下错误:

    Exception in thread "main" org.apache.http.conn.HttpHostConnectException: Connection to http://10.5.20.96:8011 refused
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
        at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
        at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1066)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1044)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1035)
        at com.tudou.findlabel.entrance.ClientWithResponseHandler.main(ClientWithResponseHandler.java:52)
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127)
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
        ... 8 more
    原来是因为linux下没有开启对8011的端口访问权限造成的。通过下面的命令可以开启允许对外访问的网络端口:

    步骤一:打开Linux文件:

     /etc/csf/csf.conf    
     
    修改: 

    # Allow incoming TCP ports
    TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,3690,3306,8080,8086,8088"

    # Allow outgoing TCP ports
    TCP_OUT = "20,21,22,25,53,80,110,113,443,993,995,3690,3306,8080,8086,8088"

     步骤二:
    /sbin/iptables -I INPUT -p tcp --dport 8086 -j ACCEPT #开启8086端口 
    /etc/rc.d/init.d/iptables save #保存配置 
    /etc/rc.d/init.d/iptables restart #重启服务 
     
    步骤三:
    查看端口是否已经开放
    /etc/init.d/iptables status 
    结果如下 

    步骤四:

    重启相关web服务即可!

  • 相关阅读:
    iOS去除导航栏和tabbar的横线
    各种坑
    iOS系统消息
    文件的读写
    MAC机中安装ruby环境--转载
    一句话处理服务器头像的尺寸
    开一个线程来处理 耗时的操作
    angular2中一种换肤实现方案
    一句话说明==和equals的区别
    下拉框样式在不同浏览器的简单兼容
  • 原文地址:https://www.cnblogs.com/Ivan-j2ee/p/4159981.html
Copyright © 2011-2022 走看看