Computersnyou

How to setup and configure dnsmasq for local development environment

Posted on  9/9/2014

Dnsmasq is small lightweight DNS server for small network such as home and and small office . Its lightweight and leaves small footprint . overall its great dns tool for local and small network. It support caching of A, AAAA, CNAME and PTR, also DNSKEY and DS , supports DHCPv4, DHCPv6, BOOTP and PXE. its DHCP subsystem support static and dynamic DHCP leasing. So lets see How to setup and configure dnsmasq for local development environment.

Screen Shot 2014-09-08 at 11.12.21 am
Screen Shot 2014-09-08 at 11.12.21 am

How to setup DNSMasq in Linux ( Ubuntu , Debian , Mint all debian based )

sudo apt-get update
sudo apt-get install dnsmasq

How to setup DNSMasq In Mac ( using homebrew )

Installation

brew install dnsmasq

it will give you some info and starting options after installation ,

copy configuration file

copy the example configuration to /usr/local/etc/dnsmasq.conf .

cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

Launch at startup

You can use this command to start dnsmasq automatically on system start

sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons

Start

Use this command to start dnsmasq manually

sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

Stop

Use this command to start dnsmasq manually

sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

also there is a great tool called LaunchRocket Its provide awesome GUI for homebrew daemons

Lauch Rocket Mac
Lauch Rocket Mac

How to Configure dnsmasq local dns

configuration file Ubuntu : /etc/dnsmasq.conf Mac : /usr/local/etc/dnsmasq.conf those are main configuration files for each platforms , let see how we can redirect all *.dev domains to localhost .

  • how to setup all .dev domain to go on localhost
sudo nano /etc/dnsmasq.conf

setup listen address to 127.0.0.1 and edit /etc/dhcp/dhclient.conf and uncomment prepend domain-name-servers 127.0.0.1; lets setup all *.dev address to localhost

sudo nano /etc/dnsmasq.conf

and search for (use ctrl+w in nano ) server block and uncomment that

server=/dev/127.0.0.1

local_dnsmasq_listen_Address
local_dnsmasq_listen_Address
dns_masq_local_dev
dns_masq_local_dev

Now restart dnsmasq

Linux : sudo /etc/init.d/dnsmasq restart MacOSX : sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist && sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist lets verify local DNS caching First try

dig ubuntu.com

;; Query time: 105 msec
;; SERVER: 192.168.100.1#53(192.168.100.1)
;; WHEN: Tue Sep 9 15:53:59 2014
;; MSG SIZE rcvd: 156

After five or six try

;; Query time: 2 msec
;; SERVER: 192.168.100.1#53(192.168.100.1)
;; WHEN: Tue Sep 9 15:54:55 2014
;; MSG SIZE rcvd: 156

lets test local.dev domains are working correctly

ping something.dev
dig something.dev

;; Query time: 1 msec
;; SERVER: 192.168.100.1#53(192.168.100.1)
;; WHEN: Tue Sep 9 15:57:58 2014
;; MSG SIZE rcvd: 106

dnsmasq local dns setup
dnsmasq local dns setup

Adding Local Entries

You can add local entries for example if you need dns for your local web development then you can use
address configuration option .
uncomment local=/localnet/ to read all /etc/hosts/ entries

address=/www.computersnyou.dev/192.168.0.100

Screen Shot 2015-06-22 at 11.43.55 am
Screen Shot 2015-06-22 at 11.43.55 am

how to make them work with apache virtual host

How to setup apache virtual host in mac If you are setting dnsmasq for local network then allow firewall to communicate

sudo ufw allow bootps

Useful Links

  1. http://thekelleys.org.uk/dnsmasq/docs
  2. https://help.ubuntu.com/community/Dnsmasq
  3. https://wiki.debian.org/HowTo/dnsmasq

Thanks for reading , I hope it was affirmative ( add our site in your adblock exception list ) to support me .


  • Home
  • About