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#

Tip

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 ...

Get Cisco IOS Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.