Previous section   Next section

Recipe 2.8 Using Static Hostname Tables

2.8.1 Problem

You want to create a static host lookup table on the router.

2.8.2 Solution

The ip host command lets you configure static host entries in the router:

Router1#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#ip host freebsd 172.25.1.1
Router1(config)#ip host router2 10.1.1.1 172.22.1.4
Router1(config)#end
Router1#

2.8.3 Discussion

Many of the router commands will accept a hostname in place of an IP address. This helps to make the configuration files more readable, because it is much easier for humans to work with device names rather than IP addresses. However, the router still needs to translate these names into the IP addresses that it prefers to work with. Cisco supports two methods for resolving hostnames into IP addresses. You can use either static host entries as in this recipe, or DNS as in Recipe 2.9.

Static host entries are strictly local to the router. The router does not share this information with other routers or other devices. And, unlike DNS, static host entries are not dependent on any external services such as name servers. If you have both DNS and static host definitions, the router will use the static entries where possible. This allows you to override the normal DNS if you don't want to use it.

The biggest problem with static entries is, quite simply, that they are static and don't respond to IP address changes without manual intervention. The biggest advantage to static entries is that they don't depend on the reliability of any external servers. If you tie a critical function to a hostname instead of an IP address, that function may go away if the DNS server is temporarily unreachable.

For this reason, we strongly recommend using static host entries rather than DNS if you use hostnames in your router configuration instead of IP addresses.

In the example, the host called router2 has more than one IP address:

Router1(config)#ip host router2 10.1.1.1 172.22.1.4

When you associate multiple addresses with a single hostname like this, the router will attempt to connect to each address in the specified order. When building a static host entry for a neighboring router, you may wish to start with the loopback IP address followed by its other reachable IP addresses.

The ip host command also accepts a port number; this is the TCP port that the router will connect to when you use Telnet to reach the specified hostname. By default, the telnet command will initiate a connection to TCP port 23. In the following example, we will define a host named mail, and instruct the router to use port 25 (SMTP) when making connections to this device:

Router1#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#ip host mail 25 172.25.1.1
Router1(config)#end
Router1#

Telneting now connects you to the SMTP process on the device:

Router1#telnet mail
Trying mail (172.25.1.1, 25)... Open
220 freebsd.oreilly.com ESMTP Postfix
quit
221 Bye
   
[Connection to mail closed by foreign host]
Router1#

The router connects directly to the host's mail port, port 25. You can override the defined host port at the command prompt by including the required port number at the end of the telnet command:

Router1#telnet mail 25

You can use the show hosts command to get a complete list of all of the static host definitions:

Router1#show hosts
Default domain is not set
Name/address lookup uses static mappings
   
Host                      Port  Flags      Age Type   Address(es)
freebsd                   None  (perm, OK)  0   IP    172.25.1.1
router2                   None  (perm, OK)  0   IP    10.1.1.1
                                                      172.22.1.4
mail                      25    (perm, OK)  0   IP    172.25.1.1
Router1#

2.8.4 See Also

Recipe 2.9


  Previous section   Next section
Top