Resolving Names on IOS

When working with advanced configuration such as routing and access lists on IOS based devices, you will often refer to other devices. There are two ways to refer to another device – using the IP address or hostnames. Remembering and using IP address of various devices is difficult and often cumbersome to troubleshoot. Hence, IOS provides two ways to map names to IP address.

The first method is to use a DNS server that you might already have in the network. You can simply add the IP address of the DNS server using the ip name-server command as shown below:

myRouter(config)#ip name-server 192.168.1.34 192.168.1.35

Notice that I added two DNS servers in the above example. You can add as many as you want. The IOS will try to get a response from each server sequentially till it gets a response. Once you have added a DNS server, every time the device encounters a name, it will try to resolve it by querying the server.

The second method is to create a mapping of names to IP addresses on the IOS itself. These mappings constitute what is also known as the host tables.

Remember this does not make the IOS a DNS server, but simply creates a local list for the router. You can use the ip host name ip_address command to do this as shown below:

myRouter(config)#ip host Router1 192.168.1.2

In the above command, I mapped the name Router1 to the IP address 192.168.1.2. Now whenever the device comes across the name Router1, it will translate it to 192.168.1.2 as can be seen in the example below.

myRouter#ping Router1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
In the above example notice that the router resolved the name in the ping command to the IP address.

Using DHCP

From the previous chapter, you would remember that DHCP is used to dynamically provide IP address to hosts in a network. An IOS device can be configured to receive as well as give out IP address. What this means is that the device can be a DHCP client as well as a DHCP server.

When you configure the device as a DHCP client, it takes an IP address from a DHCP server for its interface. To configure the interface to take the IP address from DHCP server use the ip address dhcp command in the interface configuration mode. After that, when the interface is bought up, it will start requesting for an IP addresses.

To configure the device as a DHCP server, you need to define a pool that consists of the subnet from which the device will give out addresses. Apart from the addresses, you can also configure other parameters such as DNS server and default gateway that can be sent to the client. To create the pool, use the ip dhcp pool pool-name command in the global configuration mode. This command will create the pool and bring you to the DHCP configuration mode (the prompt will change to dhcp-config). Here you can use the network, dns-server and default-router commands to define the subnet, DNS server and the gateway address as shown below:

myRouter(config)#ip dhcp pool test
myRouter(dhcp-config)#network 192.168.1.0 /24
myRouter(dhcp-config)#dns-server 192.168.1.34
myRouter(dhcp-config)#default-router 192.168.1.1

One thing you may have noticed is that the entire subnet of 192.168.1.0/24 has assigned to the pool. However this also contains the addresses that has already been assigned to the router interface and the DNS server. You will need to exclude these addresses from the pool. This can be done using the ip dhcp excluded-ddress ip_address command as shown below:

myRouter(config)#ip dhcp excluded-address 192.168.1.1
myRouter(config)#ip dhcp excluded-address 192.168.1.34