简介
本文档介绍如何为思科路由器配置域名系统 (DNS)。
先决条件
要求
Cisco 建议您了解以下主题:
-
Cisco IOS®命令行界面(CLI)
-
一般 DNS 行为
使用的组件
本文档不限于特定的软件和硬件版本。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您的网络处于活动状态,请确保您了解所有命令的潜在影响。
规则
有关文件规则的更多信息请参见“ Cisco技术提示规则”。
设置路由器以使用DNS查找
如果希望以主机名而不是IP地址使用ping
或traceroute
命令,则可将路由器配置为使用DNS查找。请使用以下命令执行此操作:
命令 |
描述 |
IP 域名查找 |
启用基于 DNS 的主机名到地址转换。默认情况下此指令被启用。 |
ip name-server
|
指定一个或多个名称服务器的地址。 |
ip domain list |
定义一个域列表,将依次尝试每个域。
注意:如果没有域列表,将使用您通过ip domain-name全局配置命令指定的域名。
如果有域列表,则不使用默认域名。 |
IP 域名 |
定义一个默认域名,由 Cisco IOS 软件用来将未限定的主机名(没有点分十进制域名的名称)补充完整。请勿包括将未限定的名称从域名分离的初始阶段。 |
ip ospf name-lookup |
配置开放最短路径优先 (OSPF),以便在所有 OSPF show EXEC 命令显示的结果中查找可供使用的 DNS 名称。此功能有助于更轻松地识别路由器,因为这样一来路由器会按名称显示,而不是按自己的路由器 ID 或邻居 ID 显示。 |
下面显示了为进行基本的 DNS 查找而在某个路由器上所做的配置示例:
基本 DNS 查找配置示例 |
Router#show running-config
Building configuration...
Current configuration : 3922 bytes
!
! Last configuration change at 16:24:57 UTC Fri May 12 2023
!
version 17.3
service timestamps debug datetime msec
service timestamps log datetime msec
! Call-home is enabled by Smart-Licensing.
service call-home
platform qfp utilization monitor load 80
platform punt-keepalive disable-kernel-core
platform console serial
!
hostname Router
!
boot-start-marker
boot-end-marker
!
!
!
no aaa new-model
!
!
!
!
!
!
!
ip name-server 192.168.1.1
!--- Configures the IP address of the name server. !--- Domain lookup is enabled by default.
!
!
interface GigabitEthernet1
ip address 192.168.1.10 255.255.255.0
negotiation auto
no mop enabled
no mop sysid
! !
!--- Output Suppressed. end |
Router#ping www.cisco.com
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.37.145.84, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
Router#
故障排除
在极少数情况下,您会看到以下错误情况之一:
Router#debug ip udp
UDP packet debugging is on
Router#ping www.cisco.com
*Mar 8 06:26:41.732: UDP: sent src=10.69.16.66(5476), dst=10.250.35.250(53), length=59
*Mar 8 06:26:44.740: UDP: sent src=10.69.16.66(5476), dst=10.250.35.250(53), length=59
*Mar 8 06:26:47.744: UDP: sent src=10.69.16.66(5476), dst=10.250.35.250(53), length=59
% Unrecognized host or address, or protocol not running.
Router#undebug all
All possible debugging has been turned off
Router#ping www.cisco.com
Translating "www.cisco.com"...domain server (172.16.249.4) ¡¦
Not process
Router#ping www.cisco.com
*May 12 16:48:36.302: Reserved port 43478 in Transport Port Agent for UDP IP type 1
*May 12 16:48:36.302: UDP: sent src=0.0.0.0(43478), dst=255.255.255.255(53), length=50
*May 12 16:48:37.303: Reserved port 56191 in Transport Port Agent for UDP IP type 1
*May 12 16:48:37.303: UDP: sent src=0.0.0.0(56191), dst=255.255.255.255(53), length=50
*May 12 16:48:37.304: Released port 43478 in Transport Port Agent for IP type 1
*May 12 16:48:37.304: Released port 43478 in Transport Port Agent for IP type 1%
Unrecognized host or address, or protocol not running.
要对此问题进行故障排除,请完成以下步骤:
-
确保路由器能到达 DNS 服务器。从路由器上使用其IP地址ping DNS服务器,并确保已使用ip name-server命令在路由器上配置DNS服务器的IP地址。
-
通过以下步骤确保路由器转发查找请求:
-
定义在 DNS 数据包上匹配的访问控制列表 (ACL):
access-list 101 permit udp any any eq domain
access-list 101 permit udp any eq domain any
-
使用debug ip packet 101命令。
注意:请确保指定ACL。如果在未指定ACL的情况下启用debug ip packet命令,可能会向控制台中生成大量输出,从而影响对设备的访问。
-
确保您在路由器上启用ip domain-lookupcommand。
可以 ping 通 Web 服务器却无法查看 HTML 页面
在极少数情况下,您无法通过名称访问特定网站。此问题通常是由对源IP地址执行反向DNS查找以验证地址是否未伪装的不可访问站点导致的。如果返回了不正确的条目或没有返回任何条目(换句话说,没有与IP范围关联的名称),则可以阻止HTTP请求。
获取Internet域名时,还必须申请inaddr.arpa域。这个特殊的域也称为反向域。反向域会将数字 IP 地址映射到域名中。如果您的ISP提供您的域名服务器,或您的ISP从您自己的地址块中为您分配地址,则您无法自行申请in-addr.arpa域。请与您的 ISP 核实。
以下是使用www.cisco.com的示例。下一个输出是从UNIX工作站捕获的。使用nslookupprogram和dig程序。请注意以下输出中的差别:
sj-cse-280% nslookup www.cisco.com
Note: nslookup is deprecated and can be removed from future releases.
Consider with the 'dig' or 'host' programs instead. Run nslookup with
the '-sil[ent]' option to prevent this message from appearing.
Server: 172.16.226.120
Address: 172.16.226.120#53
Name: www.cisco.com
Address: 192.168.219.25
sj-cse-280% nslookup 192.168.219.25
Note: nslookup is deprecated and can be removed from future releases.
Consider with the 'dig' or 'host' programs instead. Run nslookup with
the '-sil[ent]' option to prevent this message from appearing.
Server: 172.16.226.120
Address: 172.16.226.120#53
10.219.133.198.in-addr.arpa name = www.cisco.com.
dig 程序输出了更多来自 DNS 数据包的详细信息:
sj-cse-280% dig 192.168.219.25
; <<>> DiG 9.0.1 <<>> 192.168.219.25
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 5231
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;192.168.219.25. IN A
;; AUTHORITY SECTION:
. 86400 IN SOA
A.ROOT-SERVERS.NET. nstld.verisign-grs.com.
( 2002031800 1800 900 604800 86400 )
;; Query time: 135 msec
;; SERVER: 172.16.226.120#53(172.16.226.120)
;; WHEN: Mon Mar 18 09:42:20 2002
;; MSG SIZE rcvd: 107
路由器查询多个名称服务器
根据网络活动级别,路由器可以查询配置中列出的多个名称服务器。下面是debug ip domain detail输出的示例:
Router#show run | section name-server ip name-server 192.168.1.1 10.0.0.2 Router#
Router#debug ip domain detail
Router#test002
*May 12 17:56:32.723: DNS: detail: cdns_name_verify_internal: Checking if hostname is valid or not..
*May 12 17:56:32.723: DNS: info: cdns_name_verify_internal: Hostname is valid
*May 12 17:56:32.723: DNS: detail: cdns_get_rr_type: converting name kind 2000 to type 28
*May 12 17:56:32.723: DNS: detail: read_forwards: Forward zone server list:
*May 12 17:56:32.723: DNS: info: delegpt_log: DelegationPoint<.>: 0 names (0 missing), 2 addrs (0 result, 2 avail) parentNS
*May 12 17:56:32.724: DNS: detail: val_operate: validator[module 0] operate: extstate:module_state_initial event:module_event_new
*May 12 17:56:32.724: DNS: info: log_nametypeclass: validator operate: query test002. AAAA IN
*May 12 17:56:32.724: DNS: detail: iter_operate: iterator[module 1] operate: extstate:module_state_initial event:module_event_pass
*May 12 17:56:32.724: DNS: info: log_nametypeclass: resolving test002. AAAA IN
*May 12 17:56:32.724: DNS: detail: error_response: return error response NXDOMAIN
*May 12 17:56:32.724: DNS: detail: val_operate: validator[module 0] operate: extstate:module_wait_module event:module_event_moddone
*May 12 17:56:32.724: DNS: info: log_nametypeclass: validator operate: query test002. AAAA IN
*May 12 17:56:32.725: DNS: detail: cdns_get_rr_type: converting name kind 2000 to type 28
*May 12 17:56:32.725: DNS: detail: read_forwards: Forward zone server list:
*May 12 17:56:32.725: DNS: info: delegpt_log: DelegationPoint<.>: 0 names (0 missing), 2 addrs (0 result, 2 avail) parentNS
*May 12 17:56:32.726: DNS: detail: val_operate: validator[module 0] operate: extstate:module_state_initial event:module_event_new
*May 12 17:56:32.726: DNS: info: log_nametypeclass: validator operate: query test002. AAAA IN
*May 12 17:56:32.726: DNS: detail: iter_operate: iterator[module 1] operate: extstate:module_state_initial event:module_event_pass
*May 12 17:56:32.726: DNS: info: log_nametypeclass: resolving test002. AAAA IN *May 12 17:56:32.726: DNS: info: log_nametypeclass: processQueryTargets: test002. AAAA IN *May 12 17:56:32.726: DNS: info: log_nametypeclass: sending query: test002. AAAA IN *May 12 17:56:32.726: DNS: detail: log_name_addr: sending to target: <.> 192.168.1.1#53 *May 12 17:56:32.726: DNS: detail: cdns_get_first_hop: dst 192.168.1.1, intf GigabitEthernet1
*May 12 17:56:32.726: DNS: detail: cdns_set_udp_source_interface: using source interface GigabitEthernet1 with address 192.168.1.10
*May 12 17:56:33.726: DNS: detail: cdns_get_first_hop: dst 192.168.1.1, intf GigabitEthernet1
*May 12 17:56:33.726: DNS: detail: cdns_set_udp_source_interface: using source interface GigabitEthernet1 with address 192.168.1.10
*May 12 17:56:34.726: DNS: detail: iter_operate: iterator[module 1] operate: extstate:module_wait_reply event:module_event_noreply
*May 12 17:56:34.726: DNS: info: log_nametypeclass: iterator operate: query test002. AAAA IN
*May 12 17:56:34.726: DNS: info: log_nametypeclass: processQueryTargets: test002. AAAA IN
*May 12 17:56:34.727: DNS: info: log_nametypeclass: sending query: test002. AAAA IN
*May 12 17:56:34.727: DNS: detail: log_name_addr: sending to target: <.> 192.168.1.1#53
*May 12 17:56:34.727: DNS: detail: cdns_get_first_hop: dst 192.168.1.1, intf GigabitEthernet1
*May 12 17:56:34.727: DNS: detail: cdns_set_udp_source_interface: using source interface GigabitEthernet1 with address 192.168.1.10
*May 12 17:56:35.729: DNS: detail: iter_operate: iterator[module 1] operate: extstate:module_wait_reply event:module_event_reply
*May 12 17:56:35.729: DNS: info: log_nametypeclass: iterator operate: query test002. AAAA IN
*May 12 17:56:35.729: DNS: info: log_nametypeclass: response for test002. AAAA IN
*May 12 17:56:35.729: DNS: info: log_name_addr: reply from <.> 192.168.1.1#53 *May 12 17:56:35.729: DNS: info: processQueryResponse: query response was THROWAWAY
*May 12 17:56:35.729: DNS: info: log_nametypeclass: processQueryTargets: test002. AAAA IN
*May 12 17:56:35.729: DNS: info: log_nametypeclass: sending query: test002. AAAA IN *May 12 17:56:35.729: DNS: detail: log_name_addr: sending to target: <.> 10.0.0.2#53 *May 12 17:56:35.730: DNS: detail: cdns_get_first_hop: dst 10.0.0.2, intf GigabitEthernet1
*May 12 17:56:35.730: DNS: detail: cdns_set_udp_source_interface: using source interface GigabitEthernet1 with address 192.168.1.10
*May 12 17:58:35.732: DNS: error: comm_point_tcp_handle_write: tcp connect: Connection refused
*May 12 17:58:35.732: DNS: detail: log_addr: remote address is ip4 10.0.0.2 port 53 (len 16)
*May 12 17:58:35.732: DNS: detail: outnet_tcp_cb: outnettcp got tcp error -1
*May 12 17:58:35.732: DNS: detail: log_addr: tcp error for address ip4 10.0.0.2 port 53 (len 16)
*May 12 17:58:35.732: DNS: detail: iter_operate: iterator[module 1] operate: extstate:module_wait_reply event:module_event_noreply
*May 12 17:58:35.732: DNS: info: log_nametypeclass: iterator operate: query test002. AAAA IN
*May 12 17:58:35.732: DNS: info: log_nametypeclass: processQueryTargets: test002. AAAA IN
这是正常现象,在路由器需要为 DNS 服务器创建地址解析协议 (ARP) 条目时会出现这种情况。默认情况下,路由器会将一个 ARP 条目维持四个小时。在活动很少的时期,路由器需要将 ARP 条目补充完整,然后执行 DNS 查询。如果DNS服务器的ARP条目不在路由器ARP表中,那么如果它只发送一个DNS查询,您会收到错误消息。因此,要发出两条查询,一条用于获取 ARP 条目(如有必要),另一条用于执行实际的 DNS 查询。在 TCP/IP 应用中,这种现象很常见。
相关信息