10.3 Configure a hostname
You will now have an opportunity to configure a hostname on the router. The main reason for configuring a hostname on a device is to easily identify the device when accessing it remotely. For example, if you are working from an office in Milton Keynes but you are configuring a router physically located in London, the only reference you have via the command line is the hostname. It is possible that you could be connected to multiple routers at the same time, so it is important to establish the correct and identifiable hostname before you change the configuration of the device.
Watch the video below (which is about 2 minutes long) to see how to configure a hostname on a router.
Add a hostname
The task for this part is to configure the router with the hostname ‘Piccadilly’. We are connected to an unconfigured router. If we are asked about the configuration wizard, remember to answer no. Then we need to get into global configuration mode. First we need to enter privileged exec mode by typing enable. Then we can type configure terminal. The prompt will change, and then we are in the configuration mode. We could use the question mark to find out the command, but there are a lot of options in this mode. The command that we need to use is hostname. If you get stuck half way through a command you can use the question mark to get help: it will tell you what options can be used with that command. If I use the question mark, we can see that the command needs a word as stated in the CLI. This word is what you want the router to be named. We want this router to be called ‘Piccadilly’, so the full command will be hostname Piccadilly. As you hit Return you will see the prompt change to ‘Piccadilly’. This configuration change will take immediate effect, as this is now part of the running configuration. This is the configuration the router is using to make any decisions currently.
If we want the changes to still be effective after a reboot, we will need to save the configuration to the startup configuration. When the router turns on it copies the startup configuration to the running configuration and then continues to make decisions based on this running configuration. We can save the config by going back to privileged exec mode with the command exit, then use the command copy running-config startup-config. Now the configuration is saved. If the router was to restart now, the configuration of the device would come back to the same state. In the next part we will look at configuring an IP address via the command-line interface.
It is highly recommended to set a hostname on every router or switch. You need to be aware that there are rules for hostnames. For example, a hostname must not exceed 63 characters. It must start and end with a letter or digit, and contain only letters, digits, or hyphens.
Activity 3 Try it out
Open PT Anywhere [Tip: hold Ctrl and click a link to open it in a new tab. (Hide tip)] in a new tab or window so you can read these instructions.
- Select the router, open the CLI tab, then go to the appropriate configuration mode to configure a hostname.
- Configure the hostname ‘Coventry’ on the device and save the configuration.
You should have used the command enable to enter the privileged exec mode, and then the command configure terminal to enter global configuration mode. The next step was to enter the command hostname Coventry. Following this you should have noticed the prompt change from Router (config)# to Coventry (config)#. To save the change you should have entered the command exit to return to privileged exec mode and then used the command copy running-config startup-config.
You’ve now used the commands in the CLI to configure a hostname on a router. Now you know which router you are connected to, you can start making configuration changes. The next section will explain how to set an IP address on a router.