Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to establish a connection between my client and raspbian. Within my network, I can connect to my service at any time without any problems. Now I want to connect to my service via the internet. This is unfortunately not working when I try to use my internet ip for the connection.

client = new MqttClient("tcp://77.777.77.77:1883", "SendingdLoop");

My Java-Application tells me that the connection has been refused (so there is no timeout):

   Could not establish connection (32103) - java.net.ConnectException: Connection **refused**: connect          at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:75)
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:538)
        at java.lang.Thread.run(Thread.java:722)
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
        at java.net.Socket.connect(Socket.java:579)
        at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:66)

I followed the official instructions to open the port: https://wiki.debian.org/iptables

my entry looks like this:

 -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT

When I check iptables,

iptables -L
 ACCEPT tcp -- anywhere anywhere  tcp dpt: 1883

I can see the rule is active.

Is there anything else I have to configure?

share|improve this question
Is the IP correct? 77.777.77.77 – Laurent C. Mar 31 '14 at 12:28
thats just for the post...Like I said - the connection is refused, no timeout. – Goot Mar 31 '14 at 12:31
up vote 2 down vote accepted

"Is there anything else I have to configure?"

Your router, perhaps. You really have not provided enough information to provide a definitive answer, all you've done is point out is not because of iptables...perhaps.

Iptables rules are processed in order. If that was the last rule appended (-A) and is last in the list when you look at iptables -L, then it can be superseded by a preceding rule. E.g., if the list looks like:

DROP everything
ACCEPT everything 

Nothing will be accepted because everthing will be dropped before the second rule is processed (more exactly, the second rule will never be processed because everything will find a match in the first rule).

share|improve this answer
my router forwarded the connection from 1883 to 80 so your answer is correct. thanks... – Goot Mar 31 '14 at 13:05

I had the same problem with mqtt broker called vernemq, but solved it by adding the following.

  1. $ sudo vmq-admin listener show

    To show the list o allowed IP's and ports for vernemq

  2. $ sudo vmq-admin listener start port=1885 -a --mountpoint /appname --nr_of_acceptors=10 --max_connections=20000

    To add any IP and your new port. Now you should be able to connect without any problem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.