How to setup GNS3 for Network automation using Python

There is no need for me to explain the importance of learning a programming language. However, often network engineers find it difficult to understand the concepts of programming and apply then knowledge to their respective field.

I am not going to talk about python in general, although we will talk about all the basic constructs & concepts of Python. This course is specifically targeted for making a network engineers life easier using Python.

In order to practice we will need a few routers & switches & a machine with python installed which can communicate with these routers & switches on the network. I am going to use GNS3 in this lab environment. You can use real equipment or any other software such as EVE-NG or Cisco VIRL.

How to setup GNS3:

I am using a windows laptop for this setup, you can use a MAC or Linux box and achieve the same results, the process to set GNS3 might slightly differ but would be very similar.

  1. Download GNS3 using this [link ](Software | GNS3)
  2. Download the GNS3 VM as well.
  3. It is important that the GNS3 VM as well as the GNS3 desktop software needs to be the same version, else you will get some compatibility issues.
  4. Now, to run the GNS3 VM, you would require a Hypervisor, You can use either VirtualBox or VMware workstation on a windows platform. I will use VMware workstation for my setup as there are some limitations with using VirtualBox.

Install the GNS3 Desktop software as usual, just leave the default settings & proceed with the installation.

In the installation process, GNS3 might do a silent install of additional software such as Wireshark etc… which is normal. Once the installation is complete. you should see the local server running as shown in the below screenshot.

Now exit the GNS3 desktop software & install VMware workstation. It should be noted that the Microsoft Hyper-V should be disabled on the computer. Else you will encounter issues. Simply navigate to Tun on/off windows features & make sure the Hyper-V is disabled. You may run into an issue which says that VT-X is not supported on this platform especially on Windows 11. You can use the below method which resolves the problem.

  1. Open PowerShell with admin privileges & run the below commands
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
dism.exe /Online /Disable-Feature:VirtualMachinePlatform
dism.exe /Online /Disable-Feature:Microsoft-Windows-Subsystem-Linux
bcedit /set hypervisorlaunchtype off 
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All 
Disable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform
  1. In Windows Security (Find Windows Security from Start menu), Navigate to Device Security -> Core Isolation details and disable Core Isolation, Disable Memory Integrity too.
  2. Open local group policy editor. Use Win + R, Enter gpedit.msc, Press Enter key
  3. Navigate to Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Device Guard
  4. Double Click Turn On Virtualization Based Security Set to Disabled and Press OK button
  5. Open Control Panel, Find Windows Features, Disable/Uncheck Virtual Machine Platform and Press OK button

Once VMware workstation installation is completed, Import the GNS3 VM you downloaded from the GNS3 website to VMWare Workstation. Do not edit any properties of the VM such as memory or disk size or processors from VMware Workstation. The only thing, you might change is the Network adapters. In my case, I am going to set one of the Network adapter to Bridge mode so that the devices inside my GNS3 topology can access the Internet.

Do not power on the Virtual Machine. Now open the GNS3 Desktop. Navigate to edit –> preferences & Select the GNS3 VM and enable it. Click apply and wait for the GNS3 VM to automatically start & now you should see the GNS3 VM server running as well.

If you want to increase the memory or CPU for the GNS3 VM, it needs to be done from GNS3 Desktop which does an API call to the VM.

The more resources you have the larger your topology can be. I just have 8 Gig’s of RAM on this laptop so I allocated it 2 GIG’s.

Now, when it comes to images that we need, you need to download the images from Cisco Portal & it requires a Valid license. I am not able to share the images here due to copy right & legal issues. You can download them from cisco site or rumor has it that they are available elsewhere on the internet.

I am going to use a Router here for testing. Go to the Routers section and click add template & choose install on GNS3 VM. I am going to install VIRL image router. GNS3 will by default scan the downloads folder and GNS3 install folder and will let you know if it found an image. In my case, it is not found so I am going to choose my custom version.

Click on create Version & select the file & import the image. I simply named my Image as Vios Router

Once that is done, I am able to see the router in my GNS3.

Now go to End devices in GNS3 & click Add template. Install the appliance on GNS3 VM

Now under Guests , Choose the network automation container & install it. The network automation container is a docker image that has Python pre installed on it.

Now, since we have both a Router & Automation Container templates installed. Let us see how we can assign an IP to the automation container etc..

Create a new Project in GNS3 & I am going to create a Sample topology like shown below. When you pull the Network Automation server on to the workspace, the image gets pulled automatically from the repository..

I am assigning a static IP address to the Automation server, It can be done by right clicking and selecting edit configuration. Uncomment the lines of where static IP is assigned and save the configuration.

The automation server comes with python installed

The router interface Gi0/0 has been configured with the below configuration.

interface GigabitEthernet0/0
 ip address 10.1.1.2 255.255.255.0
 duplex auto
 speed auto
 media-type rj45
end
Router#

Since, IP addresses have been assigned, I am able to ping the Router from the Automation server & Vice versa. The switch in middle is an unmanaged GNS3 ether Switch.

error: Content is protected !!