Beginner · Ethernet, MAC addresses and the Cisco CLI · topic 10 of 57 · 35 min
The Cisco IOS command line
Explanation
Why learn the CLI?
Most enterprise network devices are still configured by typing commands. Cisco IOS (Internetwork Operating System) is the most common, and the CCNA exam and most network jobs expect you to use it comfortably. Other vendors have similar command lines, so the skill carries over.
Getting in: console and SSH
A brand-new device has no IP address, so the first time you connect with a console cable from your laptop to the console port (RJ45 or USB), using a terminal program such as PuTTY or Tera Term (9600 baud, 8 data bits, no parity, 1 stop bit). Once the device has an IP address and SSH is set up (covered in the security module), you manage it over the network with SSH. Telnet also works but sends passwords in plain text, so avoid it.
The modes and their prompts
| Mode | Prompt | How to get there | What you can do |
|---|---|---|---|
| User EXEC | Switch> | Log in | A few basic show commands and ping |
| Privileged EXEC | Switch# | enable | All show commands, copy, reload, debug |
| Global configuration | Switch(config)# | configure terminal | Change settings for the whole device |
| Interface configuration | Switch(config-if)# | interface g0/1 | Settings for one port |
| Line configuration | Switch(config-line)# | line console 0 (or line vty 0 15) | Settings for console or remote logins |
exit goes back one level. end (or Ctrl+Z) jumps straight back to privileged EXEC. disable goes from # back to >.
Help, completion and abbreviations
- Type ? to list the commands allowed in this mode. Type sh? to see commands starting with sh. Type show ? to see what can follow show.
- Press Tab to complete a word: conf Tab becomes configure.
- You can shorten any word as long as it is unique: conf t for configure terminal, sh ip int br for show ip interface brief, wr for write.
- The up arrow recalls earlier commands.
- In configuration mode, show commands do not work directly. Put do in front: do show ip interface brief.
Running-config and startup-config
Every command you type in configuration mode takes effect at once and is stored in the running-config, which lives in RAM. RAM is cleared when the device reboots or loses power. The startup-config is stored in NVRAM (non-volatile RAM), which survives a reboot; the device loads it when it starts. So after a good change, save it.
Switch# show running-config ! what the device is doing now (RAM)
Switch# show startup-config ! what it will load at boot (NVRAM)
Switch# copy running-config startup-config
Destination filename [startup-config]? ! press Enter
Switch# write memory ! older shortcut that does the sameA first configuration
Switch> enable
Switch# configure terminal
Switch(config)# hostname SW1-Floor2
SW1-Floor2(config)# enable secret Str0ng!Lab
SW1-Floor2(config)# no ip domain-lookup
SW1-Floor2(config)# line console 0
SW1-Floor2(config-line)# password C0nsole!Lab
SW1-Floor2(config-line)# login
SW1-Floor2(config-line)# exit
SW1-Floor2(config)# interface vlan 1
SW1-Floor2(config-if)# ip address 192.168.1.2 255.255.255.0
SW1-Floor2(config-if)# no shutdown
SW1-Floor2(config-if)# exit
SW1-Floor2(config)# ip default-gateway 192.168.1.1
SW1-Floor2(config)# end
SW1-Floor2# copy running-config startup-config- hostname changes the name in the prompt, so you always know which device you are on.
- enable secret sets the password for the enable command, stored as a hash (a one-way scrambled form). The older enable password is stored in plain text or weak encryption, so use enable secret.
- line console 0 with password and login asks for a password on the console port.
- no ip domain-lookup stops the device trying to look up a mistyped command as a host name, which otherwise freezes the prompt for several seconds.
- A Layer 2 switch gets its management IP address on a virtual interface, interface vlan 1. A router gets IP addresses on its physical interfaces, for example interface g0/1 then ip address 10.0.0.1 255.255.255.0.
- no shutdown turns an interface on. Router interfaces are shut down by default; switch ports are on by default.
The command you will use most
R1# show ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.1.1 YES manual up up
GigabitEthernet0/1 10.0.0.1 YES manual administratively down down
GigabitEthernet0/2 unassigned YES unset down downNeed help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
The Cisco IOS command line · 1/7
Cisco devices are configured by typing commands in the IOS command line, first over a console cable, later over SSH.
Prefer a video by a teacher? Find free videos on “Cisco IOS CLI basics modes hostname enable secret Packet Tracer CCNA” on YouTube ↗
In real life: A night change at an ISP point of presence
A NOC engineer in Bengaluru must add a new customer interface on a router at 2 am. She connects by SSH, runs show running-config interface g0/3 to see the current state, makes the change in interface configuration mode, checks it with do show ip interface brief, and confirms the customer can ping. Only then does she run copy running-config startup-config. If something had gone wrong before saving, a reload would have brought back the old, working configuration.
Practice (0/4 done)
The prompt shows R1(config-if)#. Which mode are you in?
You configured a switch and it works. Which command makes sure the configuration survives a reboot?
Packet Tracer lab: add one 2960 switch and one PC, and connect the PC to the switch console port with a console cable. From the PC Terminal, configure the switch: hostname SW1, enable secret, a console password with login, no ip domain-lookup, then save. Reload the switch and check that everything is still there.
Network engineers often parse show command output with a script. Write up_interfaces(output) that takes the text of show ip interface brief and returns a list of interface names whose Status is "up" AND Protocol is "up". Skip the header line. Hint: "administratively down" has a space, so use the LAST two words of each line as status and protocol.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Ethernet frames and MAC addressesEthernet, MAC addresses and the Cisco CLI · same module
- Securing device access: secrets and SSHNetwork security
- SSH: keys, ssh-copy-id and hardening sshdLinux and Red Hat (RHCSA to RHCE) · SELinux and SSH
- The command line on all three cloudsCloud Computing (AWS, Azure, Google Cloud) · Google Cloud and comparing the clouds
- Troubleshooting tools and common faultsTroubleshooting and the CCNA exam
- DHCP: automatic addressesIP services: DHCP, DNS, NAT and more
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which command takes you from Switch> to Switch#?
Answer: enable
enable moves from user EXEC to privileged EXEC.
Where is the running-config stored?
Answer: RAM
The running-config is in RAM, so it is lost at reboot unless saved to NVRAM.
You are in global configuration mode and want to check interface status without leaving. What do you type?
Answer: do show ip interface brief
do runs an EXEC command from any configuration mode.
show ip interface brief shows a router interface as "administratively down". What is missing?
Answer: no shutdown on the interface
Administratively down means the interface is shut down in the configuration.
Why is enable secret preferred over enable password?
Answer: It is stored as a hash instead of plain text or weak encryption
enable secret stores a hashed password and takes priority over enable password.
A switch has 16 VTY lines. Only line vty 0 4 has transport input ssh. What is the risk?Related
Answer: Lines 5 to 15 may still accept Telnet
Unconfigured lines keep their own settings; secure all of them with line vty 0 15.
Which command checks sshd configuration syntax?Related
Why use gcloud config configurations?Related
Answer: To keep separate named sets of account, project and region, and switch between them
Configurations let you switch between clients or environments without retyping settings.
Which command shows the VLANs allowed on a trunk?Related
Answer: show interfaces trunk
show interfaces trunk lists trunk ports, the native VLAN, and the VLANs allowed and active on each.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- This is the last topic of “Ethernet, MAC addresses and the Cisco CLI”. The module exam comes next.
- Module 2 exam: Ethernet, MAC addresses and the Cisco CLI · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, IPv4 addressing. 57 topics left in the course before the final exam.