CCNA online course

How to Configure and Verify Hostnames on Cisco IOS Devices

Learn how to set, verify, save, rename, and troubleshoot Cisco IOS router and switch hostnames using the CLI.

A hostname is the locally configured name of a Cisco IOS device. Cisco IOS, the operating system used by many Cisco routers and switches, displays this name in the command-line interface (CLI) prompt.

For example, a device named BRANCH1-RTR1 displays prompts such as BRANCH1-RTR1> in user EXEC mode and BRANCH1-RTR1# in privileged EXEC mode.

Meaningful, unique hostnames make console and SSH sessions easier to identify. They also improve network diagrams, inventory records, troubleshooting, logging, and remote administration. Changing a hostname is a local configuration change; it does not change the device IP address, DNS records, or network connectivity by itself.

Cisco IOS Command Modes

IOS uses command modes to control which commands are available. Hostname configuration is performed in global configuration mode.

ModeTypical PromptHow to EnterPurpose
User EXECRouter>Initial mode after accessLimited monitoring and basic commands
Privileged EXECRouter#Enter enable from user EXECAdministrative monitoring and access to configuration modes
Global configurationRouter(config)#Enter configure terminal from privileged EXECDevice-wide configuration settings, including the hostname

The symbols are useful clues: > normally indicates user EXEC mode, # indicates privileged EXEC mode, and (config)# indicates global configuration mode.

View the Current Hostname

Unconfigured Cisco devices commonly use a default name such as Router or Switch. The current name appears at the beginning of the prompt.

You can also inspect the active configuration. The hostname statement is near the beginning of the configuration:

Router# show running-config | include ^hostname
hostname Router

The running-config is the active configuration held in RAM. To see more context, use:

Router# show running-config

The filter | include ^hostname displays lines that begin with hostname. The caret character, ^, helps avoid matching unrelated text later in a line.

Configure a Hostname

Enter privileged EXEC mode, enter global configuration mode, and then use hostname followed by the desired name.

Router> enable
Router# configure terminal
Router(config)# hostname BRANCH1-RTR1
BRANCH1-RTR1(config)#

The prompt changes immediately after IOS accepts the command. This confirms the name currently used by the CLI, but you should still verify the configuration explicitly.

To rename an already configured device, issue the command again with the new value:

BRANCH1-RTR1(config)# hostname BRANCH1-EDGE-RTR1
BRANCH1-EDGE-RTR1(config)#

Hostname Naming Conventions and Restrictions

Use a naming standard that lets an administrator identify a device without opening its configuration. A practical format can include the site, device role, and sequence number.

Name ComponentMeaningExample
Site identifierOffice, campus, branch, or buildingHQ
Device roleFunction or device typeACC-SW
Device sequence numberIdentifies one device among similar devices01

For example, HQ-ACC-SW01 identifies access-layer switch 01 at headquarters. A branch router could use BRANCH1-RTR1.

  • Keep names concise, meaningful, and unique within the organization.
  • Use a documented format consistently across routers, switches, and other managed devices.
  • Avoid spaces. A simple combination of letters, numbers, and hyphens is usually easier to operate and document.
  • Supported characters and maximum length can vary between IOS platforms and releases. If IOS rejects a name, follow the syntax shown by the device and use a simpler value.

An IOS hostname is not the same as a DNS fully qualified domain name (FQDN). A hostname is the local device name. A DNS domain name is a separate naming component used with DNS resolution. Changing the hostname alone does not create or update a DNS record.

Save the Hostname Configuration

Hostname changes initially modify the running-config, which is stored in RAM. The startup-config is the saved configuration in nonvolatile storage, traditionally NVRAM, and is loaded when the device starts.

If you do not save the change, a reload or power cycle can remove the new hostname and restore the previously saved configuration.

BRANCH1-RTR1(config)# end
BRANCH1-RTR1# copy running-config startup-config
Destination filename [startup-config]?
[Press Enter]
Building configuration...
[OK]

The alternative syntax commonly accepted on many IOS platforms is:

BRANCH1-RTR1# write memory

copy running-config startup-config is the explicit form commonly used in training and operations. Always check the command response and confirm that the save completed successfully.

Verify the Hostname and Persistence

Use several checks rather than relying only on the prompt.

TaskIOS CommandExpected Result
Enter privileged EXEC modeenableThe prompt changes from > to #.
Enter global configuration modeconfigure terminalThe prompt includes (config)#.
Set hostnamehostname BRANCH1-RTR1The prompt updates to the new hostname immediately.
View running hostname configurationshow running-config | include ^hostnameThe active configuration contains the expected hostname line.
Save running configurationcopy running-config startup-configThe active configuration is copied to saved storage.
View saved hostname configurationshow startup-config | include ^hostnameThe saved configuration contains the expected hostname line.
Restore default hostname behaviorno hostnameOn platforms that support it, the explicitly configured hostname is removed and platform default behavior returns.

To check persistence without restarting, compare the hostname lines in the running and startup configurations:

BRANCH1-RTR1# show running-config | include ^hostname
hostname BRANCH1-RTR1
BRANCH1-RTR1# show startup-config | include ^hostname
hostname BRANCH1-RTR1

A reload-based persistence check would involve saving the configuration, reloading the device, and confirming the prompt and configuration after startup. Reloading an active production router or switch is disruptive, so do not use this test casually. Perform it only during an approved maintenance window with an appropriate recovery plan.

Correct or Undo a Hostname

If a name contains a mistake, replace it with another valid name from global configuration mode and save the result:

BRANCH1-RTR1# configure terminal
BRANCH1-RTR1(config)# hostname HQ-ACC-SW01
HQ-ACC-SW01(config)# end
HQ-ACC-SW01# copy running-config startup-config

Where supported by the platform and IOS release, the following removes the explicitly configured hostname:

HQ-ACC-SW01# configure terminal
HQ-ACC-SW01(config)# no hostname
Switch(config)#

The resulting default name can vary by platform and IOS release. If you intend to keep a specific name, configure it explicitly and save the corrected configuration.

Common Problems and Troubleshooting

The prompt still shows the old hostname

  • Confirm that you entered global configuration mode before issuing hostname.
  • Review any error message. The value may contain unsupported characters or otherwise violate the platform's naming rules.
  • Use show running-config to confirm that you are connected to the expected device and to inspect the active hostname.

The hostname disappears after a reload

The running configuration was probably not copied to the startup configuration. Compare both configurations:

show running-config | include ^hostname
show startup-config | include ^hostname

If they differ, save the active configuration with copy running-config startup-config.

The hostname command is rejected

  • Enter configure terminal from privileged EXEC mode.
  • Use a simple, concise name with letters, numbers, and hyphens where supported.
  • Remove spaces or special characters that the platform may reject or that could cause operational confusion.

Remote management or name resolution does not work

Changing the IOS hostname does not update DNS, management IP addressing, SSH settings, or remote access policies. Configure or update DNS records, domain settings, management interfaces, and access services independently when required.

Exam-Relevant Notes

  • Hostname configuration uses global configuration mode: enable, then configure terminal, then hostname name.
  • The prompt changes immediately after a successful hostname command.
  • running-config is active in RAM; startup-config is saved for the next startup.
  • Save with copy running-config startup-config or, on many platforms, write memory.
  • A hostname is local IOS configuration and is separate from a DNS domain name or DNS record.

Related Cisco IOS Skills

Hostname configuration is often completed alongside IOS password configuration, NTP configuration, and OSPF configuration. Understanding basic computer networking concepts also helps when documenting and administering Cisco devices.