Here is the very useful blog for linux guys. We all know how to configure the DNS (bind9) server and due to name servers only we are able to resolve IPs to human readable host-names and viz. but it works in between internet and LAN network. What about LAN IPs and hosts, still we need to access them by using IP address of client machines. So here is the solution for LANs IP to hostname resolution.
Friends steps in this blog shows how to configure the DHCP server to automatically update the DNS records when giving out a new lease to a client computer. I am assuming that you already have a working copy of dhcp3-server and bind9 installed. If you don’t have that I suggest that you first read my two other blogs on how to install and configure them.
Configuration Steps :
Step 1
Apparently the Ubuntu server is installed with an AppArmor profile that prevents bind to write to the /etc/bind directory. The default profile suggests that these files should be put in /var/lib/bind. We will start by copying our zone files so we have a backup remaining if anything goes wrong:
Now change the owner and group of the files to bind, so that bind will have file permissions that allows it to write to the files:
Step 2
We don’t want anybody to be able to update our DNS, so we need to create a secret, a key, that the DCHP server must know in order to be able to update the DNS:
You can observe the generated key by:
Your key should be looking somewhat like the following key (without quotes):
Now copy the key to the clipboard so that you can paste it into the configuration file later on.
Step 3
We now need to add the key to the bind configuration and tell it what zones that we want it to allow updates on. I’ve included the contents of configuration file here and marked the changes that I’ve made in bold.
Edit your /etc/bind/named.conf.local:
Changes are marked with bold and red color:
#The secret key used for DHCP updates.
key DHCP_UPDATER { algorithm HMAC-MD5.SIG-ALG.REG.INT; # Important: Replace this key with your generated key. # Also note that the key should be surrounded by quotes. secret "HgtB4WACBDEFGijkMZqwe=="; };
zone "local.domain" { type master; # Change the path of the database file to the writable
copy in /var/lib/bind file "/var/lib/bind/local.domain.db"; # Tell this zone that we will allow it to be updated
#from anyone that knows the secret specified in the
#DHCP_UPDATER key. allow-update { key DHCP_UPDATER; }; }; zone "1.168.192.in-addr.arpa" { type master; # Change the path of the database file to the
#writable copy in /var/lib/bind file "/var/lib/bind/rev.1.168.192.in-addr.arpa"; # Tell this zone that we will allow it to be updated
#from anyone that knows the secret specified in the
#DHCP_UPDATER key. allow-update { key DHCP_UPDATER; }; };
Step 4
Now edit the your dhcps.conf so that the DHCP server can send updates to the DNS
Changes are marked with bold and red:
# # Make sure to change the ddns update style to interim: ddns-update-style interim; ignore client-updates; # Overwrite client configured FQHNs ddns-domainname "local.domain."; ddns-rev-domainname "1.168.192.in-addr.arpa."; # option definitions common to all supported networks... option domain-name "local.domain"; option domain-name-servers ubuntu.local.domain; default-lease-time 600; max-lease-time 7200; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. authoritative; # Use this to send dhcp log messages to a different log file
#(you also have to hack syslog.conf to complete the redirection). log-facility local7; key DHCP_UPDATER { algorithm HMAC-MD5.SIG-ALG.REG.INT; # Important: Replace this key with your generated key. # Also note that the key should be surrounded by quotes. secret "HgtB4WACBDEFGijkMZqwe=="; }; zone local.domain. { primary 127.0.0.1; key DHCP_UPDATER; } zone 1.168.192.in-addr.arpa. { primary 127.0.0.1; key DHCP_UPDATER; } # This is a very basic subnet declaration. subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.30 192.168.1.200; option routers router.local.domain; }
Step 5
The configuration files now contains our secret key. We should not let just anyone can read our secret key, so we are removing the general read rights from them:
sudo chmod o-r /etc/dhcp3/dhcpd.conf
We should now have a fully working dynamic dns system for our local network, lets hold the thumbs and restart the services.
sudo /etc/init.d/dhcp3-server restart
Step 6
Testing :
If you have an Ubuntu client that uses DHCP you can restart its network to make the DHCP-client request a new ip-address from the server:
You should now be able to lookup your client computer in your DNS:
Result:
lappy-ubuntu.local.domain has address192.168.1.30
And the reverse should now also work for your client computer address:
Result:
30.1.168.192.in-addr.arpa domain name pointer lappy-ubuntu.local.domain.
And its done... :) now you can access any client machine by hostname only.. so there is no need to check ip address and then entering the IPs.
Hope this post will save lots of time of yourz...