Quick HOWTO : Ch19 : Dynamic DNS/zh

来自Ubuntu中文
Fei3ban留言 | 贡献2008年6月22日 (日) 16:49的版本
跳到导航跳到搜索


{{#ifexist: :Quick HOWTO : Ch19 : Dynamic DNS/zh/zh | | {{#ifexist: Quick HOWTO : Ch19 : Dynamic DNS/zh/zh | | {{#ifeq: {{#titleparts:Quick HOWTO : Ch19 : Dynamic DNS/zh|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Quick HOWTO : Ch19 : Dynamic DNS/zh|1|-1|}} | zh | | }}

简介


在大多数家庭网络环境,通过DSL或者Cable Modem连接网络的主机IP地址都是通过DHCP获得并随时间经常改变,这会给DNS服务(区域文件)带来问题。第18章“配置DNS”一节假定服务器地址是固定不变的。因此,产生了两大类DNS:

“静态DNS”
当ISP为您提供固定不变的静态IP地址时,你的DNS服务器作为您的站点域认证信息源。你可以把静态DNS看作是DNS的“传统”或“常规”模式。

“动态DNS”
当你通过DHCP从您的ISP处获得动态IP地址时,你就不得不使用第三方DNS提供商来为您的站点域提供DNS信息服务。
本章将详细讲解动态DNS的配置过程。

准备动态DNS

和DSL不同的是,大多数的cable modem供应商(类似有线宽频)不允许你在家开办主机站点,他们阻止入站的HTTP(TCP 端口80)和SMTP 邮件(TCP端口25)而允许其他的TCP通讯.许多动态DNS(DDNS)供应商意识到这点并提供了自动重定向让访问你主机的web客户通过一个不同的TCP端口.尽管这样也工作的很好,但是还是不方便.看起来很诱人的虚拟主机服务却要增加每月$10的费用,并且很多搜索引擎都不索引重定向的页面.


为你的web站点测试ISP(互联网供应商)的连通性

第一件事就是你要知道你的ISP是用DSL还是cable modem,最简单的方法就是打电话问,但是有时候答案是yes但是他们却说no.这时你就要自己做些测试.

设置

在测试开始之前你需要做一些基本调试.

1.在你的Linux web 服务器上配置并且启动Apache,参考第20章 ch20--"The Apache Web Server".

2.直接连接你的linux服务器到cable或者DSL的调制解调器,配置以太网卡的DHCP参数,参考第3章 ch3--"Linux Networking".

3.确认你可以ping到你的默认网关.

4.使用ip设置命令去设置你的web服务器的新的ip地址.(命令用法可以参考底3章).

5.在你的Linux web服务器上,尝试TELNET到新设置的ip地址,端口用80.参考第4章 ch4--"simple Network Trobleshooting".

如果你能完成这几步,说明你有很大的希望去正确配置Apache

从互联网测试

这时你应该可以看到页面在你自己的网站上.请朋友在其他地方尝试去telnet(用80端口)你网站的ip地址.

 如果80端口工作正常,再让朋友用浏览器连接你的网站看是否能看到页面.如果你的Linux服务器是在防火墙后面,那你要适当调整下你的网络结构,
 并且测试80端口指向你的服务器.
 如果TELNET到80端口失败,很可能是的ISP不允许HTTP处理.设置你的web站点使用不同的TCP端口,尽量在1024以上.Apache 的httpd.conf文件用来监听管理这个.改变它为你要的数值,然后重启httpd.

#httpd.conf listen directive, 改变 "80"为其他值
Listen 80

 再用telnet测试这个新设置的端口.如果工作,再尝试浏览器测试.如果测试的端口是1234,要使用下面的连接:

http://server-ip-address:1234

注意:如果你在运行iptable, 记住调整规则已匹配新端口,或者在测试期间停止ipstable.如果你能在非标准的端口连接到页面,然后你记下来给你的DDNS供应商做重定向.

测试端口转发

如果你的Linux 服务器是在防火墙的后面,应该适当调整你的网络结构,让Apache运行在端口80,然后从互联网测试端口转发,从非标准

端口到80端口.curl-疑难排解工具的一个特点是他允许你下载页面的HTML的代码到你屏幕上.你应该靠你web服务器的日志能确定你的路由器或者防火墙的外部地址以及curl的命令发出请求到DynDNS.org的ip信息服务器.在这个情况里你只需要关于的ip的资料,用grep命令就可以得到这个部分.在这个范例中,ip地址是24.4.97.110.

[root@bigboy tmp]# curl -s http://checkip.dyndns.org/ | grep -i address
Current IP Address: 24.4.97.110[root@bigboy tmp]# 


注册DDNS

Once you have decided to go ahead with DDNS you'll need to choose between the broad categories of Dynamic DNS service.

  • Free Dynamic DNS: Your website name will be a sub domain of the DDNS provider's domain. For example if the DDNS provider's domain is isp.net, then your site will become my-site.my-isp.net. You can perform all the necessary steps on your DDNS service provider's Web site. Remember that this type of service may be undesirable for a company that wants to establish its own corporate identity. Another disadvantage is that you must rely on your DDNS provider staying in business or else you may lose your domain. When you own your own domain this worry largely goes away as you are fully in control of the DNS registration and renewal process.

Another disadvantage is that you must rely on your DDNS provider staying in business or else you may lose your domain. When you own your own domain this worry largely goes away as you are fully in control of the DNS registration and renewal process.

  • Paid Customized DNS: You can register the domain name of your choice and still host your website on a DHCP line.

If you choose to create your own domain and use a paid DDNS service then you'll need to follow these steps:

1. Register your domains (such as my-site.com) with such companies as Verisign and RegisterFree.
2. Create an account with the DDNS provider and register your websites (sometimes called hosts) as part of your domain (as in www.my-site.com and mail.my-site.com) with them. Your DDNS registration process will provide you with a username and password which you'll need to use when configuring your DDNS client.
3. Update your domain information with your main DNS registrar (Verisign and RegisterFree) to tell them to direct queries to *.my-site.com to the DNS name servers of the DDNS provider.
4. Install a DDNS client on your web servers that continuously runs, only updating the DDNS provider's DNS servers with the most current DHCP IP address of the site whenever it detects a change.

Note: You should also be prepared for slower response times for your home-based site than if you were using a static IP and a regular DNS service.

安装DDNS客户端到你的服务器

所有的DDNS服务供应商需要在你的web服务器上有个DDNS的客户端,定期升级ip地址信息给你供应商DDNS的记录.用的最多的软件是DDclient,它是RPM格式.

动态DNS 和NAT 路由器/防火墙

As discussed in Chapter 2, "Introduction to Networking," to conserve the limited number of IP addresses available for Internet purposes, most home router/firewalls use network address translation (NAT) to map a single, public, DHCP-obtained IP address to the many private IP addresses within your network.

NAT can fool the operation of some DDNS client software. In these cases, the software can report only the true IP address of the Linux box's NIC interface. If the Linux box is being protected behind a NAT router/firewall, then the NIC reports in its data stream to the DDNS provider a private IP address that no one can reach directly via the Internet. The reported value is therefore invalid.

Some DDNS providers use more intelligent clients, such as DDclient, that can be configured to let the DDNS provider record the public IP address from which the data stream is originating. Once this is done, you'll have to also configure your router/firewall to do port forwarding to make all HTTP traffic destined for the IP address of the router/firewall to be exclusively address translated using NAT and forwarded to a single server on your home network. If your firewall is Linux based, then the examples in Chapter 14, "Linux Firewalls Using iptables," will be helpful. Many Web-based small office/home office (SOHO) firewalls have easy interfaces to configure port forwarding, please refer to your manufacturer's manual on how to do this

DDNS客户端软件- SOHO 路由器/防火墙

大部分较新的 SOHO路由器都已经内建一个或多个动态DNS供应商列表.DDNS的页面配置菜单通常有服务供应商名,用户名和密码.有了这个.你的服务器就不用另外安装软件了.

DDNS客户端软件- Linux DDclient

还有一个常用的客户端是DDclient,它可以克服NAT的局限性,可有效的确定最新的ip地址信息。类似RedHat和Fedora 这些Linux软件,DDclient也是RPM的格式.(如果你需要新版本的RPMs.参考第六章ch6--"install Linux Software")你也可以从DDNS供应商那里下载,或者在rpmfind.net上面查找.RPM的文件名通常是ddclient加版本号,比如: ddclient-3.6.3-1.noarch.rpm.

  /etc/ddclient.conf 文件

The ddclient.conf file is usually installed completely commented out, but provides many configuration examples for the most popular DDNS providers.

The most important general parameters to configure are:

  • Username: Your DDNS account's login name
    * Password: Your DDNS account's password
    * Use: The method used to determine the IP address to advertise to the DDNS server

Some important DDNS provider parameters are

  • Server: The name of the DDNS provider's main DNS server
    * Protocol: The methodology the DDNS client should use to communicate with the DDNS server
    * Your domain: The domain to which your web server will belong

You can use the ddclient command to determine the best use parameter to use in the ddclient.conf file. In this example, only the use=web option gives a valid Internet IP address and should be considered as a first option:

[root@bigboy tmp]# ddclient -daemon=0 -query
use=if, if=lo address is 127.0.0.1
use=if, if=wlan0 address is 192.168.1.100
use=web, web=dyndns address is 97.158.253.26
[root@bigboy tmp]# 

Take a look at a sample configuration. This example specifies a username of my-account-login-name and a password of my-account-password using the dyndns DDNS service provider's settings to track the Web site named mysite-example.dnsalias.com.

General Parameter Section

login=my-account-login-name
password=my-account-password

DDNS Provider Parameters Section

server=members.dyndns.org, \
protocol=dyndns2 \
mysite-example.dnsalias.com

You can add one of the following use lines to the General Parameter Section near the top of the file to define the method that will be used to determine the correct IP address:

  • Query A Well Known Internet Server: The web method queries two well known servers run by DynDNS.org and DNSpark to determine the public Internet IP address of the web server running the DDclient software. This method is the simplest as it requires no further information and handles NAT correctly.

use=web

  • Use The IP Address Of A Specific Server NIC : You can also use this option which will query the IP address of the DDclient web server's NIC interface of your choice. This is probably most valuable for servers connected directly to the Internet, and not via NAT

use=if, if=eth0

  • Login To Your SOHO Firewall For Information: The ddclient.conf file has a list of use statements for various vendor's firewalls. If your model isn't listed, you can create your own parameters as outlined in the ddclient README file. This option is good for NAT environments where the "use=web" option isn't considered a good alternative.

After editing your configuration file you'll have to start ddclient as shown in the next section.

怎样设置 DDclient 启动

你可以在boot的时候用chkconfig命令配置 DDclient启动:

[root@bigboy tmp]# chkconfig ddclient on 

你能够在boot后用下面的参数启动,停止,重启DDclient:

[root@bigboy tmp]# service ddclient start
[root@bigboy tmp]# service ddclient stop
[root@bigboy tmp]# service ddclient restart 

记住,每次在你更改了ddclient.conf文件之后要重启ddclient进程,这样才会取得效果.

你可以在任何时候测试,使用pgrep的命令,取得简洁的进程ID

[root@bigboy tmp]# pgrep ddclient

查找 DDclient 帮助

 DDclient 的read-me文件和 ddclient.conf 文件是定制配置和问题解决的一种很好的资源.你可以使用 DDclient RPMs 或者 locate 命令行查找read-me文件.

使用 rpm 命令得到 DDclient 文件列表:

[root@bigboy tmp]# rpm -ql ddclient
...
/usr/doc/ddclient-3.6.3/README
...
[root@bigboy tmp]# 

也可以替代使用 locate 命令去查找 DDclient 文件:

[root@bigboy tmp]# locate ddclient | grep READ
/usr/doc/ddclient-3.6.3/README
/usr/doc/ddclient-3.6.3/README.cisco
[root@bigboy tmp]# 

如果命令不起作用,尝试升级你的locate数据库,使用locate -u 命令:

[root@bigboy tmp]# locate -u 


测试你的动态DNS

你可以通过一下方式测试你的动态DNS:

  • 查询你DNS供应商的状态页面,确认匹配你站点的ip地址和你的路由器/防火墙的公网ip地址一样.
    * 在Linux命令提示符下使用 "host www.my-site.com" 命令去确认能不能得到反应.如果失败,你可以看到下面的错误信息:
[root@bigboy tmp]# host www.my-site.com
Server: 127.0.0.1Address: 127.0.0.1#53
**server can't find www.my-site.com: NXDOMAIN

这个错误信息是因为你的域名没有在互联网上传递.你可强制NS直接到域名服务器以确认所有的事情是对的.下面的列子就是查询miniDNS域名服务器 ns1.minidns.net:

[root@bigboy tmp]# host www.my-site.com ns1.minidns.net
www.my-site.com has address 97.158.253.26
[root@bigboy tmp]# 

结尾

Always remember that dynamic DNS works, but it is frequently unreliable as residential class broadband data circuits are not monitored, maintained, or managed as closely as business class lines. It is a good starting place to help you become familiar with Web hosting, but as your Web site becomes busier and more financially important to you, you may need to consider a regular data center far away from spilt coffee and the washing machine that always trips the circuit breakers.