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.
There
are two ways to resolve hostnames to IP addresses: building a host table on
each router or building a Domain Name System (DNS) server.
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
Corp(config)#ip host R1 10.2.2.2
Corp(config)#ip host ap 10.1.1.2
Notice
in the above 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
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 that the entry is manually
configured. If it said temp, it would be an entry that was resolved by DNS.
To
verify that the host table resolves names, try typing the hostnames at a router
prompt. Remember that if you don’t specify the command, the router assumes you
want to telnet.
In
the following example, I’ll use the hostnames to telnet into the remote devices
and press
Ctrl+Shift+6
and then X to return to the main console of the Corp router:
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#
Notice
that the entries in the show sessions output now display the hostnames and IP
addresses instead of just the IP addresses:
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, using DNS is a much better choice!
Using DNS to Resolve Names
Any
time a Cisco device receives a command it doesn’t understand, it will try to
resolve it through DNS by default. Watch what happens when I type the special
command todd at a Cisco router prompt:
Corp#todd
Translating “todd”...domain server (255.255.255.255)
Translating “todd”...domain server (255.255.255.255)
Translating “todd”...domain server (255.255.255.255)
% Unknown command or computer name, or unable to find
computer address
Corp#
It
doesn’t know my name or what command I am trying to type, so it tries to
resolve this through DNS. This is really annoying because I need to wait for
the name lookup to time out.
You
can prevent a time-consuming DNS lookup by using the no ip domain-lookup
command on your router from global configuration mode.
If
you have a DNS server on your network, you need to add a few commands to make
DNS name resolution work:
-
The first command is ip domain-lookup, which is turned on by
default.
_
The second command is ip name-server. This sets the IP address of
the DNS server. You can enter the IP addresses of up to six servers.
_
The last command is ip domain-name. Although this command is
optional, it really should be set.
Here’s
an example of using these three commands:
Corp#config t
Corp(config)#ip domain-lookup
Corp(config)#ip name-server 192.168.0.70
Corp(config)#ip domain-name lammle.com
After
the DNS configurations are set, you can test the DNS server by using a hostname
to ping or telnet a device like this:
Corp#ping
R1
use
the show hosts command to see that the device cached this information in the
host table:
Corp#sh hosts
Default domain is lammle.com
Name/address lookup uses domain service
Name servers are 192.168.0.70
Host Flags Age Type Address(es)
R1 (temp, OK) 0 IP 10.2.2.2
ap (perm, OK) 0 IP 10.1.1.2
Corp#
The
entry that was resolved is shown as temp, but the ap device is still perm,
meaning that it’s a static entry. Notice that the hostname is a full domain
name. If I hadn’t used the ip domain-name lammle.com command, I would have
needed to type in ping r1.lammle.com, which is a pain.
No comments:
Post a Comment