Previous section   Next section

Recipe 2.9 Enabling Domain Name Services

2.9.1 Problem

You want to configure your router to use DNS to resolve hostnames.

2.9.2 Solution

To configure the router to use DNS to resolve hostnames, you need to specify a domain name and at least one name server:

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#

2.9.3 Discussion

As we mentioned in Recipe 2.8, you can configure your router to use DNS to resolve hostnames. In fact, Cisco routers have DNS name resolution enabled by default. However, since there is no default name server, the router will attempt to use the local broadcast address (255.255.255.255) until you explicitly configure a proper name server. 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 name server, you can access any hostname 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 198.133.219.25, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 80/91/104 ms
Router1#

You can see that the router sent a DNS query to the name server (172.25.1.1) and asked it to translate the hostname www.cisco.com. The server responded with an IP address of 198.133.219.25. 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 have configured multiple name servers:

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 fictitious 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 first sent this query to the name server at 172.25.1.1. When this device was unable to resolve the name, the router resorted to the second name server, 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     198.133.219.25
Router1#

This command displays the domain name, the name servers (in their order of preference), and 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 in Recipe 2.8 is that the router will automatically flush the dynamic entries from the cache after a period of time. This time period is specified by the DNS server separately for each hostname; 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 organizations 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 and you have specified a domain name, the router will use the given domain name. However, as soon as you configure a domain list, the router will ignore the domain name. This is why we included the original domain name, oreilly.com, in the domain list example.

Again, the order of the domain list entries is important because the router will use it to build the FQDN for its queries. For example, if you sent a query for the host named mail, the router would correctly find it in either domain. However, if a host named mail exists in both domains, the router will connect to mail.ora.com instead of mail.oreilly.com: this is the order specified by the domain list. You can still connect to mail.oreilly.com by entering the full domain name.

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    198.133.219.25
freebsd                   None  (perm, OK) 0   IP    172.25.1.1
Router1#

2.9.4 See Also

Recipe 2.8


  Previous section   Next section
Top