This weekend I setup my DNS and DHCP again (updated to new version and changed the software). I am currently using the DNS and DHCP from ISC. There is nothing special about it, just the usual stuff. This configuration example will allow you to setup a normal DNS for caching and with a forward and reverse lookup zone, incl. access for rndc and updates from DHCP. The DHCP server will be configured with a small range of IP's and with access to update the DNS. The domain will be example.com but you can use whatever you want. The DNS and DHCP server will be the same machine. It's name in this example configuration is dc01. The network size is from 192.168.1.64 - 192.168.1.127, obviously the netmask is 255.255.255.192. The IP's from 192.168.1.65 - 192.168.1.120 I want to use as static IP's for my servers to play around. The IP's from 192.168.1.121 - 192.168.1.126 I want to use as DHCP range. Also the DNS acts caching, that means that all addresses that are not locally available will be externally resolved.
DNSFirst configure the named (all leading "spaces" must be "tabs"):
# vi /etc/named.confoptions { directory "/var/named"; forward first; forwarders { 58.6.115.43; };};// KEYSkey "rndc_key" { algorithm hmac-md5; secret "secret_rndc_key";};key "dhcp_key" { algorithm hmac-md5; secret "secret_dhcp_key";};// RNDCcontrols { inet 127.0.0.1 allow { localhost; } keys { rndc_key; };};// ZONESzone "." { type hint; file "root.hints";};zone "0.0.127.in-addr.arpa" { type master; file "zones/0.0.127";};zone "example.com" { type master; notify no; file "zones/example.com"; allow-update { key "dhcp_key"; };};zone "1.168.192.in-addr.arpa" { type master; notify no; file "zones/1.168.196"; allow-update { key "dhcp_key"; };};The configuration file above has some basic option in the beginning followed by two keys. The first key will allow the dhcpd to update the hosts in the domain. The second key will allow to control named by the rndc command.
Then configure the rndc:
# vi /etc/rndc.confkey rndc_key { algorithm "hmac-md5"; secret "secret_rndc_key";};options { default-server localhost; default-key rndc_key;};There is nothing special about it, just the key and the server to control.
After that the 3 zone files must be created. At first for localhost (all leading "spaces" must be "tabs"):
# vi /var/named/zones/0.0.127@ IN SOA dc01.example.com. root.example.com. ( 1 ; Serial 8H ; Refresh 2H ; Retry 4W ; Expire 1D) ; Minimum TTL NS dc01.example.com.1 PTR localhost.Then the forward zone files (all leading "spaces" must be "tabs"):
# vi /var/named/zones/example.comexample.com IN SOA dc01.example.com. root.example.com. ( 199804069 ; serial 28800 ; refresh (8 hours) 7200 ; retry (2 hours) 2419200 ; expire (4 weeks) 86400 ; minimum (1 day) ) NS dc01.example.com. A 192.168.1.73 MX 10 dc01.example.com.bck01 A 192.168.1.76The file above has some basic options about refresh etc. It also holds the NS record and the MX record. This is for the name server and the mail exchanger which are both dc01. The last entry is any server with a A record and an IP.
The last file is the reverse zone file (all leading "spaces" must be "tabs"):
# vi var/named/zones/1.168.1961.168.192.in-addr.arpa IN SOA dc01.example.com. root.example.com. ( 199803388 ; serial 28800 ; refresh (8 hours) 7200 ; retry (2 hours) 2419200 ; expire (4 weeks) 86400 ; minimum (1 day) ) NS dc01.example.com.76 PTR bck01.example.com.The reverse file just holds the NS again and the server from above.
Start named with the following command:
# /usr/sbin/namedCheck if it is running:
# pgrep -fl named8212 /usr/sbin/namedWhen it's not up and running, then check the logs. These can be /var/log/syslog, /var/log/messages or maybe /var/named/named.run. But this depends on your system.
DHCPThe next configuration file is for the DHCP which is much smaller then the DNS configuration above. First configure the dhcpd configuration file:
# vi /etc/dhcpd.conf# GENERICdefault-lease-time 86400; # ONE DAYmax-lease-time 604800; # ONE WEEK# DDNSddns-update-style interim;ddns-domainname "example.com";update-static-leases true;key dhcp_key { algorithm hmac-md5; secret secret_dhcp_key;};# ZONESzone example.com. { primary 127.0.0.1; key dhcp_key;}zone 1.168.192.in-addr.arpa. { primary 127.0.0.1; key dhcp_key;}# LEASESsubnet 192.168.1.64 netmask 255.255.255.192 { option domain-name-servers 192.168.1.73; option domain-name "example.com"; range 192.168.1.120 192.168.1.126; option routers 192.168.1.73;}The configuration above is very simple. It begins with the lease times and continues with section how to update the DNS. The last section defines the DHCP leases for the clients itself like the netmask, the DNS etc.
Start the dhcp server and check it:
# /usr/sbin/dhcpd# pgrep -fl dhcpd15295 /usr/sbin/dhcpdIf it is not up and running, check the logs again. If you now request an IP over DHCP than the DHCP server updates the DNS with the leased IP and the hostname of the client:
# dhcpcd eth0...# nslookup nb001Server: 192.168.1.73Address: 192.168.1.73#53Name: nb001.example.comAddress: 192.168.1.120And check your /etc/resolv.conf:
# cat /etc/resolv.conf # Generated by dhcpcd from eth0# /etc/resolv.conf.head can replace this linedomain example.comnameserver 192.168.1.73# /etc/resolv.conf.tail can replace this lineOr just use dig:
# dig bck01...# dig -x bck01...