title: Cannot get Mosquitto to Allow Connection from Outside Local Network
body: <p>I have Linux Ubuntu 18.04 laptop, and I installed the Mosquitto MQTT broker there. On my Windows 10 laptop, I am running a C# application written in Visual Studio 2013 that uses the M2Mqtt Libraries.</p>
  
  <p>If I connect via the localhost, everything is fine. I start up the Mosquitto server, connect via the C# application, subscribe to a topic, and then can send messages back and forth all day long.</p>
  
  <p>But when I try to connect through the internet address, I consistently get a uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException: 
  "No connection could be made because the target machine actively 
  refused it 95.XXX.XXX.134:1883" error. (The address there is what I got via "WhatsmyIP")</p>
  
  <p>Here's what I have done so far:</p>
  
  <p>First, I went to my router, which is a TP-LINK AC1200. I set the port to forward to the local IP address of the Linux box.</p>
  
  <p><a href="https://i.stack.imgur.com/6RXMC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6RXMC.png" alt="TPLINK Screenshot"></a></p>
  
  <p>Then I went to my Linux box and used ufw to enable port 1833 and enable the firewall</p>
  
  <p><a href="https://i.stack.imgur.com/1XvnT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1XvnT.png" alt="Linux Screenshot"></a></p>
  
  <p>From there I have tried everything I can think of -- I've run Mosquitto with the port declared at the command line, I have changed the conf file to say: </p>
  
  <p>Listener 1883 0.0.0.0</p>
  
  <p>and </p>
  
  <p>Listener 1883 192.168.0.144</p>
  
  <p>I have removed the port assignment and listener assignment entirely (since that is its default anyway) and always I get the same result. </p>
  
  <p>I downloaded 2 different utilities -- one on an android phone and one is an app available from Windows store, and I cannot connect with either of them, either. The Android phone simply will not connect (it is not on the same network so localhost is not an option) and the other app will connect locally, but not when I change to the internet address. </p>
  
  <p>I get the sense I'm just missing one small thing, but I can't figure out what it is. There are other stackoverflow questions that show the same error, but they don't help me. </p>
  
  <p>If it matters, the actual C# code that is being run is:</p>
  
  <pre><code>try 
             {
                  System.Security.Cryptography.X509Certificates.X509Certificate caCert = null;
                  Boolean useSecureProtocol = false;
                  int OpenPort = 1883;
                  // external IP address
                  String PublicIPAddress = "95.XXX.XXX.134";
                  // local IP address
                  String LocalIPAddress = "192.168.0.144";
  
                  System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(PublicIPAddress);
                  client = new MqttClient(ipaddress, OpenPort, useSecureProtocol, caCert, MqttSslProtocols.TLSv1_0); 
  // certificate and Protocol are irrelevant because security set to false??
              }
              catch (System.Net.Sockets.SocketException SException )
              {
                  string SEX = SException.Message;
              }
  
  * * * 
  
              try
              {
                  Byte retVal = client.Connect(ClientId);
              }
              catch (uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException ex)
              {
                  string m = ex.Message;
              }
  </code></pre>
  
  <p>Config File: conf.d (which I run explicitly with the -C option)</p>
  
  <pre><code># Place your local configuration in /etc/mosquitto/conf.d/
  #
  # A full description of the configuration file is at
  # /usr/share/doc/mosquitto/examples/mosquitto.conf.example
  #
  
  
  pid_file /var/run/mosquitto.pid
  
  persistence true
  persistence_location /var/lib/mosquitto/
  
  log_dest file /home/mark_admin/mosquitto.log
  
  include_dir /etc/mosquitto/conf.d
  </code></pre>
  
  <p>As I said, I have changed it and tried many things:</p>
  
  <p>Listener 1883 192.168.0.144
  Listener 1883 0.0.0.0
  Listener 1883 </p>
  
  <p>And none of the above. Just left it blank. None of them worked.</p>