You want to configure your router to use DNS to resolve hostnames.
To configure the router to use DNS to resolve hostnames, you need to specify a domain name and at least one nameserver:
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#ip domain-lookup Router1(config)#ip domain-name oreilly.com Router1(config)#ip name-server 172.25.1.1 Router1(config)#ip name-server 10.1.20.5 Router1(config)#end Router1#
As we mentioned in Recipe 2.10, you can configure your router to use Domain Name Service (DNS) to resolve hostnames. In fact, Cisco routers have DNS name resolution enabled by default. However, since there is no default nameserver, the router will attempt to use the local broadcast address, 255.255.255.255, until you explicitly configure a proper nameserver. This means that the ip domain-lookup configuration command in the example is necessary only if someone has explicitly disabled DNS on the router.
After you configure the router with a valid nameserver, you can access any hostname that is known by your DNS server. For example, our DNS server exchanges information with the public Internet, so we can ping the Cisco web page by name:
Router1#ping www.cisco.com Translating "www.cisco.com"...domain server (172.25.1.1) [OK] Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 188.8.131.52, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 80/91/104 ms Router1#
You can see in this output that the router sent a DNS query to the nameserver, 172. 25.1.1, and asked it to translate the hostname www.cisco.com. The server responded with an IP address of 184.108.40.206. The router then behaved as if we had simply asked it to ping this destination IP address instead of the hostname.
In this example, we configure multiple nameservers:
Router1(config)#ip name-server 172.25.1.1 Router1(config)#ip name-server 10.1.20.5
The router will send its queries to these servers in the order that we entered them. For example, suppose we tried to ping a factitious host, cookbook.oreilly.com:
Router1#ping cookbook.oreilly.com Translating "cookbook.oreilly.com"...domain server (172.25.1.1)(10.1.20.5) % Unrecognized host or address, or protocol not running. Router1#
As you can see, the router sent this query first to the nameserver at 172.25.1.1. When this device was unable to resolve the name, the router resorted to the second nameserver, 10.1.20.5. Ultimately the query failed because the hostname doesn't exist.
You can view the DNS configuration parameters with the show hosts command:
Router1#show hosts Default domain is oreilly.com Name/address lookup uses domain service Name servers are 172.25.1.1, 10.1.20.5 Host Port Flags Age Type Address(es) www.cisco.com None (temp, OK) 0 IP 220.127.116.11 Router1#
This command displays the domain name, the nameservers (in their order of preference), as well recently resolved hostnames. The router keeps a name cache of recently resolved names to prevent unnecessary DNS lookups on successive attempts to the same host. The difference between these dynamically learned hosts and the statically configured ones that we saw last chapter is that the router will automatically flush the dynamic entries from the cache after a period of time. This time period is actually specified by the DNS server separately for each hostname, so you cannot change it on the router.
The ip domain-name command allows you to specify your network's domain name:
Router1(config)#ip domain-name oreilly.com
When you configure a domain name like this, you can work with just the local hostname instead of the Fully Qualified Domain Name (FQDN). For example, you could type mail instead of mail.oreilly.com, and the router would resolve it correctly.
Some organization use more than one domain name. You can configure the router to use multiple domain names by including several ip domain-list commands in the configuration. For example, we can configure the router to use a second registered domain name, ora.com:
Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#ip domain-list ora.com Router1(config)#ip domain-list oreilly.com Router1(config)#end Router1#
If no domain list is present but you do have a domain name, the router will use the domain name. However, as soon as you configure a domain list, the router will ignore the domain name. This is why we had to include the original domain name, oreilly.com, in the domain-list example.
Again, the order of the domain-list entries is important because this is how the router will build the FQDN it uses for its queries. For example, if you sent a query for the host named mail, the router would correctly find it in either domain. But if there was a host named mail in both domains, then the router would connect to mail.ora.com instead of mail.oreilly.com because the domain list specifies ora.com before oreilly.com. This doesn't prevent you from connecting to mail.oreilly.com; but you would have to specify the full name, rather than just mail.
The show hosts command output includes the domain list:
Router1#show hosts Default domain is oreilly.com Domain list: ora.com, oreilly.com Name/address lookup uses domain service Name servers are 172.25.1.1, 172.25.1.3, 10.1.20.5 Host Port Flags Age Type Address(es) www.cisco.com None (temp, OK) 0 IP 18.104.22.168 freebsd None (perm, OK) 0 IP 172.25.1.1 Router1#
Router Configuration and File Management
User Access and Privilege Levels
Handling Queuing and Congestion
Tunnels and VPNs
NTP and Time
Router Interfaces and Media
Simple Network Management Protocol
First Hop Redundancy Protocols
Appendix 1. External Software Packages
Appendix 2. IP Precedence, TOS, and DSCP Classifications