Building a Host Table

Building a Host Table
A host table provides name resolution only on the router that it was built upon. The command
to build a host table on a router is as follows:
ip host host_name tcp_port_number ip_address
The default is TCP port number 23, but you can create a session using Telnet with a
different TCP port number if you want. You can also assign up to eight IP addresses to
a hostname.
Here’s an example of configuring a host table on the Corp router with two entries to resolve
the names for the R1 router and the ap device:
Corp#config t
Enter configuration commands, one per line. End with CNTL/Z.
Corp(config)#ip host R1 ?
<0-65535> Default telnet port number
A.B.C.D Host IP address
additional Append addresses
mx Configure a MX record
ns Configure an NS record
srv Configure a SRV record
Corp(config)#ip host R1 10.2.2.2 ?
A.B.C.D Host IP address

Corp(config)#ip host R1 10.2.2.2
Corp(config)#ip host ap 10.1.1.2
Notice in the previous router configuration that I can just keep adding IP addresses to reference
a host, one after another, up to eight IP address. And to see the newly built host table,
just use the show hosts command:
Corp(config)#do show hosts
Default domain is not set
Name/address lookup uses domain service
Name servers are 255.255.255.255
Codes: UN - unknown, EX - expired, OK - OK, ?? - revalidate
temp - temporary, perm - permanent
NA - Not Applicable None - Not defined
Host Port Flags Age Type Address(es)
ap None (perm, OK) 0 IP 10.1.1.2
R1 None (perm, OK) 0 IP 10.2.2.2
Corp(config)#^Z
Corp#
You can see the two hostnames plus their associated IP addresses in the preceding router
output. The perm in the Flags column means the entry is manually configured. If it said temp,
it would be an entry that was resolved by DNS. Here is an example of a router resolving a hostname
and then telnetting to the resolved IP address:
Corp#r1
Trying R1 (10.2.2.2)... Open
User Access Verification
Password:
R1>Ctrl+Shift+6
Corp#ap
Trying ap (10.1.1.2)... Open
User Access Verification
Password:
ap>Ctrl+Shift+6
Corp#
Corp#sh sessions
Conn Host Address Byte Idle Conn Name
1 r1 10.2.2.2 0 1 r1
* 2 ap 10.1.1.2 0 0 ap
Corp#
If you want to remove a hostname from the table, just use the no ip host command, like
this:
RouterA(config)#no ip host R1
The problem with the host table method is that you would need to create a host table on
each router to be able to resolve names. And if you have a whole bunch of routers and want
to resolve names, using DNS is a much better choice!

Resolving Hostnames

Resolving Hostnames
To use a hostname rather than an IP address to connect to a remote device, the device that you
are using to make the connection must be able to translate the hostname to an IP address.
You can resolve hostnames to IP addresses in two ways: building a host table on each router
or building a Domain Name System (DNS) server, which is similar to a dynamic host table.
Table 2.12 is a list of important commands that can be used to help you resolve hostnames on
a router:
TABLE 2 . 1 2 Hosts Table Commands
Command Meaning
ip host Creates a static host table on your router
show hosts Displays the host table on your router
ip domain-lookup Enables the DNS service
ip name-server Configures your device with the IP address of a DNS server
ip domain-name Configures domain suffix for fully qualified domain name

Closing Telnet Sessions

Closing Telnet Sessions
You can end Telnet sessions a few different ways—using exit or disconnect is probably the
easiest and quickest:
ap>exit
[Connection to 10.1.1.2 closed by foreign host]
Corp#
Since the ap device was my last session, I just pressed Enter twice to return to that session.
To end a session from a local device, use the disconnect command:
Corp#sh session
Conn Host Address Byte Idle Conn Name
2 10.2.2.2 10.2.2.2 0 0 10.2.2.2
Corp#disconnect ?
<0-0> The number of an active network connection
qdm Disconnect QDM web-based clients
ssh Disconnect an active SSH connection
Corp#disconnect 2
Closing connection to 10.2.2.2 [confirm][enter]
Corp#
If you want to end a session of a device attached to your local device through Telnet, you
should first check to see whether any devices are telnetted into your router. To get that information,
use the show users command like this:
R1#sh users
Line User Host(s) Idle Location
* 0 con 0 idle 00:00:00
vty 194 idle 00:00:21 10.2.2.1
This output shows that VTY has IP address 10.2.2.1 connected. That’s the Corp router.
Also notice that the Corp router connected to line 194—remember, you cannot choose which
line you connect to! This is why I set the same password on all lines.
To clear the connection, use the clear line # command:
R1#clear line 194
[confirm][enter]
[OK]
R1#sh users
Line User Host(s) Idle Location
* 0 con 0 idle 00:00:00
This output confirms that the line has been cleared.

Checking Telnet Users

Checking Telnet Users
You can list all active consoles and VTY ports in use on your router with the show users
command:
Corp#sh users
Line User Host(s) Idle Location
* 0 con 0 10.1.1.2 00:00:01
10.2.2.2 00:01:06
In the command’s output, con represents the local console. In this example, the console is
connected to two remote IP addresses or, in other words, two devices. In the next example, I
typed sh users on the ap device that the Corp router had telnetted into and that is connected
via line 1:
Corp#sh sessions
Conn Host Address Byte Idle Conn Name
1 10.1.1.2 10.1.1.2 0 0 10.1.1.2
* 2 10.2.2.2 10.2.2.2 0 0 10.2.2.2
Corp#1
[Resuming connection 1 to 10.1.1.2 ... ]
ap>sh users
Line User Host(s) Idle Location
* 1 vty 0 idle 00:00:00 10.1.1.1
ap>
This output shows that the console is active and that VTY port 1 is being used. The asterisk
represents the current terminal session from which the show user command was entered.

Checking Telnet Connections

Checking Telnet Connections
To see the connections made from your router to a remote device, use the show sessions
command, like so:
Corp#sh sessions
Conn Host Address Byte Idle Conn Name
1 10.2.2.2 10.2.2.2 0 0 10.2.2.2
* 2 10.1.1.2 10.1.1.2 0 0 10.1.1.2
Corp#
See that asterisk (*) next to connection 2? It means that session 2 was your last session. You
can return to your last session by pressing Enter twice. You can also return to any session by
typing the number of the connection and pressing Enter.