Your /etc/resolv.conf needs to point to 127.0.0.1 or a local IP of the host. And dnsmasq needs to be configured with a DNS server (recursor) to forward requests to. dig, host, and most other applications (I’m looking at you, nginx) use /etc/resolv.conf to determine which DNS server to contact.
Logically, the order would go dig → /etc/resolv.conf → dnsmasq → recursor. When looking up something under the .consul domain, it would go dig → /etc/resolv.conf → dnsmasq → consul agent.
I’m also running centos 7, consul, and dnsmasq. My dnsmasq looks like:
/etc/dnsmasq.d/000-base.conf:
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
# disable negative caching
no-negcache
# read from resolv.conf generated via NetworkManager
resolv-file=/etc/resolv.conf.dnsmasq
/etc/dnsmasq.d/010-consul.conf:
# forward queries for .consul TLD to the consul agent
/etc/resolv.conf has the local IP of the instance:
# generated by /etc/NetworkManager/dispatcher.d/50-update-dnsmasq-resolv-conf; do not edit
nameserver 10.112.16.146
/etc/resolv.conf.dnsmasq contains the nameserver from the DHCP config in the VPC:
/etc/NetworkManager/dispatcher.d/50-update-dnsmasq-resolv-conf is a script I wrote to manage /etc/resolv.conf.dnsmasq:
#!/bin/bash
## script to be executed when dhcp changes are made; maintains /etc/resolv.conf
## man NetworkManager
interface="${1}"
action="${2}"
/bin/logger -t "${0}" \
"invoked for interface ${interface:-<not_provided>} and action '${action}' with nameservers '${IP4_NAMESERVERS}', domains '${IP4_DOMAINS}'"
if [ -n "${IP4_NAMESERVERS}" ]; then
echo "# generated by ${0}; do not edit" >| /etc/resolv.conf.dnsmasq
for ns in ${IP4_NAMESERVERS}; do
echo "nameserver ${ns}" >> /etc/resolv.conf.dnsmasq
done
## use IP of eth0, so we can use the same resolv.conf and mount it in
## containers
local_ip=$( ip addr show eth0 | awk '/inet / {print substr($2, 0, index($2, "/") - 1)}' )
echo "# generated by ${0}; do not edit" >| /etc/resolv.conf
echo "nameserver ${local_ip:-127.0.0.1}" >> /etc/resolv.conf
if [ -n "${IP4_DOMAINS}" ]; then
echo "search node.consul ${IP4_DOMAINS}" >> /etc/resolv.conf
fi
fi
The final piece is /etc/NetworkManager/conf.d/000-hands-off-my-resolv.conf, which tells NetworkManager to not manage /etc/resolv.conf:
[main]
## configure NetworkManager to not manage /etc/resolv.conf, as we'll bring our own
## man NetworkManager.conf
dns=none
I hope that helps, Chris.