Configure Dnsmasq To Query Different Nameservers For Different Domains

When connecting to a VPN you may have a DNS server which serves for a particular domain. For example when connected to your companies VPN, your local DNS config in /etc/resolv.conf is updated with: nameserver

The DNS server is your companies internal DNS server which resolves to You need to access on but don’t necessarily want to have all DNS queries go to You also don’t want manage /etc/hosts entries which can become stale over time.

dnsmasq a lightweight DNS and DHCP service can help. Simply install dnsmasq, starting off with a simple config.


Create /etc/dnsmasq.d/

  • line one returns for the host
  • line two specifies as the upstream DNS server for all other queries such as

Reload the dnsmasq service.

systemctl restart dnsmasq

And finally update /etc/resolv.conf


Now your local resolver clients will use dnsmasq as a DNS server with dnsmasq only forwarding queries for to the upstream DNS server

Sistem Uzmanı, Linux Hacısı, El-Kernel

Yorum yapın