Enabling Domain Name Services

Problem

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

Solution

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#

Starting in IOS Version 12.2, Cisco changed the command syntax from ip domain-lookup to ip domain lookup. They also changed the command syntax from ip domain-name to ip domain name. The new IOS software still accepts previous versions of the commands.

 

Discussion

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

 

See Also

Recipe 2.10

Router Configuration and File Management

Router Management

User Access and Privilege Levels

TACACS+

IP Routing

RIP

EIGRP

OSPF

BGP

Frame Relay

Handling Queuing and Congestion

Tunnels and VPNs

Dial Backup

NTP and Time

DLSw

Router Interfaces and Media

Simple Network Management Protocol

Logging

Access-Lists

DHCP

NAT

First Hop Redundancy Protocols

IP Multicast

IP Mobility

IPv6

MPLS

Security

Appendix 1. External Software Packages

Appendix 2. IP Precedence, TOS, and DSCP Classifications

Index



Cisco IOS Cookbook
Cisco IOS Cookbook (Cookbooks (OReilly))
ISBN: 0596527225
EAN: 2147483647
Year: 2004
Pages: 505

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net