|
我们在办室的时候,有时会去访问别的机器,如果是在windows下,我们有时候会用机器名去访问,因为netbios/wins会帮我们来把机器名转成IP的。下面给大家介绍一种用动态DNS来解析机器名的办法。不过,不是用的w2k的DDNS,而是用的Linux. <br>
<br>
准备:一台(或两台)Linux服务器,用来做DHCP server和DNS server。也可以把它做成两台服务器。 <br>
<br>
安装:服务器的安装过程,请参考其它文档,记住把 dhcp 和 bind, bind-utils 装上就行了。 <br>
<br>
配置: <br>
<br>
一、DHCP的配置: <br>
<br>
配置DHCP server 时很简单,可以参考 /usr/share/doc/dhcp-x.xx/dhcpd.conf.sample来做。也可以先把这个文件cp 到 /etc/dhcpd.conf,然后根据自己的需要做适当修改。下面贴出我的一个/etc/dhcpd.conf,供大家参考: <br>
代码: <br>
<br>ddns-update-style interim; <br>ignore client-updates; <br>
<br>key DHCP_UPDATER { <br>algorithm HMAC-MD5; <br>secret qhB++OR5yWo8BTXwk/m4ng; <br>}; <br>
<br>zone bj.pnx. { <br>primary 127.0.0.1; <br>key DHCP_UPDATER; <br>} <br>
<br>zone 251.168.192.in-addr.arpa. { <br>primary 127.0.0.1; <br>key DHCP_UPDATER; <br>} <br>
<br>subnet 192.168.251.0 netmask 255.255.255.0 { <br>range 192.168.251.100 192.168.251.200; <br># --- default gateway <br>option routers 192.168.251.254; <br>option subnet-mask 255.255.255.0; <br>
<br># option nis-domain "domain.org"; <br>option domain-name "bj.pnx"; <br>option domain-name-servers 192.168.251.63,192.168.251.254; <br>
<br># option time-offset 28800; # PRC Standard Time <br># option ntp-servers 192.168.251.220; <br># option netbios-name-servers 192.168.1.1; <br>
<br># range dynamic-bootp 192.168.0.128 192.168.0.255; <br>default-lease-time 21600; <br>max-lease-time 43200; <br><br>} <br><br>
<br>
<br>
几个要注意的地方: <br>
1. "ddns-update-style" <br>
这个就是动态DNS的更新方式,有几个选项,我用的是interim,可以用 man dhcpd.conf找到另外的几个选项。 <br>
<br>
2. "ignore client-updates" <br>
这个选项是不允许客户机更新DNS记录。当然,也可能允许,但会有一点问题。 <br>
<br>
3. "key DHCP_UPDATER" <br>
这个是更新DNS的KEY,是必须的。其中algorithm 后的是生成key的算法,key的生成是用 "dnssec-keygen -a HMAC-MD5 -b 128 -n USER DHCP_UPDATER"。 <br>
<br>
4. "zone" <br>
要更新的zone,如果是本机就是DNS server,primay 就写127.0.0.1,要是其它机器是DNS server, 就写那台机器的IP。 <br>
<br>
别的都是一般DNS该有的了,要注意的是一定要有 range 那一行,不然就分不了IP啦。 <br>
<br>
配好以后,可以启动一下试试, service dhcpd start,如果没问题,把dhcpd改成开机就启动,chkconfig --level 2345 dhcpd on。 <br>
<br>
二、bind(named)的配置。 <br>
<br>
关于bind(named)配置的文章有很多了。这里只把与普通配置不同的地方写出来。 <br>
下面给我的named.conf供大家参考: <br>
代码: <br>
<br>// generated by named-bootconf.pl <br>
<br>options { <br>directory "/var/named"; <br>/* <br>* If there is a firewall between you and nameservers you want <br>* to talk to, you might need to uncomment the query-source <br>* directive below. Previous versions of BIND always asked <br>* questions using port 53, but BIND 8.1 uses an unprivileged <br>* port by default. <br>*/ <br>// forwarders { 192.168.1.254; }; <br>// query-source address * port 53; <br>}; <br>
<br>// <br>// a caching only nameserver config <br>// <br>controls { <br>inet 127.0.0.1 allow { localhost; } keys { rndckey; }; <br>}; <br>
<br>key DHCP_UPDATER { <br>algorithm HMAC-MD5; <br>secret qhB++OR5yWo8BTXwk/m4ng; <br>}; <br>
<br>zone "." IN { <br>type hint; <br>file "named.ca"; <br>}; <br>
<br>zone "localhost" IN { <br>type master; <br>file "localhost.zone"; <br>allow-update { none; }; <br>}; <br>
<br>zone "0.0.127.in-addr.arpa" IN { <br>type master; <br>file "named.local"; <br>allow-update { none; }; <br>}; <br>
<br>zone "1.168.192.in-addr.arpa" IN { <br>type master; <br>file "1.168.192.zone"; <br>allow-update { key DHCP_UPDATER; }; <br>}; <br>
<br>zone "test.com" IN { <br>type master; <br>file "test.com"; <br>allow-update { key DHCP_UPDATER; }; <br>}; <br>include "/etc/rndc.key"; <br><br>
<br>
<br>
其中多了的是 <br>
代码: <br>
<br>key DHCP_UPDATER { <br>algorithm HMAC-MD5; <br>secret qhB++OR5yWo8BTXwk/m4ng; <br>}; <br><br>
<br>
这就是更新dns要用的key,必须和dhcpd.conf里的一样。 <br>
<br>
还有就是每个 zone 都可以用 key 来update了。 <br>
<br>
这样就行了。然后启动一下试试吧。 <br>
<br>
你就可以ping 机器名来找你同事的机器了。 <br>
<br>
本人只在windows客户机上试验过,Linux好象会有一点问题。哪位有兴趣,共同研究一下。 <br>
<br>
更新一下: <br>
代码: <br>
<br>
#===/etc/dhclient.conf for linux ======= <br>
send host-name "your host name"; <br>
request subnet-mask, broadcast-address, routers, <br>domain-name, domain-name-servers; <br>
require subnet-mask, domain-name-servers; <br>
timeout 60; <br>
retry 60; <br>
reboot 10; <br>
select-timeout 5; <br>
initial-interval 2; <br>
script "/sbin/dhclient-script"; <br><br>
<br>
|
|