一、 DNS说明
DNS使用端口号:53
正解与反解说明:
正解:通过Domain(DNS下的hostname)应射IP;通过hostname去找IP
反解:通过IP反查hostname
Zone(区域):一个正解或一个反解的设定就是一个zone
二、 安装DNS的套件:bind9
sudo apt-get install bind9
查看安装后的相关目录文件:sudo dpkg – L bind9
查看端口是否已启动:netstat – tunlp | grep 53
三、 DNS设定:
配置环境:DNS Server IP:192.168.1.254 ,hostname:samba.elantech.com
在DNS Server下的配置文件有如下:
/etc/bind/named.conf.options //全局设置
/etc/bind/named.conf.default-zone //添加或删除zone的配置
/etc/bind/db.127 //本机反解
/etc/bind/db.local //本机正解
四、 DNS Server 配置:
配置步骤如下:
1、修改全局选项 sudo vi /etc/bind/named.conf.options
转发的IP地址修改成广东电信的DNS IP:
forwarders {
202.96.128.143;
};
2、添加zone sudo vi /etc/bind/named.conf.default-zone
添加2个zone ,“db.elantech.com”用来正解、“db.192”是用来反解
zone "elantech.com" {
type master;
file "/etc/bind/db.elantech.com";
};
zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192";
};
3、设定DNS的正解:sudo cp /etc/bind/db.local /etc/bind/db.elantech.com
root@samba:/etc/bind# vi db.elantech.com
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA elantech.com. root.elantech.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS elantech.com.
@ IN A 192.168.1.254
samba IN A 192.168.1.254
4、设定DNS的反解: sudo cp /etc/bind/db.127 /etc/bind/db.192
root@samba:/etc/bind# vi db.192
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA elantech.com. root.elantech.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS elantech.com.
1.0.0 IN PTR samba.elantech.com.
254 IN PTR samba.elantech.com.
5、启动bind服务: sudo /etc/inti.d/bind9 restart
6、查看启动bind服务的日志: tail /var/log/syslog
root@samba:/etc/bind# tail /var/log/syslog
Aug 3 10:15:14 samba named[1228]: command channel listening on ::1#953
Aug 3 10:15:14 samba named[1228]: zone 0.in-addr.arpa/IN: loaded serial 1
Aug 3 10:15:14 samba named[1228]: zone 127.in-addr.arpa/IN: loaded serial 1
Aug 3 10:15:14 samba named[1228]: zone 1.168.192.in-addr.arpa/IN: loaded serial 1
Aug 3 10:15:14 samba named[1228]: zone 255.in-addr.arpa/IN: loaded serial 1
Aug 3 10:15:14 samba named[1228]: zone elantech.com/IN: loaded serial 2
Aug 3 10:15:14 samba named[1228]: zone localhost/IN: loaded serial 2
Aug 3 10:15:14 samba named[1228]: managed-keys-zone ./IN: loading from master file managed-keys.bind failed: file not found
Aug 3 10:15:14 samba named[1228]: managed-keys-zone ./IN: loaded serial 0
Aug 3 10:15:14 samba named[1228]: running
7、在本机(192.168.1.254)上设置DNS :sudo /etc/resolv.conf
添加一行, nameserver 192.168.1.254
五、 测试DNS
1、 在DNS Server端
命令:host samba.elantech.com (正解)
samba.elantech.com has address 192.168.1.254
命令:host 192.168.1.254 (反解)
254.1.168.192.in-addr.arpa domain name pointer samba.elantech.com.
2、 在客户端
命令: nslookup www.baidu.com
C:\Documents and Settings\Administrator>nslookup www.baidu.com
Server: samba.elantech.com
Address: 192.168.1.254
Non-authoritative answer:
Name: www.a.shifen.com
Addresses: 220.181.112.143, 220.181.111.148
Aliases: www.baidu.com
参考: