How to Create Multiple VLANs with Python Script

Vlan stands for virtual local area network. Creating a VLAN is an important part of the configuration of a switch. n this article, we will write a script and run this script to create Multiple VLANs with Python script on a switch. We will perform this lab in EVE-NG software.

Creating Management Cloud in the EVE-NG

            Run the eve-ng and open the network. We will create a cloud and will open a layer 2 switch. The cloud will directly connect to a switch. We connected Vmware Vmnet8 to the eve-ng cloud. The Vmnet 8 IP is 192.168.2.1/24.  The Switch IP is 192.168.2.129/24.

Click on the Plus (+) sign at the left side in eve-ng, and then click on Network.

Add network

Click on the “Type” of the network and select “Management (Cloud0)”.

Management Cloud

When you select Management Cloud, then save it by clicking on the save button.

Save

Click on Add an object and select Node.

Add node

Add a layer 2 switch iOS image, and then save it.

Add layer 2 switch

The cloud represents our real network (PC).

Topology for How to create Multiple vlan through python script

Check the Vmnet8 IP address.

VMnet 8

The IP address of Vmnet8 is 192.168.2.1/24.

set IP of VMnet

Configure the IP address of a switch as 192.168.2.129/24. Create a user in it and also configure the Line VTY also.

create username and password

Configure the default gateway of Vmnet8.

Set default gateway

Python Script for Creating Vlans

Now we will write a Python script to create vlans e.g. valn1, vlan2, and vlan3 with their names.

Now open the cmd, and go to the specified directly via the cd command. At last, run the script via “py vlanscript_1.py”.

Now we will check the switch to whether VLANs are created or not. Via the “show vlan” command.

Creating Bulk Vlans

We have created 3 vlans which are vlan11, vlan12, and vlan13. Suppose you are asked to create multiple VLANs. In the next script with the same topology, I am going to create multiple VLANs which will be from “vlan41 to vlan80”. I will create vlans from 41 to 81 through for loop having range from 41 to 81. It will vlans from vlan41 to vlan80. Save the script via name “vlanscript_forloop_2.py”.

Python script for How to Create Multiple VLANs with Python Script

Run the script in cmd.

run the script

Verify the script on switch through show command, whether it has created vlans or not.

show vlan at switch

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *