DNS wildcard and DHCP with BIND vs dnsmasq

Disable dnsmasq from networkmanager

  • sudo vim /etc/NetworkManager.conf and #dnsmasq
  • sudo service network-manager restart

Install and configure dnsmasq

  • sudo apt-get install dnsmasq
  • sudo vim /etc/dnsmasq.conf
  •     listen-address=
  • To add *.dev, *.prod
  •      address=/dev/
  •     address=/prod/
  • To add alias:    cname=svn, localhost
  • sudo service dnsmasq restart

Add local dnsmasq as a name server to /etc/resolv.conf

  1. add “nameserver” to /etc/resolv.conf so that it will be used by all DNS clients.
  2. (hack here) In order to prevent network-manager to flush this file. “sudo chattr +i /etc/resolv.conf”

Set up Apache for vhost_alias


  • sudo a2enmod rewrite: enable module rewrite
  • sudo a2enmod vhost_alias: enable module vhost_alias 
  • add the following into a site such as default site. 

<VirtualHost *:80>
# get the server name from the Host: header and put in %0

# this is for dev
RewriteCond %{HTTP_HOST} ^mongo.dev$
RewriteRule (.*) http://localhost:28017/_replSet

RewriteCond %{HTTP_HOST} ^mongo.snap$
RewriteRule (.*)

UseCanonicalName Off

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /var/www/vhosts/%0

<Directory />
# Global settings
Options FollowSymLinks
AllowOverride All


set up DNS wildcard for blah.dev

BIND configuration

zone “dev” {
type master;
file “/etc/bind/db.dev”;

run”named-checkconf named.conf.local”

/etc/bind/db.dev:  use the loopback address so the IP address is not affected by DHCP.
dev. 86400 IN SOA dev. hostmaster.dev. (
20111101; serial yyyy-mm-dd
10800; refresh every 15 min
3600; retry every hour
3600000; expire after 1 month +
86400 ); min ttl of 1 day
IN NS dev.
IN MX 10 dev.
*.dev. IN A

named-checkzone dev db.dev

DHCP client configuration

  • uncomment the line in /etc/dhcp/dhclient.conf: prepend domain-name-servers;
  • sudo dhclient
  • sudo /etc/init.d/bind9 restart

ping blah.dev will return
This entry was posted in dns, dnsmasq. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s