eduardo:linux:dns
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
eduardo:linux:dns [2014/11/17 09:54] – eduardo | eduardo:linux:dns [2024/02/23 08:20] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== BIND DNS ====== | ||
+ | ===== Check BIND Install ===== | ||
+ | |||
+ | < | ||
+ | bash# rpm -q bind | ||
+ | | ||
+ | |||
+ | bash# rpm -q bind-chroot | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ===== Install Bind ===== | ||
+ | Bind packages are available under default yum repositories. To install packages simple execute below command. | ||
+ | |||
+ | < | ||
+ | bash# yum -y install bind bind-chroot | ||
+ | </ | ||
+ | |||
+ | ===== Configure FQDN ===== | ||
+ | |||
+ | Edit the /etc/hosts file and replace the ip address and domain name with yours ipaddress and domain name | ||
+ | |||
+ | < | ||
+ | bash# vi /etc/hosts | ||
+ | |||
+ | 192.168.122.9 ns1.example.com ns1 | ||
+ | </ | ||
+ | |||
+ | Edit the / | ||
+ | |||
+ | < | ||
+ | bash# vi / | ||
+ | |||
+ | HOSTNAME=ns1 | ||
+ | </ | ||
+ | |||
+ | Restart the network service | ||
+ | |||
+ | < | ||
+ | bash# / | ||
+ | </ | ||
+ | |||
+ | Now check Hostname and FQDN you are getting properly. | ||
+ | Once logout and re-login or Restart the server | ||
+ | |||
+ | < | ||
+ | bash# hostname | ||
+ | |||
+ | ns1 | ||
+ | |||
+ | bash# hostname -f | ||
+ | |||
+ | ns1.example.com | ||
+ | </ | ||
+ | |||
+ | Edit / | ||
+ | |||
+ | < | ||
+ | bash# vi / | ||
+ | |||
+ | domain example.com | ||
+ | search example.com | ||
+ | |||
+ | nameserver 192.168.122.9 | ||
+ | |||
+ | bash# | ||
+ | </ | ||
+ | |||
+ | ===== Config ===== | ||
+ | |||
+ | Copy sample configuration file | ||
+ | |||
+ | < | ||
+ | bash# cd / | ||
+ | |||
+ | bash# cp / | ||
+ | bash# cp / | ||
+ | </ | ||
+ | |||
+ | ===== Master DNS Server ===== | ||
+ | |||
+ | Edit named.conf | ||
+ | |||
+ | < | ||
+ | bash# vi / | ||
+ | |||
+ | ####### | ||
+ | include "/ | ||
+ | |||
+ | options { | ||
+ | directory "/ | ||
+ | forwarders {192.168.122.10; | ||
+ | }; | ||
+ | |||
+ | //Forward zone section for example.com | ||
+ | zone " | ||
+ | type master; | ||
+ | file " | ||
+ | allow-update { none; }; | ||
+ | }; | ||
+ | |||
+ | // Reverse Zone Section for example.com | ||
+ | zone " | ||
+ | type master; // Declaring as DNS Master Server | ||
+ | file " | ||
+ | allow-update { none; }; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | Create Forward Zone and Reverse zone file. | ||
+ | |||
+ | < | ||
+ | bash# vi / | ||
+ | |||
+ | ; comment is given by symbol ; ,hence this line is commented | ||
+ | ; IN SOA we give Start Of Authority email id in this pattern, username.domainname.tld eg. admin.example.com | ||
+ | ; FQDN must have period (.) sign at trailing end,see given below "IN NS ns1.example.com." | ||
+ | |||
+ | $TTL 1D | ||
+ | @ IN SOA ns1.example.com sharadchhetri.example.com. ( | ||
+ | 0 ; serial | ||
+ | 1D ; refresh | ||
+ | 1H ; retry | ||
+ | 1W ; expire | ||
+ | 3H ) ; minimum | ||
+ | |||
+ | IN NS ns1.example.com. | ||
+ | IN A 192.168.122.9 | ||
+ | NS1 IN A 192.168.122.9 | ||
+ | www IN A 192.168.122.11 | ||
+ | </ | ||
+ | |||
+ | Reverse Zone File: | ||
+ | |||
+ | < | ||
+ | bash# vi / | ||
+ | |||
+ | ;Reverse Zone File for example.com | ||
+ | ; do not forget to use period (.) at trailing end of FQDN | ||
+ | |||
+ | $TTL 1D | ||
+ | |||
+ | @ IN SOA ns1.example.com sharadchhetri.example.com. ( | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 3H ) ; minimum | ||
+ | |||
+ | | ||
+ | 9 IN PTR ns1.example.com. | ||
+ | 11 | ||
+ | </ | ||
+ | |||
+ | Changing ownership and group of files. | ||
+ | |||
+ | < | ||
+ | bash# cd / | ||
+ | |||
+ | chown named:named example.com.* | ||
+ | </ | ||
+ | |||
+ | Restart the named service. When you first time restart the named service,new rndc.key file will be generated and named service will take time to restart | ||
+ | |||
+ | < | ||
+ | bash# / | ||
+ | </ | ||
+ | |||
+ | ===== Slave DNS Server ===== | ||
+ | |||
+ | On Master DNS Server. Update named.conf | ||
+ | |||
+ | < | ||
+ | options { | ||
+ | .... | ||
+ | notify yes; | ||
+ | also-notify { 202.84.190.10; | ||
+ | allow-transfer { 202.84.190.10; | ||
+ | .... | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | Create named.conf file in / | ||
+ | |||
+ | < | ||
+ | bash# vi / | ||
+ | |||
+ | // named.rfc1912.zones: | ||
+ | // | ||
+ | // Provided by Red Hat caching-nameserver package | ||
+ | // | ||
+ | // ISC BIND named zone configuration for zones recommended by | ||
+ | // RFC 1912 section 4.1 : localhost TLDs and address zones | ||
+ | // and http:// | ||
+ | // (c)2007 R W Franks | ||
+ | // | ||
+ | // See / | ||
+ | // | ||
+ | |||
+ | ####### New line Addition ######## | ||
+ | |||
+ | include "/ | ||
+ | |||
+ | options { | ||
+ | directory "/ | ||
+ | forwarders {192.168.122.9; | ||
+ | }; | ||
+ | |||
+ | //Forward zone section for example.com | ||
+ | |||
+ | zone " | ||
+ | type slave; | ||
+ | file " | ||
+ | masters {192.168.122.9; | ||
+ | }; | ||
+ | |||
+ | // Reverse Zone Section for example.com | ||
+ | |||
+ | zone " | ||
+ | type slave; // Declaring as DNS Slave Server | ||
+ | file " | ||
+ | masters {192.168.122.9; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | Change the permission of / | ||
+ | |||
+ | So that when we restart the named service in ns2, bydefault all zone file will be transfer. | ||
+ | |||
+ | < | ||
+ | bash# chmod 770 / | ||
+ | </ | ||
+ | |||
+ | Restart the named service | ||
+ | |||
+ | < | ||
+ | bash# / | ||
+ | </ | ||
+ | |||
+ | Now check all zone files are bydefault transfered to slave DNS server | ||
+ | |||
+ | < | ||
+ | bash# ls -l / | ||
+ | |||
+ | total 40 | ||
+ | drwxr-x--- 6 root named 4096 Jul 18 23:23 chroot | ||
+ | drwxrwx--- 2 named named 4096 Mar 29 04:18 data | ||
+ | drwxrwx--- 2 named named 4096 Mar 29 04:18 dynamic | ||
+ | -rw-r--r-- 1 named named 378 Jul 20 16:58 example.com.forward-zone | ||
+ | -rw-r--r-- 1 named named 452 Jul 20 17:01 example.com.reverse-zone | ||
+ | -rw-r----- 1 root named 1892 Feb 18 2008 named.ca | ||
+ | -rw-r----- 1 root named 152 Dec 15 2009 named.empty | ||
+ | -rw-r----- 1 root named 152 Jun 21 2007 named.localhost | ||
+ | -rw-r----- 1 root named 168 Dec 15 2009 named.loopback | ||
+ | drwxrwx--- 2 named named 4096 Mar 29 04:18 slaves | ||
+ | |||
+ | bash# | ||
+ | </ | ||
+ | |||
+ | Whenever you do any update in master DNS server in zone files increase the serial otherwise slave will not get update from master. | ||
+ | |||
+ | After this ,restart the named service by using command / | ||
+ | |||
+ | < | ||
+ | bash# cat / | ||
+ | |||
+ | $ORIGIN . | ||
+ | $TTL 86400 ; 1 day | ||
+ | 122.168.192.in-addr.arpa IN SOA ns1.example.com.122.168.192.in-addr.arpa. sharadchhetri.example.com. ( | ||
+ | 2 ; serial | ||
+ | 86400 ; refresh (1 day) | ||
+ | 3600 ; retry (1 hour) | ||
+ | 604800 | ||
+ | 10800 ; minimum (3 hours) ) | ||
+ | | ||
+ | NS ns1.example.com. | ||
+ | NS ns2.example.com. | ||
+ | $ORIGIN 122.168.192.in-addr.arpa. | ||
+ | 10 PTR ns2.example.com. | ||
+ | 11 PTR www.example.com. | ||
+ | 9 PTR ns1.example.com. | ||
+ | |||
+ | bash# | ||
+ | </ | ||
+ | |||
+ | ===== Firewall Rule ===== | ||
+ | |||
+ | DNS servers communicate over port 53 UDP. The firewall must be configured to allow UDP on both source and destination ports 53. | ||
+ | < | ||
+ | [bash]# iptables -I INPUT -p udp --dport 53 -j ACCEPT | ||
+ | |||
+ | [bash]# service iptables save | ||
+ | </ | ||
+ | |||
+ | To allow zone transfer, add the following on master. As zone transfer uses TCP instead of UDP | ||
+ | < | ||
+ | [bash]# iptables -I INPUT -p tcp --dport 53 -j ACCEPT | ||
+ | |||
+ | [bash]# service iptables save | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Auto start ===== | ||
+ | |||
+ | You should now set the runlevels required for the DNS service, then restart it. | ||
+ | |||
+ | < | ||
+ | [bash]# chkconfig --level 2345 named on | ||
+ | [bash]# / | ||
+ | </ | ||
+ | |||
+ | You can check which runlevels the service will be active with the following command. | ||
+ | |||
+ | < | ||
+ | [bash]# chkconfig --list named | ||
+ | </ |