I use a VPN on an interface, e.g tun0 (, while the LAN network is on the interface eth0 (

I use dnsmasq to route specific addresses to my LAN and these addresses have their VPN network counterparts which should link to the same host name which resides on the same machine which is also the DNS. (The interfaces are firewalled so eth0 can't communicate with tun0 and viceversa)

So we would have two host file like these:

hosts.eth0: example.com

hosts.tun0: example.com

I'm finding some difficulties to tell dnsmasq to use a specific host file for a specific interface without launching dnsmasq two times in a way similar to:

dnsmasq -I lo -i eth0 -H hosts.eth0

and its counterpart

dnsmasq -I lo -i tun0 -H hosts.tun0

This approach isn't very nice on a Debian 8 box and I think there must be a better way to achieve what I want to do. What can I do?


Will this do what you're looking for?

-y, --localise-queries

Return answers to DNS queries from /etc/hosts which depend on the interface over which the query was received. If a name in /etc/hosts has more than one address associated with it, and at least one of those addresses is on the same subnet as the interface to which the query was sent, then return only the address(es) on that subnet. This allows for a server to have multiple addresses in /etc/hosts corresponding to each of its interfaces, and hosts will get the correct address based on which network they are attached to. Currently this facility is limited to IPv4.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.