Openvpn – How to automatically add localhost DNS server (dnsmasq) to resolv.conf

arch-linuxdnsmasqdomain-name-systemopenvpnresolv.conf

I did the steps at https://wiki.archlinux.org/index.php/OpenVPN#DNS to set up DNS with OpenVPN so that anytime the OpenVPN connects or disconnects, it automatically updates /etc/resolv.conf.

The problem is that I've also got a DNS server (dnsmasq) running on localhost to resolve certain custom domains, and I'd like to add these entries to the generated /etc/resolv.conf. How can I do that?

I tried uncommenting the line name_servers=127.0.0.1 in /etc/resolvconf.conf, but then the generated /etc/resolv.conf contains only that single line, rather than appending it to the end.

Best Answer

Something I ran into also.

Resolvconf can generate configuration which dnsmasq can read.

Add to your resolvconv.conf

dnsmasq_resolv=/etc/dnsmasq-resolv.conf

And then to your dnsmasq.conf

resolv-file=/etc/dnsmasq-resolv.conf

This way, resolvconf will write the dns servers for dnsmasq in a special configuration file, instead of dnsmasq reading it from /etc/resolv.conf.

Related Topic