Using Static Hostname Tables:
You want to create a static host lookup table on the router.
The ip host command lets you configure static host entries in the router:
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:
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:
Then Telnet to this hostname connects to the SMTP process on the device:
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:
You can use the show hosts command to get a complete list of all of the static host definitions: