VMware ESXi and vSphere Cluster Management
Configure a Hostname on a Cisco IOS Device
Learn how to configure, verify, and save a Cisco IOS hostname on a router or switch using the command-line interface.
A hostname is the local name assigned to a Cisco IOS device. Cisco IOS is the operating system and command-line environment used by many Cisco routers and switches. The hostname appears in the CLI prompt, the text IOS displays before you enter a command.
A meaningful hostname helps administrators identify the correct device during console sessions, remote administration, troubleshooting, documentation, monitoring, and automation. For example, BRANCH1-RTR1 identifies a router at branch site 1, while HQ-ACC-SW01 identifies access switch 01 at headquarters.
Why Configure an IOS Hostname?
Without a useful hostname, multiple device sessions can look nearly identical. A clear prompt reduces the risk of entering a change on the wrong router or switch.
- Device identification: The prompt shows which device is currently receiving commands.
- Console administration: Local and remote operators can distinguish sessions more easily.
- Documentation: Diagrams, inventories, and configuration records can use a consistent device label.
- Troubleshooting: Command output and session notes are easier to associate with a specific device.
- Operations: Monitoring tools, terminal servers, scripts, and configuration-management systems can use the name as an inventory identifier.
Choose a consistent naming convention based on information such as location, site, building, rack, device role, device type, and sequence number. For example, HQ-ACC-SW01 can represent headquarters, the access layer, a switch, and device 01.
Hostname and DNS Are Different
Changing the IOS hostname changes the local device identity and the CLI prompt. It does not automatically create, update, or remove a DNS record.
DNS, the Domain Name System, is a separate name-resolution service. A DNS record maps a name to information such as an IP address. If an administrator changes the device hostname to LAB-R1, a DNS lookup for that name will not necessarily work. An appropriate DNS record must be created or updated through the organization's DNS administration process.
| Characteristic | IOS Hostname | DNS Name or Record |
|---|---|---|
| Purpose | Labels the local Cisco IOS device and appears in the CLI prompt. | Provides name resolution through DNS. |
| Where it is configured | In the device's IOS configuration. | On DNS servers or through a DNS management system. |
| Effect of changing it | Changes the local prompt and active hostname setting. | Changes how names resolve only when the DNS data is updated. |
| Automatic relationship | Does not automatically update DNS. | Does not automatically change the IOS prompt. |
IOS Command Modes for Hostname Configuration
IOS uses command modes to control which commands are available. The prompt usually indicates the current mode.
| Mode | Typical Prompt Indicator | How It Is Reached | Role in Hostname Configuration |
|---|---|---|---|
| User EXEC mode | >, such as Router> | Usually the initial mode after authentication. | Use enable to move to privileged EXEC mode. |
| Privileged EXEC mode | #, such as Router# | Enter enable from user EXEC mode. | Use configure terminal or conf t to enter global configuration mode. |
| Global configuration mode | (config)#, such as Router(config)# | Enter configuration mode from privileged EXEC mode. | Enter the hostname command here. |
The hostname command is a global configuration command. Entering it from user EXEC or privileged EXEC mode will not configure the hostname.
Hostname Naming Requirements
Use the traditional ARPANET-style hostname conventions when selecting a name:
- Begin with an alphabetic character.
- End with a letter or numeral.
- Use letters, numerals, and hyphens within the name.
- Do not use spaces.
- Do not use unsupported punctuation or symbols.
- Keep the hostname no longer than 63 characters.
These rules make names predictable and compatible with common network naming practices.
| Rule | Valid Example | Invalid Example | Reason |
|---|---|---|---|
| Start with a letter | BRANCH1-RTR1 | 1st-floor-switch | The invalid example begins with a digit. |
| Use letters, numerals, and hyphens | HQ-SW1 | HQ Switch 1 | The invalid example contains spaces. |
| End with a letter or numeral | LAB-R1 | LAB-R1- | The invalid example ends with a hyphen. |
| Stay within 63 characters | REMOTE-EDGE-RTR01 | THIS-NAME-EXCEEDS-THE-MAXIMUM-HOSTNAME-LENGTH-OF-SIXTY-THREE-CHARACTERS-01 | The invalid example is longer than the permitted maximum. |
Configure the Hostname
Connect to the router or switch through the console or an available remote management session. Authenticate when IOS requests credentials. The exact initial prompt may differ, but the procedure is the same once you reach the CLI.
Step 1: Enter privileged EXEC mode
From user EXEC mode, identified by a prompt ending in >, enter enable. IOS may request the privileged EXEC password.
Router> enable
Router#
Step 2: Enter global configuration mode
From privileged EXEC mode, identified by a prompt ending in #, enter configure terminal. The common abbreviation is conf t.
Router# configure terminal
Router(config)#
Step 3: Set the hostname
Enter hostname followed by the desired device name. This example names an access switch at headquarters.
Router(config)# hostname HQ-ACC-SW01
HQ-ACC-SW01(config)#
The prompt changes immediately after IOS accepts the command. The (config)# portion shows that the session remains in global configuration mode.
Step 4: Exit configuration mode
Use end to return directly to privileged EXEC mode, or use exit one level at a time.
HQ-ACC-SW01(config)# end
HQ-ACC-SW01#
Complete Configuration Sequence
enable
configure terminal
hostname HQ-ACC-SW01
end
copy running-config startup-config
Verify the Hostname
The changed prompt is the first immediate confirmation. From privileged EXEC mode, inspect the active configuration with:
HQ-ACC-SW01# show running-config | include hostname
hostname HQ-ACC-SW01
The running configuration is the active configuration currently held by the device. The command filters the displayed configuration so that the hostname line is easier to find.
Save the Hostname for a Reload
A change made to the running configuration is active immediately, but it may be lost after a reload if it has not been saved. The startup configuration is the saved configuration that IOS loads when the device reboots.
After verifying the name, save the running configuration to startup configuration:
HQ-ACC-SW01# copy running-config startup-config
Respond to any confirmation prompt according to the device's instructions. Saving is important when the hostname must survive a power cycle or reload.
Troubleshooting Hostname Configuration
The hostname command is rejected or unavailable
The session is probably not in global configuration mode. Enter privileged EXEC mode with enable, then enter configure terminal before issuing the hostname command.
The prompt does not show the expected name
The command may not have been accepted, the name may contain a spelling difference, or the session may be connected to a different device. Check the current prompt, run show running-config | include hostname from privileged EXEC mode, and confirm the physical or remote connection.
The former hostname returns after a reboot
The running configuration was probably not saved. Reapply the intended name if necessary, verify it, and use copy running-config startup-config.
The chosen hostname is refused
Check whether it begins with a letter, ends with a letter or numeral, uses only letters, numerals, and hyphens, contains no spaces or unsupported punctuation, and is no longer than 63 characters.
DNS cannot resolve the new name
An IOS hostname change does not modify DNS. Request creation or modification of the required DNS record through the organization's DNS process.
Operational Considerations
Before changing a hostname on a production device, consider systems and procedures that may expect the old prompt or device label. A hostname change can affect:
- Administrator runbooks and terminal-server labels.
- Monitoring and alerting systems.
- Automation scripts that match prompts or inventory names.
- Configuration-management workflows.
- Network diagrams, asset inventories, and maintenance records.
- External DNS information, which must be updated separately when required.
Use a name that is unique enough to prevent operators from confusing devices during remote sessions. After the change, update network documentation and external inventory systems according to organizational procedures.
Summary
- The IOS hostname is the local device name displayed in the CLI prompt.
- Configure it from global configuration mode with
hostname <device-name>. - Use letters, numerals, and hyphens; begin with a letter, end with a letter or numeral, and stay within 63 characters.
- Verify the active setting with
show running-config | include hostname. - Save the change with
copy running-config startup-configwhen it must survive a reload. - Changing the IOS hostname does not automatically change DNS.