การทำ DNS Server (DNS:Domain Name System)

1.) ตรวจสอบว่ามี โปรแกรม Bind (Berkeley Internet Name Domain) ติดตั้งอยู่หรือไม่ version ไหน
[root@test root]# rpm -q bind
bind-9.2.1-9

2.) ปรับแต่ง file ที่ /etc/named.conf

// generated by named-bootconf.pl

options {
directory "/var/named";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
};

// a caching only nameserver config

controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};

zone "." IN {
type hint;
file "named.ca";
};

zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};

zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};

// เพิ่ม zone ที่ต้องการเข้าไป เช่น company.com
zone "company.com" IN {
type master;
file "zone.company.com";
allow-update { none; };
};



3.) สร้าง file zone.company.com ไว้ที่ /var/named

$TTL 43200
$ORIGIN company.com.
@ IN SOA ns1.company.com. root.company.com. (

        2006020701 ; Serial
21600 ; Refresh
900 ; Retry
1209600 ; Expire
43200 ) ; Minimum
      IN NS ns1.company.com.
IN MX 10 mail1.company.com.
IN MX 20 mail2.company.com.
 
ns1 A IN 192.168.1.1  
www A IN 192.168.1.2  
mail1 A IN 192.168.1.3  
mail2 A IN 192.168.1.4  
proxy A IN 192.168.1.5  

~
~
~



4.) เรียบร้อยแล้ว ใช้คำสั่ง
[root@test root]# service named restart
Stopping named: [ OK ]
Starting named: [ OK ]

[root@test root]#


5.) ทดสอบโดย ใช้คำสั่ง
[root@testt root]# nslookup www.company.com
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: 192.168.1.1
Address: 192.168.1.1#53

Name: www.company.com
Address: 192.168.1.2

You have new mail in /var/spool/mail/root
[root@test root]#



@ Secure BIND with these tips

BIND is a DNS server package that's had a rather spotty history when it comes to security. However, despite these limitations, there are few alternatives for serving up DNS data that are as feature-rich as BIND.

If you just need to serve up DNS data without support for zone transfers, keys, and other features that BIND offers, using something like D.J. Bernstein's djbdns package may be sufficient. But if you need some of the more robust features that only BIND offers, you might as well learn a few things you can do to better secure your setup.

First, configure BIND not to report its version number. This can stop passive scanners from identifying the version of BIND you're using.

This trick doesn't really secure BIND as much as it obfuscates things a bit. You can do this by editing the named.conf file, as shown below:

options {
version "Not available";
}

You can also restrict which hosts can perform zone transfers. BIND configurations typically have no restrictions for performing a zone transfer, which can lead to providing unwanted data to potential attackers.

You can also set this restriction using the named.conf file. Here's an example:

options {
allow-transfer { 192.168.5.10; };
}

This restricts zone transfers to 192.168.5.10, which would be your secondary DNS server. You can also use Transaction Signatures (TSIG) to more securely perform zone transfers.

You should also disable recursive queries, which prevents your DNS server from being vulnerable to spoofing attacks. Add the following to the named.conf file:

options {
fetch-glue no;
recursion no;
}

Finally, you may also want to consider running BIND in a chrooted environment as a nonprivileged user. (BIND's documentation discusses how to do this.)

By running BIND in a chroot, you're locking it into a special section of your system where it can't interact with the rest of the system, minimizing the damage potentially caused by an attacker who successfully exploits it.