Securing the Network Device
A router or switch is a Linux-like computer with a management plane — and that management plane is the way in. Hardening means removing every unnecessary way in and locking down the ones that remain. This lesson is a hands-on hardening checklist: nine controls, each with the exact IOS commands, plus the port-security rules the exam tests.
What hardening means
Hardening is the process of reducing the attack surface of a device: turning off what you do not need, securing what you must keep, and making sure every action is authenticated and logged. On a Cisco device that means the management plane — console, AUX, VTY (Telnet/SSH), HTTP, SNMP, CDP, and the small services (finger, tcp-small-servers, and so on). Each one is a door; hardening is closing the ones you do not use and putting a good lock on the ones you do.
Hardening is layered. Physical access is the foundation (password recovery via the configuration register proves it), SSH and strong passwords control logical access, service and port restrictions shrink the attack surface, and logging makes everything auditable.
enable secret, not enable password; (2)
transport input ssh disables Telnet; (3) SSH needs hostname + domain
name + RSA keys; (4) port-security violations are
protect → restrict → shutdown; (5) sync time (NTP) and ship
logs (syslog) so you can prove what happened.Rule 1 — strong passwords, and Rule 2 — the banner
The password that protects privileged EXEC mode is the most important one on the
device. Protect it with enable secret, which stores a strong one-way
hash (by default MD5, type 5). The older enable password is stored in clear
text or a weak, reversible type-7 form and must not be used. If both are configured,
the secret takes precedence.
! Preferred: hashed privileged-EXEC password R1(config)# enable secret Str0ngSecret! ! Optional (newer IOS): SHA-256 hash instead of MD5 R1(config)# enable algorithm-type sha256 secret Str0ngSecret! ! Encrypt other clear-text passwords stored in the configuration R1(config)# service password-encryption R1(config)#
enable secret = one-way hash, not reversible. enable password = clear
text or weak reversible type-7. If a question shows both, the secret wins.
service password-encryption only obscures the other stored passwords (console,
VTY, username) with type-7 — it does not affect the already-hashed secret.service password-encryption is a fixed, reversible obfuscation that offers no real
protection against anyone with the config file. It only stops a shoulder-surfer reading plain text.
Use it, but do not rely on it.Rule 2 — a login banner
A message-of-the-day (motd) banner appears before login. It is a legal control: a
clear warning that access is restricted to authorised users supports prosecution of intruders. The
character immediately after motd is a delimiter you choose; IOS prints your
text until it sees that same character again.
R1(config)# banner motd ^ Enter TEXT message. End with the character '^'. Authorized access only. Disconnect immediately if you are not an authorized user. ^ R1(config)#
Rule 3 — the VTY lines, and Rule 4 — SSH
The VTY (virtual terminal) lines are the remote-login doors. By default they accept Telnet, which sends everything — including the password — in cleartext. Restrict them to SSH only, authenticate against the local user database, and set an idle timeout.
R1(config)# line vty 0 4 R1(config-line)# transport input ssh ! disable Telnet; allow SSH only R1(config-line)# login local ! use the local username database R1(config-line)# exec-timeout 5 0 ! log out after 5 minutes idle R1(config-line)# exit R1(config)#
exec-timeout 5 0 means
5 minutes and 0 seconds of idle time. The second value is seconds, so
exec-timeout 5 30 is five and a half minutes. Setting exec-timeout 0 0
disables the timeout entirely — convenient, but insecure, so do not do it.You can further restrict VTY access by source address with an ACL and
access-class <number> in on the line, so only a management subnet may attempt
SSH. You can also throttle and slow brute-force attempts:
! Restrict VTY logins to the management subnet R1(config)# access-list 20 permit 192.168.1.0 0.0.0.255 R1(config)# line vty 0 4 R1(config-line)# access-class 20 in R1(config-line)# exit ! Optional: block the source for 60s after 3 failed logins in 120s R1(config)# login block-for 60 attempts 3 within 120
SSH setup
SSH encrypts the whole management session. IOS needs three things before it can generate keys: a hostname, a domain name, and a local username with a secret. Then generate the RSA key pair and force version 2.
R1(config)# hostname R1 R1(config)# ip domain-name example.com R1(config)# username admin privilege 15 secret cisco12345 ! Generate the RSA key pair. Minimum is 768 bits; use 1024 or more. R1(config)# crypto key generate rsa The name for the keys will be: R1.example.com How many bits in the modulus [512]: 2048 % Generating 2048 bit RSA keys, keys will be non-exportable...[OK] R1(config)# ip ssh version 2 R1(config)# line vty 0 4 R1(config-line)# transport input ssh R1(config-line)# login local R1(config-line)# exit
crypto key generate rsa fails if the
hostname is still the default (“Router”) or no domain name is set — the keys are
named hostname.domain. The old minimum was 768 bits; 1024 is the practical minimum
and 2048 is recommended. SSH version 1 is insecure — disable it with
no ip ssh version 1 or force version 2. To delete the keys, use
crypto key zeroize rsa.Rule 5 — console and AUX, Rule 6 — unneeded services
The console is local but still a door: anyone at the device can attach a cable.
Protect it with a password and a timeout. logging synchronous is not security — it
re-prints your typed line after a log message interrupts it — but it belongs in a standard
device template.
R1(config)# line console 0 R1(config-line)# password cisco12345 R1(config-line)# login R1(config-line)# logging synchronous R1(config-line)# exec-timeout 5 0 R1(config-line)# exit ! AUX line: used for out-of-band modem access. Disable it if unused. R1(config)# line aux 0 R1(config-line)# password cisco12345 R1(config-line)# login R1(config-line)# exec-timeout 5 0 R1(config-line)# no exec ! disable remote EXEC on AUX R1(config-line)# transport input none R1(config-line)# exit
no exec. no exec prevents an
interactive EXEC session on that line. Applying it to AUX (if no modem is attached)
closes an often-forgotten remote door. Do not apply it to the console if you need local
sessions.Every running service is potential attack surface. Turn off the ones you do not use. Availability varies by platform, so treat this as “where applicable”:
R1(config)# no ip http server ! disable the web (GUI) server R1(config)# no ip http secure-server ! disable HTTPS GUI as well R1(config)# no service tcp-small-servers R1(config)# no service udp-small-servers R1(config)# no ip finger ! older IOS: no service finger R1(config)# no ip bootp server R1(config)# no service config ! stop loading config from the network R1(config)# no cdp run ! or: no cdp enable per interface R1(config)# no ip domain-lookup ! avoid name leaks and lookup delays R1(config)#
On a switch, unused access ports are just as important. Move them to an unused VLAN and shut them down so a rogue device cannot plug in:
S1(config)# vlan 999 S1(config-vlan)# name UNUSED S1(config-vlan)# exit S1(config)# interface range fastethernet0/10 - 24 S1(config-if-range)# switchport mode access S1(config-if-range)# switchport access vlan 999 S1(config-if-range)# shutdown S1(config-if-range)# exit
Rule 7 — port security
Port security limits which MAC addresses may use a switch access port. It stops a rogue device from joining, and it blunts MAC-flooding attacks by capping how many addresses a port can learn. It applies to access ports only, so set the mode first.
S1(config)# interface fastethernet0/1 S1(config-if)# switchport mode access ! port security needs an access port S1(config-if)# switchport port-security S1(config-if)# switchport port-security maximum 1 S1(config-if)# switchport port-security mac-address sticky S1(config-if)# switchport port-security violation restrict S1(config-if)# end S1# show port-security interface fastethernet0/1
switchport port-security— enables port security on the interface (default maximum is 1).switchport port-security maximum 1— allows only one MAC address.switchport port-security mac-address sticky— dynamically learns the current device’s MAC and adds it to the running configuration as a sticky entry. Save the config to keep it. You can also hard-code withswitchport port-security mac-address 0001.2222.3333.switchport port-security violation <mode>— what to do when a violation occurs.
shutdown is the default. If a question mentions logging or a counter,
it is restrict; if it mentions silence, it is protect; if it mentions
err-disable, it is shutdown.To recover a port that was err-disabled by port security, you can bounce it manually, or enable automatic recovery:
! Manual recovery S1(config)# interface fastethernet0/1 S1(config-if)# shutdown S1(config-if)# no shutdown S1(config-if)# exit ! Or let IOS recover the port automatically after 300 seconds S1(config)# errdisable recovery cause psecure-violation S1(config)# errdisable recovery interval 300
Rules 8 and 9 — NTP and syslog — and the checklist
Secure devices must agree on the time. Accurate timestamps make logs, security events, and forensic correlation meaningful — and a device with a wrong clock can fail certificate validation or produce useless audit trails. NTP (Network Time Protocol) keeps clocks aligned to a trusted source.
R1(config)# ntp server 192.168.1.1 R1(config)# clock timezone UTC 0 R1(config)# service timestamps log datetime msec localtime show-timezone R1# show ntp status R1# show ntp associations ! Optional: authenticated NTP so a rogue time server cannot spoof it R1(config)# ntp authenticate R1(config)# ntp authentication-key 1 md5 NtpKey123 R1(config)# ntp trusted-key 1 R1(config)# ntp server 192.168.1.1 key 1
ntp
authenticate) and pick servers inside your trusted management network.Local logs are lost when a device reboots or is replaced, and an attacker who owns the device can erase them. Send logs to a central syslog server so there is an independent copy that supports auditing and incident response.
R1(config)# logging host 192.168.1.50 ! older IOS: logging 192.168.1.50 R1(config)# logging trap informational ! send severity 0-6 to the server R1(config)# logging source-interface GigabitEthernet0/0 R1(config)# logging buffered 16384 ! keep a local ring buffer too R1# show logging
The hardening checklist
This table is the whole lesson on one screen. Reproduce it from memory before the exam.
| Area | Key command(s) | Purpose |
|---|---|---|
| Privileged EXEC | enable secret <pw> | Hash the enable password (beats enable password). |
| Stored passwords | service password-encryption | Obscure other clear-text passwords (type 7). |
| Banner | banner motd ^ | Legal warning before login. |
| VTY lines | transport input ssh, login local, exec-timeout 5 0 | SSH only, authenticate locally, auto-logout. |
| SSH | hostname, ip domain-name, crypto key generate rsa, ip ssh version 2 | Encrypted management access. |
| Console / AUX | password, login, exec-timeout, no exec (AUX) | Protect local and out-of-band ports. |
| Services | no ip http server, no cdp run, no service tcp-small-servers | Shrink the attack surface. |
| Unused ports | switchport access vlan 999 + shutdown | Stop rogue device connections. |
| Port security | switchport port-security + maximum + sticky + violation | Control which MACs may connect. |
| Time | ntp server <ip> | Accurate, correlatable logs. |
| Logging | logging host <ip>, logging trap | Independent audit trail. |
Review
Check what you have learned with these review questions.
Sources & references
- Cisco. CCNA (200-301) Exam Topics, Domain 5.3 (Configure device access control) and Domain 5.5 (describe security program elements). cisco.com.
- Cisco. Cisco Guide to Harden Cisco IOS Devices (security configuration guide). cisco.com.
- Cisco. Configuring Port Security (Catalyst switch security configuration guide). cisco.com.
- Cisco. Configuring NTP and Configuring System Message Logging (IOS configuration guides). cisco.com.
- Cisco. Configuring Secure Shell (SSH) on IOS (tech note). cisco.com.
- NIST. SP 800-123: Guide to General Server Security and SP 800-53 access control controls. csrc.nist.gov.
Target exams: CCNA 200-301 v1.1 · CyberOps Associate 200-201. Last content verification: 2026-10-11.