JavaEar 专注于收集分享传播有价值的技术资料

Apache Kafka - DNS resolution failed for url in bootstrap.servers (Failed to construct kafka producer)

I have a problem to construct kafka producer with hostname. Here's what I did.

1) I set the, port config to



2) I add the host ip and alias name to /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

3) set up a firewall using iptables

-A INPUT -p tcp -m tcp --dport 3888 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2888 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2181 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 9092 -j ACCEPT

4) I construct the producer with below configuration. I set the "hostname:port" instead of "ip:port".

  props = new Properties();

**props.put("bootstrap.servers", "");
  props.put("acks", "0");
  props.put("retries", "0");

Exception occurred while running the producer. Here's the error log. I don't understand why fail to construct kafka producer. please check it. :)

Exception in thread "main" org.apache.kafka.common.KafkaException: **Failed to construct kafka producer**
at org.apache.kafka.clients.producer.KafkaProducer.<init>(
at org.apache.kafka.clients.producer.KafkaProducer.<init>(
at com.lgcns.sep.kafka.producer.MessageSender.createProducer(
at com.lgcns.sep.kafka.producer.MessageSender.getInstance(
at com.lgcns.jartest.producerTest.main(

Caused by: org.apache.kafka.common.config.ConfigException: **DNS resolution failed for url in bootstrap.servers**:
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(
at org.apache.kafka.clients.producer.KafkaProducer.<init>(
... 4 more


  1. i am using 2 vms. 1vm having kafka client java program. 2nd vm having all kafka setups. in file of vm2 add property "", add this as a bootstrap.server value in kafka client program which is in vm1.

    And you should start vm2 from vm1 terminal only other wise you will get that error. i also got same.