title: Unable to produce to Kafka topic that is running on WSL 2 from Windows
body: <p>I am running the latest Kafka on Ubuntu WSL2 successfully. I can start zookeeper, kafka server, create topics, console produce and console consume just fine from within the Ubuntu that I have running on the WSL. However, when I go into my Intellij on Windows and create a simple Java Producer it does not seem to be able to connect to the broker</p>
  <p><strong>Versions &amp; Hostname</strong></p>
  <pre><code>    Java version: 1.8
      Kafka Version: 2.6
      hostname (from Ubuntu): KDAAPPDEV04
      hostname (from Powershell): KDAAPPDEV04
      java.net.InetAddress.getLocalHost().getHostName() = KDAAPPDEV04
      java.net.InetAddress.getLocalHost().getCanonicalHostName() = KDAAPPDEV04
      netstat from CMD:
          TCP    [::1]:9092             [::]:0                 LISTENING
  </code></pre>
  <p><strong>server.properties</strong>
  I found this settings on another SO answer but these did not work for me.</p>
  <pre><code>advertised.listeners=PLAINTEXT://127.0.0.1:9092
  listener.security.protocol.map=PLAINTEXT:PLAINTEXT
  listeners=PLAINTEXT://0.0.0.0:9092
  </code></pre>
  <p>then tried (and restarted zookeeper and kafka)</p>
  <pre><code>advertised.listeners=PLAINTEXT://KDAAPPDEV04:9092
  listener.security.protocol.map=PLAINTEXT:PLAINTEXT
  listeners=PLAINTEXT://0.0.0.0:9092
  </code></pre>
  <p><strong>Producer</strong></p>
  <p>I run this producer with three different values: hostname, localhost and 127.0.0.1 but it never connects to the broker</p>
  <pre><code>    public class ProducerDemo{
  
      private static Logger logger = LoggerFactory.getLogger(ProducerDemo.class);
  
      public static void main(String[] args) throws UnknownHostException{
  
          System.out.println(InetAddress.getLocalHost().getHostName());
          System.out.println(InetAddress.getLocalHost().getCanonicalHostName());
  
          String bootstrapServers = &quot;127.0.0.1:9092&quot;;
  //        String bootstrapServers = &quot;localhost:9092&quot;;
  //        String bootstrapServers = &quot;KDAAPPDEV04:9092&quot;;
  
          //create Producer properties
          Properties properties = new Properties();
          properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,bootstrapServers);
          properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
          properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());
  
          //create the producer
          KafkaProducer&lt;String,String&gt; producer = new KafkaProducer&lt;String, String&gt;(properties);
  
          //create a producer record
          ProducerRecord&lt;String,String&gt; record = new ProducerRecord&lt;String, String&gt;(&quot;first-topic&quot;,&quot;hola mundo&quot;);
  
          //send data
          producer.send(record);
  
          //flush + close
          producer.flush();
          producer.close();
      }
  }
  </code></pre>
  <p><strong>Error</strong></p>
  <pre><code>[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka version: 2.6.0
  [main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka commitId: 62abe01bee039651
  [main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka startTimeMs: 1601666175706
  [kafka-producer-network-thread | producer-1] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=producer-1] Connection to node -1 (KDAAPPDEV04/my-ipconfig-address-here:9092) could not be established. Broker may not be available.
  </code></pre>