.NODE

Using Static Hostname Tables

Problem

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

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#

 

Discussion

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

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 nameservers. If you have both DNS and static host definitions, the router will prefer the static entries. 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. So they don't respond to IP address changes without manual intervention. The biggest advantage to static entries is that being static, they don't depend on the reliability of any external servers. If you tie some critical function to a hostname instead of an IP address, you don't want that function to go away just because the DNS server became temporarily unreachable.

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

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, which is the TCP port that the router will connect to when you use Telnet to connect to 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#

Then Telnet to this hostname connects 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#

Notice that the router connected 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#

 

See Also

Recipe 2.11


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

show all menu





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

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