Building a Cisco IOSv Layer-2 Vagrant Libvirt Box
Cisco IOSvL2 is supported by the netlab libvirt package command. To build an IOSvL2 box:
Create an empty directory on a Ubuntu machine with libvirt and Vagrant.
Copy the IOSvL2 disk image (
.vmdk
or.qcow
file) into that directory. The image name should start withvios_l2
or you might not have an IOSv Layer-2 image.Execute netlab libvirt package iosvl2 virtual-disk-file-name and follow the instructions
Warning
The Cisco IOSv layer-2 image uses slightly different configuration commands and system defaults than the IOSv image and must be built as a separate Vagrant box.
If you’re using a netlab release older than 1.8.2, or if you’re using a Linux distribution other than Ubuntu, please read the box-building caveats first.
Initial Device Configuration
During the box-building process (inspired by this recipe) you’ll have to copy-paste initial device configuration. netlab libvirt config iosvl2 command displays the build recipe:
Creating initial configuration for Cisco IOSv L2 image
======================================================
* Answer 'no' to the 'Would you like to enter the initial configuration dialog' prompt
* Press ENTER to start a CLI session
* Go into enable mode, enter configuration mode
* Copy-paste the following configuration (see also NOTE below the configuration)
======================================================
hostname iosvl2
no ip domain lookup
ip domain name lab.local
!
no service config
!
crypto key generate rsa modulus 2048
ip ssh version 2
!
aaa new-model
!
aaa authentication login default local
aaa authorization exec default local
!
username vagrant privilege 15 secret vagrant
!
ip ssh pubkey-chain
username vagrant
key-hash ssh-rsa DD3BB82E850406E9ABFFA80AC0046ED6
!
vrf definition MGMT
description Management interface
!
address-family ipv4
exit-address-family
!
interface GigabitEthernet0/0
no switchport
vrf forwarding MGMT
description vagrant-management
ip address dhcp
no shutdown
!
line vty 0 4
transport input ssh
!
event manager applet ENABLE-MGMT
event syslog pattern "SYS-5-RESTART"
action 0 cli command "enable"
action 1 cli command "conf t"
action 2 cli command "interface GigabitEthernet0/0"
action 3 cli command "no shutdown"
action 4 cli command "exit"
action 5 cli command "crypto key generate rsa modulus 2048"
!
end
=============================================
NOTE:
* On a system with slow CPU, you might have to change the "event syslog ..."
trigger to "event timer countdown time 5"
After copying the configuration:
* Exit the configuration mode
* Save the configuration with 'wr mem'
* Disconnect from console (ctrl-] usually works).