Error: Connection to Node -1 could not be established

If you are encountering the error "connection to node -1 (localhost/ could not be established. broker may not be available." in your Kafka setup, here are some steps to resolve it:

  1. Check Kafka Broker Status: Ensure that your Kafka broker is running and reachable. You can use the following command to check the status:
./bin/ config/
  1. Verify Broker Configuration: Double-check your Kafka broker configuration. Ensure that the advertised listeners are correctly configured. You can find this in your `` file:
  1. Check Network and Firewall Settings: Make sure there are no network issues or firewall restrictions preventing connections to the broker. Ensure that the specified hostname or IP address (localhost/ in your case) is correct and accessible.
  1. Restart Kafka and Zookeeper: Sometimes, restarting Kafka and Zookeeper can resolve connection issues. Stop both services and then start them again:
./bin/ config/
./bin/ config/

If the issue persists after trying these steps, consider checking Kafka logs for more detailed error messages that might provide insights into the problem.

To obtain the external interface IP on Ubuntu terminal, you can use the command:

ip addr | grep eth0

Once you have the IP, set it as the advertised.listener. Then, on Windows cmd, execute the following command to forward ports:

netsh interface portproxy add v4tov4 listenport=9092 listenaddress= connectport=9092 connectaddress=XXX.XX.XX.XX

Replace XXX.XX.XX.XX with the external interface IP. After executing this command, you can verify the setup using:

netstat -ab

This will display the IP and Port TCP as, confirming that the port forwarding is functioning correctly.

I encountered a similar issue where everything appeared to be functioning correctly, yet an error persisted. Upon reviewing my changes related to the Kafka initial setup, I identified the following steps to resolve the issue:

  1. Ensure that your JDK is installed correctly. In my case, the issue stemmed from an incorrect JDK path or JAVA_HOME path specified in my environment variables. This misconfiguration prevented the client from detecting the broker, even though it was started. If necessary, reinstall the JDK correctly to prevent this issue from occurring.
  2. If the problem persists despite the JDK verification, consider adjusting the broker configuration. Change the listener configuration from:
    to either:
    Note: If your broker starts but issues persist, you may observe dumps being created in your kafka\bin\windows directory.