How to setup and configure dnsmasq for local development environment

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

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 )


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


Use this command to start dnsmasq manually

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


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

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 and edit /etc/dhcp/dhclient.conf and uncomment prepend domain-name-servers; 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


local_dnsmasq_listen_Address 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


;; Query time: 105 msec
;; WHEN: Tue Sep 9 15:53:59 2014
;; MSG SIZE rcvd: 156

After five or six try

;; Query time: 2 msec
;; WHEN: Tue Sep 9 15:54:55 2014
;; MSG SIZE rcvd: 156

lets test domains are working correctly


;; Query time: 1 msec
;; WHEN: Tue Sep 9 15:57:58 2014
;; MSG SIZE rcvd: 106

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


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


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

Tagged With : -
Add Comment