Software versionisc-dhcp-client 4.3.0 dnsmasq 2.71
Operating SystemDebian 8
WebsiteDebian Website
Last Update27/07/2014

Introduction

My use case is specific but not isolated. When I’m at work, I’m connected to my VPN at home. I have a specific DNS at home for my domain in deimos.lan and this is very useful to avoid me to remind all the IP of the services I have.

Sometimes, I want to connect to a home service from the VPN, but my bookmarks are with the local DNS at home which is of course not known from the DNS at work. A solution is to add specifics entries in /etc/hosts but it quickly starts to be very boring. That’s why I’ve searched a solution to use my DNS at home only when I try to reach deimos.lan domain.

Installation

First of all, I need a dhcp client (as I have a DHCP server at home and at work) and dnsmasq to run locally on my laptop:

1
aptitude install dnsmasq isc-dhcp-client

Configuration

Dnsmasq

We’re going to setup dnsmasq like this:

1
2
3
4
server=/deimos.lan/192.168.0.1
interface=lo
listen-address=127.0.0.1
bind-interfaces

Here are explanations:

  • server: you need to specify for the domain (deimos.lan) which DNS server should be targeted (192.168.0.1)
  • interface: the interface to listen on
  • listen-address: only listen to 127.0.0.1 IP address
  • bind-interfaces: only bind to specified interfaces (here: lo)

And restart dnsmasq to apply this new configuration.

DHCP client

If we now change resolv.conf values to point to the DNS 127.0.0.1, we will be correctly redirected. But the problem is everytime the dhcp lease will expire and renewed, it will change the resolv.conf file. To avoid it, we’re going to add this line in the dhclient configuration file:

1
prepend domain-name-servers 127.0.0.1;

This will force the first “nameserver” line in resolv.conf to be 127.0.0.1. To finish, restart the dhclient service to have this new version working.

Last updated 27 Jul 2014, 13:41 CEST. history