Author: renjithbs

  • What is Power over Ethernet (PoE)?

    Power over Ethernet (PoE) allows network cables to carry both data and electrical power to devices like IP phones, wireless access points, and security cameras, eliminating the need for separate power adapters.

    PoE Standards

    StandardMax Power per PortDevices Supported
    802.3af (PoE)15.4WPhones, small APs
    802.3at (PoE+)30WHigh-power APs, cameras
    802.3bt (PoE++)60-100WLED lights, laptops

    How to Enable PoE on a Cisco Switch

    Most Cisco switches support PoE by default, but you can manually enable or configure it.

    1. Check if the Switch Supports PoE

    Run:

    Switch#show power inline

    If you see available power and usage stats, the switch supports PoE.


    2. Enable PoE on an Interface

    Run:

    Switch#conf t
    interface <interface_id>
    power inline auto
    exit
    • <interface_id> → Example: GigabitEthernet1/0/1
    • auto → Enables PoE when a powered device (PD) is detected.

    To disable PoE on a port:

    Switch#conf t
    interface <interface_id>
    power inline never
    exit

    3. Set Power Limits for Devices

    By default, the switch assigns power dynamically. You can manually set power limits:

    Switch#conf t
    interface <interface_id>
    power inline static max 20000
    exit
    • Max power in milliwatts (mW)
      • 15000 for 15W (PoE)
      • 30000 for 30W (PoE+)
      • 60000 for 60W (PoE++)

    To check power consumption:

    Switch#show power inline interface <interface_id> detail

    4. Troubleshoot PoE Issues

    If a device is not powering up:

    • Check PoE status:bashCopyEditshow power inline interface <interface_id>
    • Reset PoE on the port:bashCopyEditconf t interface <interface_id> power inline never power inline auto exit
    • If the port is err-disabled, recover it:bashCopyEditconf t interface <interface_id> shutdown no shutdown exit
    • If power is exhausted, check:bashCopyEditshow power inline

    Summary

    TaskCommand
    Enable PoEpower inline auto
    Disable PoEpower inline never
    Set power limitpower inline static max <mW>
    Check PoE statusshow power inline
    Check port power useshow power inline interface <interface_id> detail
  • Troubleshooting Switch Interfaces

    Troubleshooting Cisco switch interface errors requires a structured approach to diagnose and resolve issues efficiently. Here’s a step-by-step guide:


    1. Check Interface Status

    Run:

    Switch#show interfaces status
    • Connected → Interface is up and functioning
    • Notconnect → No device is connected or a cable issue
    • Err-disabled → Error condition detected (see step 5)
    • Disabled → Interface is administratively down

    If the interface is down, enable it:

    Switch#conf t
    interface <interface_id>
    no shutdown
    exit

    2. Verify Cable and Physical Connection

    • Ensure the cable is properly plugged in.
    • Test with a different cable.
    • Check port LED status (blinking green = active, amber = issue).

    3. Check Interface Errors

    Run:

    Switch#show interfaces <interface_id>

    Look for:

    • Input errors: CRC errors, frame errors → Cable or duplex mismatch.
    • Output errors: Congestion or hardware failure.
    • CRC errors: Bad cables, interference, or duplex mismatch.
    • Collisions: High count may indicate a duplex mismatch.

    4. Check Duplex and Speed Settings

    Run:

    Switch#show interfaces <interface_id> status

    If there is a duplex mismatch, manually configure it:

    Switch#conf t
    interface <interface_id>
    duplex full
    speed 1000
    exit

    5. Check for Err-Disabled State

    Run:

    Switch#show interfaces status | include err-disabled

    Common causes:

    • Port security violation
    • BPDU guard violation
    • Link flap detection
    • UDLD failure

    Fix:

    Switch#conf t
    interface <interface_id>
    shutdown
    no shutdown
    exit

    To find the specific reason:

    Switch#show interfaces <interface_id> | include error

    If it’s due to port security:

    Switch#show port-security interface <interface_id>
    Switch#clear port-security sticky interface <interface_id>

    If BPDU guard triggered:

    Switch#spanning-tree bpduguard disable

    To automatically recover from err-disabled state:

    Switch#conf t
    errdisable recovery cause all
    errdisable recovery interval 30
    exit

    6. Check VLAN and Trunk Settings

    Run:

    Switch#show vlan brief

    Ensure the port is in the correct VLAN.

    For trunk ports:

    Switch#show interfaces trunk

    If VLANs are missing, add them:

    Switch#conf t
    interface <interface_id>
    switchport mode trunk
    switchport trunk allowed vlan add <vlan_id>
    exit

    7. Check Spanning Tree (STP) Issues

    Run:

    Switch#show spanning-tree interface <interface_id>
    • If the port is in Blocking state, STP is preventing loops.
    • If the port is flapping, check STP settings.

    To disable STP (use cautiously):

    Switch#conf t
    interface <interface_id>
    spanning-tree portfast
    exit

    8. Check MAC Address Table

    Run:

    Switch#show mac address-table interface <interface_id>

    If there are no MAC addresses, the device might not be communicating.


    9. Debugging Further

    To see real-time logs:

    Switch#terminal monitor
    debug spanning-tree events
    debug interface <interface_id>

    Disable debugging after use:

    Switch#undebug all

    10. Reload Interface or Switch

    If all else fails:

    Switch#reload

    or shut/no shut the interface.

  • How to Install Cisco SD-WAN on EVE-NG

    This guide covers hardware & VMware prerequisites, setting up EVE-NG, and installing Cisco SD-WAN components (vManage, vBond, vSmart, vEdge).


    1. Prerequisites

    Hardware Requirements

    • CPU: 8+ cores (Intel VT-x/EPT or AMD-V/RVI enabled)
    • RAM: 16GB+ (32GB+ recommended for large labs)
    • Storage: 100GB+ SSD (for performance)
    • Network: Bridged networking for external access

    VMware Workstation Requirements

    • VMware Workstation Pro (Recommended) or Player
    • Nested Virtualization enabled (for running EVE-NG inside VMware)
    • EVE-NG Installed (ISO or OVA method)
    • EVE-NG Network Adapter set to Bridged

    2. EVE-NG Setup on VMware

    If you haven’t installed EVE-NG yet, follow this guide:
    📌 How to Install EVE-NG on VMware Workstation

    Once EVE-NG is running, find its IP address using:

    bashCopyEditip a
    

    Access EVE-NG via browser:

    cppCopyEdithttp://<EVE-NG-IP>/
    

    3. Download Cisco SD-WAN Images

    You need to get the Cisco SD-WAN images for EVE-NG.
    These images are available on Cisco’s official website (Cisco Software Downloads).

    🔹 Required Images for Cisco SD-WAN Deployment:

    • vManage (Orchestrator)
    • vBond (Authentication Controller)
    • vSmart (Control Plane)
    • vEdge (Data Plane)

    🚨 Make sure you download KVM/QEMU-compatible images (not ESXi/OVA).


    4. Upload & Configure SD-WAN Images in EVE-NG

    1. Connect to EVE-NG via SSH:bashCopyEditssh root@<EVE-NG-IP>
    2. Navigate to QEMU Directory:bashCopyEditcd /opt/unetlab/addons/qemu/
    3. Create Folders for Each Image:bashCopyEditmkdir -p viptela-vmanage-<version> mkdir -p viptela-vbond-<version> mkdir -p viptela-vsmart-<version> mkdir -p viptela-edge-<version>
    4. Upload Images (via WinSCP or SCP Command)
      • Use WinSCP to upload images into the respective folders.
      • Alternatively, use SCP from another system:bashCopyEditscp <local-path-to-image>.qcow2 root@<EVE-NG-IP>:/opt/unetlab/addons/qemu/viptela-vmanage/
    5. Rename Image to “hda.qcow2”bashCopyEditmv <original-image-name>.qcow2 hda.qcow2
    6. Fix PermissionsbashCopyEdit/opt/unetlab/wrappers/unl_wrapper -a fixpermissions

    5. Deploy Cisco SD-WAN Nodes in EVE-NG

    Step 1: Create a New Lab

    1. Open EVE-NG Web GUINew Lab
    2. Name the lab (e.g., SD-WAN-Lab)

    Step 2: Add Cisco SD-WAN Devices

    1. Click “Add a Node”
    2. Choose vManage, vBond, vSmart, and vEdge
    3. Assign at least:
      • vManage: 8GB RAM, 4 vCPUs
      • vBond: 4GB RAM, 2 vCPUs
      • vSmart: 4GB RAM, 2 vCPUs
      • vEdge: 2GB RAM, 1 vCPU
    4. Save and Start the Nodes

    6. Initial Configuration of SD-WAN Components

    Once the devices boot up, access them via console (telnet in EVE-NG).

    vManage Setup

    1. Login with default credentials:pgsqlCopyEditUsername: admin Password: admin
    2. Assign Basic Configurations:bashCopyEditconfig terminal system host-name vManage system-ip 1.1.1.1 site-id 100 organization-name "YourOrg" exit commit

    vBond Setup

    1. Set hostname, system IP, and site ID:bashCopyEditconfig terminal system host-name vBond system-ip 2.2.2.2 site-id 200 organization-name "YourOrg" exit commit

    vSmart Setup

    1. Configure hostname, system IP, and site ID:bashCopyEditconfig terminal system host-name vSmart system-ip 3.3.3.3 site-id 300 organization-name "YourOrg" exit commit

    vEdge Setup

    1. Configure hostname, system IP, and site ID:bashCopyEditconfig terminal system host-name vEdge system-ip 4.4.4.4 site-id 400 organization-name "YourOrg" exit commit

    7. Establish Control Connections

    1. Ensure vManage, vBond, and vSmart can communicate.
    2. Check connectivity using:bashCopyEditshow control connections
    3. Verify tunnel status:bashCopyEditshow ip route

    8. Web Access & Final Configuration

    1. Open a browser and go to:cppCopyEdithttps://<vManage-IP>:8443
    2. Login with:
      • Username: admin
      • Password: admin
    3. Complete initial setup via the GUI.

    9. Troubleshooting & Tips

    Common Issues & Fixes

    IssueSolution
    Nodes not startingIncrease RAM & CPU in EVE-NG VM settings
    No network connectivityUse Bridged Adapter in VMware & ensure correct IP settings
    Can’t access vManage Web GUICheck HTTPS port (8443) & restart vManage
    Control connections not formingVerify IP configs & firewall rules

    10. Conclusion

    You’ve successfully installed Cisco SD-WAN on EVE-NG within VMware! 🎉

    🔹 Next Steps:

    • Integrate real WAN/LAN connections.
    • Add vEdge Cloud or physical cEdge routers.
    • Test policy-based routing and QoS.
  • EVE-NG Installation on VMware Workstation

    Installing EVE-NG on VMware Workstation involves several steps. Here’s a step-by-step guide:

    Prerequisites

    1. VMware Workstation Pro or VMware Workstation Player installed.
    2. EVE-NG ISO or OVA downloaded from EVE-NG website.
    3. Adequate System Requirements:
      • At least 4 CPU cores (8+ recommended).
      • 16GB RAM (More for large labs).
      • 100GB+ SSD storage.
      • Intel VT-x/EPT or AMD-V/RVI enabled in BIOS.
      • VMware installed with nested virtualization support enabled.

    Method 1: Install EVE-NG using OVA (Recommended)

    Step 1: Download the EVE-NG OVA File

    • Download the EVE-NG Community OVA or EVE-NG Professional OVA from EVE-NG.net.

    Step 2: Import the OVA in VMware

    1. Open VMware Workstation.
    2. Click FileOpen.
    3. Select the EVE-NG OVA file.
    4. Click Import and wait for the process to complete.

    Step 3: Adjust VM Settings

    • Increase CPU Cores (Recommended: 4 or more).
    • Increase RAM (Recommended: 8GB or more).
    • Set Network Adapter to Bridged (for external access).
    • Enable Nested Virtualization:
      • Go to Processors → Enable “Virtualize Intel VT-x/EPT or AMD-V/RVI”.

    Step 4: Start the VM & Configure EVE-NG

    1. Power on the VM.
    2. Login using default credentials:
      • Username: root
      • Password: eve
    3. Change the root password when prompted.
    4. Configure network settings using the CLI or DHCP.
    5. Access the web GUI via **http://<EVE-NG-IP>/`.

    Method 2: Install EVE-NG from ISO (Manual Installation)

    Step 1: Create a New VM

    1. Open VMware Workstation and click Create a New Virtual Machine.
    2. Select “Custom (Advanced)” and click Next.
    3. Choose “I will install the operating system later” and click Next.
    4. Select LinuxUbuntu 64-bit.
    5. Name the VM (e.g., EVE-NG) and choose the storage location.

    Step 2: Configure VM Settings

    • CPU: At least 4 cores (More recommended).
    • RAM: At least 8GB (More recommended).
    • Hard Disk: 100GB or more.
    • Network Adapter: Set to Bridged or NAT.
    • Enable Virtualization: Go to Processors and enable VT-x/EPT.

    Step 3: Mount & Install EVE-NG

    1. Attach the EVE-NG ISO:
      • Go to CD/DVD (IDE) settings.
      • Select “Use ISO Image File” and browse for the EVE-NG ISO.
    2. Power on the VM.
    3. Follow the installation wizard:
      • Choose Install EVE-NG.
      • Select disk and proceed with the installation.
      • Set up a root password.
      • Configure network settings.
    4. After installation, reboot the VM.

    Step 4: Access EVE-NG

    • Login via CLI using:makefileCopyEditUsername: root Password: (your password)
    • Find the IP address of the VM (ifconfig or ip a).
    • Open a web browser and go to http://<EVE-NG-IP>/.

    Post-Installation Steps

    1. Enable SSH & Web GUI Access

    • Ensure EVE-NG is reachable from your network.
    • Use a browser to access the Web GUI at http://<EVE-NG-IP>/.

    2. Upload & Install Network Images

    • Upload images (Cisco, Juniper, Fortinet, etc.) to /opt/unetlab/addons/qemu/.
    • Fix permissions using:bashCopyEdit/opt/unetlab/wrappers/unl_wrapper -a fixpermissions

    3. Connect to the Lab

    • Use SecureCRT, Putty, or the built-in console to connect to network devices.

    Troubleshooting

    1. Web GUI Not Accessible?
      • Check network settings and ensure Bridged Adapter is selected.
      • Try systemctl restart networking inside EVE-NG.
    2. VM Won’t Boot?
      • Enable VT-x/EPT in BIOS.
      • Ensure Nested Virtualization is enabled in VMware.
    3. Slow Performance?
      • Allocate more CPU cores and RAM.
      • Ensure SSD storage is used.
  • MAC address learning process

    A switch learns MAC addresses using a process called MAC address learning or learning and forwarding. Here’s how it works:

    1. Receives a Frame: When a switch receives an Ethernet frame on a port, it examines the frame’s source MAC address.
    2. Updates the MAC Table (CAM Table):
      • The switch stores the source MAC address and the port number in its MAC address table (also called the Content Addressable Memory (CAM) table).
      • This way, the switch knows which device is connected to which port.
    3. Forwards the Frame:
      • If the destination MAC address is already in the MAC table, the switch forwards the frame only to the corresponding port.
      • If the destination MAC address is not in the table, the switch floods the frame to all ports except the one it was received from. This is called unknown unicast flooding.
    4. Refreshes Entries:
      • MAC address entries have a timeout (typically 5 minutes by default).
      • If a device doesn’t send traffic for a while, its MAC entry is removed from the table to free up space.

    Example Scenario:

    • A device with MAC AA:BB:CC:DD:EE:01 sends a frame through Port 1.
    • The switch records AA:BB:CC:DD:EE:01 → Port 1 in its MAC table.
    • If the destination MAC is unknown, the switch floods the frame.
    • When the destination device responds, the switch learns its MAC and updates the table.

    This process helps switches efficiently forward traffic and reduce unnecessary network congestion.

  • Cisco SD-WAN Templates

    Cisco SD-WAN uses device and feature templates to manage configurations efficiently across multiple devices. Here’s a breakdown of how these templates work:

    • Device Templates: These are specific to a device model, such as vEdge routers, and are used to configure the complete operational setup of a device. A device template consists of one or more feature templates. Device templates can be customized for different locations or roles within a network.
    • Feature Templates: These templates define configurations for specific software features on Cisco SD-WAN devices. They can be applied across multiple device types and are used to configure parameters like system settings, interfaces, routing protocols, and security settings. Feature templates can be mandatory or optional, and some have default configurations that can be overridden.
    • Parameter Scope: Parameters in feature templates can have different scopes:
      • Device Specific: Values are unique to each device and are entered when attaching a device template to a specific device. Examples include system IP address, hostname, and GPS location.
      • Global: Values apply to all devices using the template, such as DNS server settings or interface MTUs.
    • CSV Files: Device-specific settings can be managed using CSV files. Each row in the CSV file corresponds to a device, with columns for parameters like device ID, IP address, and hostname. These files are uploaded when attaching a device template to a device.
    • Template Creation: Templates can be created from feature templates or via the CLI. Mandatory feature templates and some optional ones have default configurations. Custom templates can be created to tailor configurations to specific needs.
    • Configuration Management: Templates help in managing configurations across multiple devices, reducing human error and scaling issues. They support features like zero-touch provisioning (ZTP) and automatic rollback, ensuring efficient and error-free deployment.

    These templates streamline the configuration process, making it easier to manage and scale Cisco SD-WAN networks.

  • What is the Dark Web?

    The dark web is a part of the internet that is not indexed by search engines and requires specific software to access. It is designed to provide anonymity and privacy to its users, allowing them to communicate and conduct business without revealing their identifying information.

    Key Features of the Dark Web:

    • Not indexed by search engines
    • Requires specific software to access (e.g. Tor browser)
    • Provides anonymity and privacy to users
    • Often associated with illegal activities and selling stolen personal information

    How to Access the Dark Web:

    1. Install Tor Browser: Download and install the Tor browser from the official website.
    2. Use Special Search Engines: The dark web uses special search engines designed to help you find hidden sites.
    3. Navigate .onion Domains: Websites on the dark web end with the “.onion” domain extension.
    4. Stay Safe: Be cautious when accessing the dark web as it can be a dangerous place. Use security measures like antivirus software and avoid downloading files from untrusted sources.
  • Configuring Pi-hole for Ad Blocking

    To configure Pi-hole to block ads, follow these steps:

    1. Set Up Raspberry Pi: First, configure a Raspberry Pi running Raspberry Pi OS. You can use any Raspberry Pi model, but the Zero 2 W is recommended for its low power consumption. Install Raspberry Pi OS Lite (32-bit) to run headlessly (without a mouse and keyboard).
    2. Install Pi-hole: Once your Raspberry Pi is set up, install Pi-hole software on it. You can use a one-line script installer provided by Pi-hole to set up the software easily.
    3. Assign Static IP Address: Ensure your Raspberry Pi has a static IP address that does not change when it restarts or reconnects to the network. This can be done through your router’s settings by specifying the MAC address of the Raspberry Pi and assigning it a static IP.
    4. Configure Router DNS Settings: Log into your router’s admin interface and change the DNS settings to use the static IP address of your Raspberry Pi. This can usually be found under sections like “Internet,” “DHCP,” “Internet Connection,” or “DDNS.” Enter your Pi-hole’s IP address in the DNS field. If your router provides multiple custom DNS fields, add your Pi-hole address in each field.
    5. Direct DNS Queries to Pi-hole: After configuring your router, all devices connected to your network will send DNS queries to your Pi-hole instead of to a DNS server on the internet. Pi-hole will block requests to ad domains before they leave your network.
    6. Access Pi-hole Dashboard: Visit the Pi-hole dashboard using the admin URL (usually http://pi.hole/admin) to manage your Pi-hole settings. You can block or unblock specific domain names and configure other features from here.

    By following these steps, you can effectively block ads across your entire network, including devices that don’t support browser extensions, such as smart TVs and game consoles.

  • What is SD-WAN ?

    SD-WAN, or Software-Defined Wide Area Network, is a virtual WAN architecture that uses software-defined networking (SDN) principles to manage and optimize the performance of wide area networks. It allows organizations to securely connect users, applications, and data across multiple locations, providing improved performance, reliability, and scalability. SD-WAN simplifies network management by providing centralized control and visibility over the entire network, enabling businesses to use lower-cost Internet access to build higher-performance WANs, often replacing more expensive private WAN connection technologies like MPLS.

    SD-WAN vs MPLS

    The main difference between SD-WAN and MPLS is that SD-WAN is a virtualized network overlay that can combine multiple types of connections, whereas MPLS is a dedicated, hardware-based private network. SD-WAN creates encrypted tunnels over the internet, while MPLS doesn’t directly support encryption but is partitioned from the internet.

    • SD-WAN: A software-defined wide area network that uses virtualization and overlay tunnels to connect users to workloads across multiple transport services and types of existing infrastructure, offering improved bandwidth availability, WAN redundancy, and cost-effectiveness.
    • MPLS: A multiprotocol label switching protocol that improves performance and efficiency of data transmission in a wide area network, operating between Layer 2 and Layer 3 of the OSI model, but with higher per-megabit costs and limited flexibility.

    SD-WAN is generally considered more cost-effective, flexible, and secure than MPLS, with the ability to cost-effectively mix and match network links according to content type or priority. However, MPLS is still in demand, particularly for organizations with specific connectivity and security requirements, due to its lower packet loss and dedicated leased lines. Ultimately, the choice between SD-WAN and MPLS depends on the organization’s specific needs and priorities.

    SD-WAN implementation

    Implementing SD-WAN involves several best practices to ensure a successful and efficient transition. Here are key steps and considerations:

    1. Assess Your Network: Evaluate your current network infrastructure to identify strengths, weaknesses, and areas that require improvement. This includes understanding your network traffic patterns, application requirements, and performance goals. Assess compatibility issues with legacy systems and ensure your SD-WAN solution aligns with your business objectives.
    2. Define Objectives and Strategy: Clearly define what you want to achieve with SD-WAN, such as cost savings, improved performance, or enhanced security. Align stakeholders and decision-makers on the strategic goals of the SD-WAN implementation.
    3. Choose Deployment Model: Decide whether to deploy SD-WAN in-house, use a managed service provider (MSP), or a hybrid approach. Consider factors like in-house expertise, management and monitoring needs, and budget constraints.
    4. Select the Right Vendor: Choose a vendor that offers robust SD-WAN solutions, including advanced security features, flexible deployment options, and strong customer support. Ensure the vendor can meet industry, country, or region-specific regulations.
    5. Plan for Scalability and Flexibility: Design your SD-WAN solution to handle future growth and changing business demands. This includes considering the number of locations, size, and complexity of your network. Use modular methodologies and configuration templates to streamline deployment and management.
    6. Implement Security Measures: Secure SD-WAN solutions should include advanced security features like Zero Trust Network Access (ZTNA), Intrusion Prevention System (IPS), and application-aware firewall capabilities. Ensure the SD-WAN solution can dynamically scale and adapt to different cloud environments.
    7. Monitor and Troubleshoot: Implement robust monitoring tools to proactively identify and resolve performance issues. Regularly review performance metrics and network logs to ensure optimal performance and address any potential bottlenecks or security threats.
    8. Ongoing Maintenance: After deployment, continue to maintain the SD-WAN network to ensure it operates efficiently. This includes regular updates, monitoring, and troubleshooting.

    FortiGate SD-WAN Configuration Steps

    To configure SD-WAN on a FortiGate device, follow these step-by-step instructions:

    1. Enable SD-WAN Feature: Navigate to System > Feature visibility and ensure the SD-WAN option is selected.
    2. Remove WAN Interfaces from Policies: Go to Policy & Objects > Firewall Policy and remove WAN interfaces from any existing policies to avoid losing internet connection.
    3. Create SD-WAN Interface: Navigate to Network > SD-WAN and create a new SD-WAN interface. Click “Create New SD-WAN Member” on all ports used in SD-WAN.
    4. Configure SD-WAN Members: For each WAN interface, assign the correct network gateway address. For example, set the wan1 interface Addressing mode to DHCP and Distance to 10, and set the wan2 interface IP/Netmask to 10.100.20.1 255.255.255.0.
    5. Enable SD-WAN: In the SD-WAN Interface Members table, click “Create New,” select the interface, and set the appropriate gateway and cost. Set the status to Enable and click OK.
    6. Configure SD-WAN Rules: Define SD-WAN rules to steer traffic based on business applications. These rules are matched in order, and the first match applies to the traffic.
    7. Install Device Settings: Use FortiManager to install device settings, including creating interfaces, building VPN tunnels, and setting up BGP adjacencies. Preview the changes before installation to ensure accuracy.
    8. Map Interfaces: Map your interfaces to Normalized Interfaces so that Policy Packages will install correctly.
    9. Install Policy Packages: Go to Policy & Objects and click Install on the top blue bar. Preview the install before proceeding to ensure all settings are correct.
    Photo by Vladimir Srajber on Pexels.com
  • Python script to check the Cisco IOS version and perform upgrades or downgrades as needed

    This script will utilize the Netmiko library for SSH connections and the NAPALM library for device configuration management.

    Script Requirements

    1. Python 3.x
    2. Netmiko library (install using pip install netmiko)
    3. NAPALM library (install using pip install napalm)
    4. Cisco IOS device(s) with SSH enabled
    5. A configuration file (e.g., config.yaml) defining the recommended IOS versions for each device model
    6. A directory containing the IOS image files (e.g., images/) matching the device models and recommended versions

    Script Structure

    The script will consist of the following components:

    1. Device Connection: Establish an SSH connection to the Cisco device using Netmiko.
    2. IOS Version Check: Retrieve the current IOS version from the device using NAPALM.
    3. Configuration Check: Compare the current IOS version with the recommended version defined in the configuration file.
    4. Upgrade/Downgrade: Perform the necessary upgrade or downgrade using NAPALM, if the current version does not match the recommended version.
    5. Image Transfer: Transfer the required IOS image file from the images/ directory to the device using SCP (or other transfer method).

    Script Code

    Here’s a sample script to get you started:

    import os
    import yaml
    from netmiko import SSHNetmiko
    from napalm.base import get_network_driver
    
    # Configuration file path
    config_file = 'config.yaml'
    
    # Device model to IOS image mapping
    device_models = {
        'WS-C3560X-48P': 'c3560e-universalk9-mz.122-55.SE8.bin'
    }
    
    # Recommended IOS versions for each device model
    recommended_versions = {
        'WS-C3560X-48P': '15.2(4)E8'
    }
    
    def get_current_ios_version(device):
        # Establish SSH connection using Netmiko
        ssh = SSHNetmiko(device['ip'], username='your_username', password='your_password')
        # Retrieve current IOS version using NAPALM
        ios_version = ssh.get_facts()['ios_version']
        return ios_version
    
    def check_ios_version(current_version, recommended_version):
        if current_version != recommended_version:
            return True  # Version mismatch, upgrade/downgrade required
        return False  # Version matches, no action needed
    
    def upgrade_or_downgrade(device, current_version, recommended_version):
        # Determine upgrade/downgrade direction
        if current_version < recommended_version:
            direction = 'upgrade'
        elif current_version > recommended_version:
            direction = 'downgrade'
        else:
            return  # No action needed
    
        # Transfer required IOS image file using SCP
        image_file = os.path.join('images/', device_models[device['model']])
        ssh.scp.put(image_file, '/tmp/')
    
        # Perform upgrade/downgrade using NAPALM
        if direction == 'upgrade':
            ssh.load_replace_candidate(filename='/tmp/' + image_file)
            ssh.commit_config()
        elif direction == 'downgrade':
            ssh.load_replace_candidate(filename='/tmp/' + image_file, replace='exact')
            ssh.commit_config()
    
        # Reload the device to apply changes
        ssh.send_command('reload')
    
    def main():
        with open(config_file, 'r') as f:
            config_data = yaml.safe_load(f)
    
        for device in config_data['devices']:
            current_version = get_current_ios_version(device)
            recommended_version = recommended_versions[device['model']]
            if check_ios_version(current_version, recommended_version):
                upgrade_or_downgrade(device, current_version, recommended_version)
    
    if __name__ == '__main__':
        main()

    Note

    1. Replace your_username and your_password with your actual SSH credentials.
    2. Update the device_models dictionary to match your specific device models and corresponding IOS image files.
    3. Modify the recommended_versions dictionary to reflect the desired IOS versions for each device model.
    4. Ensure the images/ directory contains the required IOS image files.
    5. This script is a starting point and may require additional error handling, logging, and testing to ensure its reliability.

    Remember to test the script in a lab environment before deploying it to production :)