Ai-CompTech

AI Computing

Networking Fundamentals +

Cisco IOS Command Line

Master Cisco IOS commands for router and switch configuration and management

Advanced 90 min read 0 examples 5 quiz questionsID: 69452477
Lesson Content

Cisco IOS Command Line Interface

Introduction

Cisco IOS (Internetwork Operating System) is the software that runs on Cisco routers and switches. This guide covers essential IOS commands for network administration.

IOS Modes

User EXEC Mode

code
Router> # Limited viewing commands # No configuration changes allowed

Privileged EXEC Mode

code
Router> enable Router# # Full viewing access # Can execute troubleshooting commands

Global Configuration Mode

code
Router# configure terminal Router(config)# # Can configure global settings

Interface Configuration Mode

code
Router(config)# interface gigabitethernet 0/0 Router(config-if)# # Configure specific interface

Line Configuration Mode

code
Router(config)# line console 0 Router(config-line)# # Configure console, VTY, or AUX lines

Basic Configuration

Initial Setup

code
# Enter privileged mode enable # Enter configuration mode configure terminal # Set hostname hostname R1 # Set enable password (encrypted) enable secret Cisco123! # Set console password line console 0 password ConsolePass login exit # Set VTY password (remote access) line vty 0 4 password VtyPass login exit # Set banner banner motd # *********************************************** * Unauthorized access is prohibited! * * All activity is logged and monitored. * *********************************************** # # Save configuration end write memory # or copy running-config startup-config

Interface Configuration

Configuring IP Address

code
# Enter interface configuration interface gigabitethernet 0/0 # Set IP address ip address 192.168.1.1 255.255.255.0 # Enable interface no shutdown # Add description description LAN Connection to Switch # Exit interface mode exit

Serial Interface (WAN)

code
interface serial 0/0/0 ip address 10.1.1.1 255.255.255.252 clock rate 64000 # Only on DCE side bandwidth 64 # For routing metrics no shutdown exit

Loopback Interface

code
interface loopback 0 ip address 1.1.1.1 255.255.255.255 description Management Interface exit

Routing Configuration

Static Routes

code
# Add static route ip route 192.168.2.0 255.255.255.0 10.1.1.2 # Default route ip route 0.0.0.0 0.0.0.0 10.1.1.2 # or ip default-network 10.1.1.0 # Floating static route (backup) ip route 192.168.2.0 255.255.255.0 10.1.1.3 10

RIP Configuration

code
# Enable RIP version 2 router rip version 2 network 192.168.1.0 network 10.0.0.0 no auto-summary passive-interface gigabitethernet 0/0 exit

OSPF Configuration

code
# Enable OSPF router ospf 1 router-id 1.1.1.1 network 192.168.1.0 0.0.0.255 area 0 network 10.1.1.0 0.0.0.3 area 0 passive-interface gigabitethernet 0/1 exit # Configure interface cost interface gigabitethernet 0/0 ip ospf cost 10 exit

EIGRP Configuration

code
# Enable EIGRP router eigrp 100 network 192.168.1.0 0.0.0.255 network 10.1.1.0 0.0.0.3 no auto-summary passive-interface gigabitethernet 0/1 exit

Switch Configuration

VLAN Configuration

code
# Create VLAN vlan 10 name SALES exit vlan 20 name ENGINEERING exit # Assign port to VLAN interface fastethernet 0/5 switchport mode access switchport access vlan 10 spanning-tree portfast exit # Configure trunk port interface gigabitethernet 0/1 switchport mode trunk switchport trunk allowed vlan 10,20,30 switchport trunk native vlan 99 exit # Configure management VLAN interface vlan 1 ip address 192.168.1.10 255.255.255.0 no shutdown exit # Set default gateway ip default-gateway 192.168.1.1

Port Security

code
interface fastethernet 0/5 switchport mode access switchport port-security switchport port-security maximum 2 switchport port-security mac-address sticky switchport port-security violation restrict exit

Security Configuration

SSH Configuration

code
# Set domain name (required for SSH) ip domain-name company.com # Generate RSA keys crypto key generate rsa # Choose key size: 2048 # Configure SSH version 2 ip ssh version 2 ip ssh time-out 60 ip ssh authentication-retries 3 # Configure VTY lines for SSH line vty 0 4 transport input ssh login local exit # Create local user username admin privilege 15 secret AdminPass123!

Access Control Lists (ACL)

