question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vlan database in Cisco Router

See original GitHub issue

I am using the Cisco 3745 Multi-service router in GNS3 and creating vlans. To create vlans I need to send these commands in priv exec mode.

S3#vlan database
S3(vlan)#vlan 10 name my_vlan
VLAN 10 added:
    Name: my_vlan
S3(vlan)#exit
S3#

I am using the below code with NETMIKO:

for n in range (2,21):
   print "Creating VLAN " + str(n)
   config_commands = ['vlan database', 'vlan ' + str(n) + ' name Python_VLAN_' + str(n)]
   output = net_connect.send_config_set(config_commands)
   print output 

The problem is that if I use .send_config_set it will enter the config mode, whereas the vlan database command works in exec mode.

If I use .send_command

config_commands = ['vlan database', 'vlan ' + str(n) + ' name Python_VLAN_' + str(n)]
output = net_connect.send_command(config_commands)

the code doesn’t work and I have to ctrl+c to stop the script.

It seems that the code is executed and as it enters the “vlan database” mode it is unable to execute the next commands.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
farhanahmed77commented, Aug 29, 2018

@ktbyers Thanks that worked. So, we are specifying manually the config mode to ‘vlan database’ instead of conf t.

0reactions
asirajahmedcommented, Feb 5, 2019

Well, here is the exact solution which works

from netmiko import ConnectHandler

iosv_l2 = {
        'device_type': 'cisco_ios',
        'ip': '192.168.122.51',
        'username': 'siraj',
        'password': 'cisco',
}

net_connect = ConnectHandler(**iosv_l2)

config_commands = ['vlan 11 name Python_VLAN_11', 'exit']
output = net_connect.send_config_set(config_commands, config_mode_command='vlan database')

# for creating a range of VLAN's

for n in range (21,26):
    print ("Creating VLAN " + str(n))
    config_commands = ['vlan {} name Python_VLAN_{}'.format(n,n), 'exit']
    output = net_connect.send_config_set(config_commands, config_mode_command='vlan database')
    print (output)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: vlan's on router - Cisco Community
Solved: Hi Seniors, I understand that vlan's can be created on cisco switches but last day I was looking on the configuration of...
Read more >
How To Configure VLANs On the Catalyst Switches
Configuring Vlan using VLAN database mode: · 1) Issue the "vlan database" command at the enable prompt in order to enter the VLAN...
Read more >
Create Ethernet VLANs on Catalyst Switches - Cisco
You can create VLANs in either VLAN database mode or global configuration mode. You must create VLANs that are numbered higher than 1005...
Read more >
Configuring VLANs - Cisco
Switches running the LAN Base feature set support only static routing on SVIs. • A VLAN should be present in the switch to...
Read more >
Solved: "vlan database" mode; What is it? - Cisco Community
You can configure normal-range VLANs (from 1-1005) in VLAN database mode, whereas you need to use config-vlan mode to configure extended-range VLANs (1006-4095) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found