0
votes

I'm trying to use Consul to do service discovery from a Java application running on a default Debian server using spotify's dnsjava

I know Consul DNS listens on port 8600 for queries (https://www.consul.io/docs/agent/dns.html).

However DNS listens on port 53 by default, so queries need to be forwarded to Consul. I did this forwarding using IPTables - but I don't know if this is the right approach. It does work however using dig, but I don't know what the side effects might be. Being a application developer, I don't necessarily have access to update iptables and install additional packages

I have a service I call bapi

sudo apt-get install dnsutils

sudo iptables -t nat -A PREROUTING -p udp -m udp --dport 53 -j REDIRECT --to-ports 8600

sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 8600

sudo iptables -t nat -A OUTPUT -d localhost -p udp -m udp --dport 53 -j REDIRECT --to-ports 8600

sudo iptables -t nat -A OUTPUT -d localhost -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 8600

dig @127.0.0.1 -p 8600 bapi.service.consul. SRV

dig @127.0.0.1 -p 8600 bapi-stub-node.node.consul. ANY

dig @127.0.0.1 -p 53 bapi.service.consul. SRV

dig @127.0.0.1 -p 53 bapi-stub-node.node.consul. ANY

This application attempts to lookup DNS from a Java Application, but it doesn't work, I don't know why

https://github.com/tonymurphy/srv-discovery

I know Spring has consul integration and service discovery, but I don't want all the baggage that comes with it, and it does seem to use http api to do service lookups

1

1 Answers

1
votes

There are 2 approaches:

  1. Use port forwarding like ip tables (that u used), dnsmasq, etc.. For example, installing dnsmasq using your debian package manager will be: apt-get install dnsmasq and then: echo "server=/consul/127.0.0.1#8600" > /etc/dnsmasq.d/10-consul

  2. Make consul listen on port 53 by using the port.dns config (https://www.consul.io/docs/agent/options.html)

I prefer to do port forwarding since listening on low ports requires root permissions, and giving consul root permission might not be a good idea. On the other hand installing dnsmasq or other solution is just another dependency to your system.

Anyway, you must choose between them, and you need root permission for both approaches (ask your system administrators to support you).

You can read all about it here: https://www.consul.io/docs/guides/forwarding.html