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