code
# Standard ACL (source IP only) access-list 10 permit 192.168.1.0 0.0.0.255 access-list 10 deny any # Apply to interface interface gigabitethernet 0/0 ip access-group 10 in exit # Extended ACL (source, destination, protocol) access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 80 access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 443 access-list 100 deny ip any any # Named ACL ip access-list extended WEB-TRAFFIC permit tcp any any eq 80 permit tcp any any eq 443 deny ip any any exit # Apply ACL interface gigabitethernet 0/1 ip access-group WEB-TRAFFIC out exit

NAT Configuration

Static NAT

code
# Map inside local to inside global ip nat inside source static 192.168.1.10 203.0.113.10 # Configure inside interface interface gigabitethernet 0/0 ip nat inside exit # Configure outside interface interface gigabitethernet 0/1 ip nat outside exit

Dynamic NAT (PAT)

code
# Define inside addresses access-list 1 permit 192.168.1.0 0.0.0.255 # Define NAT pool ip nat pool PUBLIC 203.0.113.10 203.0.113.20 netmask 255.255.255.0 # Configure NAT ip nat inside source list 1 pool PUBLIC overload # Configure interfaces interface gigabitethernet 0/0 ip nat inside exit interface gigabitethernet 0/1 ip nat outside exit

DHCP Configuration

DHCP Server

code
# Exclude addresses from DHCP pool ip dhcp excluded-address 192.168.1.1 192.168.1.10 # Create DHCP pool ip dhcp pool LAN-POOL network 192.168.1.0 255.255.255.0 default-router 192.168.1.1 dns-server 8.8.8.8 8.8.4.4 lease 7 exit

DHCP Relay

code
interface gigabitethernet 0/0 ip helper-address 192.168.2.10 exit

Show Commands

Viewing Configuration

code
# Show running configuration show running-config show run | section interface show run | include ip address # Show startup configuration show startup-config # Show specific configuration show running-config interface gigabitethernet 0/0 show running-config | begin router ospf

Interface Information

code
# Show all interfaces show ip interface brief show interfaces show interfaces gigabitethernet 0/0 # Show interface status show interface status show interfaces trunk # Show interface statistics show interfaces gigabitethernet 0/0 | include error show interfaces counters errors

Routing Information

code
# Show routing table show ip route show ip route ospf show ip route connected # Show routing protocols show ip protocols # Show OSPF information show ip ospf neighbor show ip ospf interface show ip ospf database # Show EIGRP information show ip eigrp neighbors show ip eigrp topology

VLAN and Switch Information

code
# Show VLANs show vlan brief show vlan id 10 # Show MAC address table show mac address-table show mac address-table interface fastethernet 0/1 # Show port security show port-security show port-security interface fastethernet 0/5 # Show spanning tree show spanning-tree show spanning-tree vlan 1

Security Information

code
# Show access lists show access-lists show ip access-lists # Show NAT translations show ip nat translations show ip nat statistics # Show SSH information show ip ssh show ssh

Troubleshooting Commands

Ping and Traceroute

code
# Ping ping 8.8.8.8 ping 192.168.1.1 repeat 100 # Extended ping ping Protocol [ip]: Target IP address: 8.8.8.8 Repeat count [5]: 1000 Source address or interface: 192.168.1.1 # Traceroute traceroute 8.8.8.8

Debug Commands

code
# Enable debugging (use carefully!) debug ip routing debug ip ospf events debug eigrp packets # Disable debugging no debug all undebug all # Show active debugs show debug

Clear Commands

code
# Clear interface counters clear counters # Clear ARP cache clear arp-cache # Clear NAT translations clear ip nat translation * # Clear MAC address table clear mac address-table dynamic # Clear logging buffer clear logging

Configuration Management

Backup and Restore

code
# Backup configuration to TFTP copy running-config tftp: # Enter TFTP server IP and filename # Restore configuration from TFTP copy tftp: running-config # Copy between config files copy running-config startup-config copy startup-config running-config # Erase startup config write erase erase startup-config

IOS Upgrade

code
# Show current IOS version show version # Show flash contents show flash: # Copy new IOS to flash copy tftp: flash: # Enter TFTP server IP and filename # Set boot system config terminal boot system flash:c2900-universalk9-mz.SPA.154-3.M5.bin exit # Reload router reload

Best Practices

  1. Always save configuration:
    code
    write memory
  2. Use descriptive names: Interface descriptions, ACL names
  3. Document changes: Banner, comments in config
  4. Regular backups: Automated config backups
  5. Use strong passwords: Enable secret, not enable password
  6. Disable unused services:
    code
    no ip http server
  7. Implement security: SSH instead of Telnet
  8. Test before production: Lab environment testing
  9. Version control: Track config changes
  10. Monitor logs:
    code
    show logging