Showing posts with label dns. Show all posts
Showing posts with label dns. Show all posts

Tuesday, November 8, 2011

DNS wildcard and DHCP with BIND vs dnsmasq


set up DNS wildcard for blah.dev

BIND configuration

/etc/bind/named.conf.local 
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.
  IN A 127.0.0.1
*.dev. IN A 127.0.0.1
named-checkzone dev db.dev

DHCP client configuration

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


Testing

ping blah.dev will return 127.0.0.1


Set up dnsmasq for local DNS cache and DHCP


disable dnsmasq from networkmanager

sudo vim /etc/NetworkManager.conf.  comment out dnsmasq
sudo service network-manager restart



Install and configure dnsmasq


  • sudo apt-get install dnsmasq
  • sudo vim /etc/dnsmasq.conf
  •     listen-address=127.0.0.1
  •     address=/dev/127.0.0.1
  •     address=/prod/127.0.0.1
  • sudo service dnsmasq restart


Set up Apache for vhost_alias
 

mod_vhost_alias
  • sudo a2enmod vhost_alias (this will enable module vhost_alias for loading). 
  • sudo vi /etc/apache2/mods-available/vhost_alias.conf    (create one if not existing)
<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 (.*) http://192.168.1.100:28000/_replSet



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
</Directory>

</VirtualHost>



Saturday, September 17, 2011

DNS query tracing

dig @dns.server target.dns +tracing
watch it under wireshark, It is very useful to understand how DNS query works especially for a non-cached look up.
  • As a DNS client, dig will send a standard DNS query to the target DNS server via UDP port 53. 
  • For a non-cached look up, dig will ask the answer from root server, TLD (Top Level Domain) server, specific domain server in that order.