簡介
本文說明如何設定適用於思科路由器的網域名稱系統 (DNS)。
必要條件
需求
思科建議您瞭解以下主題:
-
Cisco IOS® 命令列介面 (CLI)
-
一般 DNS 行為
採用元件
本文件所述內容不限於特定軟體和硬體版本。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
慣例
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
設定路由器以執行 DNS 查詢
如果希望以主機名而不是IP地址使用ping
或traceroute
命令,則可將路由器配置為使用DNS查詢。如要這麼做,請使用以下命令:
指令 |
說明 |
ip domain lookup |
啟用 DNS 將主機名稱轉換為位址的功能,此命令預設為啟用。 |
ip name-server
|
指定一或多個名稱伺服器的位址。 |
ip domain list |
定義網域清單,依序嘗試每個網域。
附註:如果沒有網域清單,系統會使用您透過 ip domain-name 全域設定命令指定的網域名稱。
如有網域清單,系統便不會使用預設的網域名稱。 |
ip domain name |
定義 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 位址對 DNS 伺服器執行 ping,請務必使用 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-lookup 命令。
您可以對 Web 伺服器執行 ping,但無法查看 HTML 網頁
在極少數情況下,您無法按名稱訪問特定網站。會發生這個問題,通常是因為無法存取的網站為了驗證來源 IP 位址非詐騙,而對其執行反向 DNS 查詢。如果項目有誤或未傳回項目(換句話說,該 IP 範圍沒有相關聯的名稱),HTTP 要求就會遭到封鎖。
當您取得網際網路網域名稱時,也必須申請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 查詢。如果路由器 ARP 表中沒有 DNS 伺服器的 ARP 項目,只傳送一個 DNS 查詢就會執行失敗。因此,您必須傳出兩個查詢,一個用於取得 ARP 項目(如有必要),第二個用於實際執行 DNS 查詢。此行為在 TCP/IP 應用中很常見。
相關資訊