Monthly Archives: July 2017

Quick and Easy Junos Labs with Vagrant and VirtualBox

It’s been far too long since my last blog post, mainly due to the fact that my spare time recently has been taken up with authoring a series of courses over at Pluralsight for the Juniper JNCIA-Junos certification, which are due to be published in October this year.

Anyway, with this in mind, there are a few options out there for building a Junos lab including getting hold of an evaluation version of the vSRX platform that is free to use for 60 days. Now, this is great and is definitely a good option, however, there is an even better option and that is using Vagrant to build out a virtual lab using the vSRX image. This is freely available and incredibly simple to set up. I’ve done this from scratch on both a Windows 10 laptop and a Macbook Pro – and both times I was logged into a virtual router running Junos within 15 minutes. Hat’s off to @Mierdin for his original blog post that outlined this way back 2015.

I’ve based this on a Windows install, but the process is the same for OSX.

What you’ll need…

Vagrant

Start by installing Vagrant. Vagrant allows you to spin up virtual environments quickly and easily utilising various vritualization platforms such as virtualbox and vmware.

VirtualBox

Next up we need to install VirtualBox as our platform to run the vSRX images on.

Git

Finally we need to install Git as we will be cloning the Git repository that contains everything we need to get up and running.

Once you have these 3 pre-requisites installed, simply do the following:

Clone the git repository:

U:\>git clone https://github.com/JNPRAutomate/vagrant-junos.git
Cloning into 'vagrant-junos'...
remote: Counting objects: 208, done.
remote: Total 208 (delta 0), reused 0 (delta 0), pack-reused 208
Receiving objects: 100% (208/208), 28.28 KiB | 0 bytes/s, done.
Resolving deltas: 100% (83/83), done.

cd into the newly created vagrant-junos directory and install the Junos and Vagrant host shell plugins:

U:\>cd vagrant-junos

U:\vagrant-junos>vagrant plugin install vagrant-junos
Installing the 'vagrant-junos' plugin. This can take a few minutes...
Fetching: vagrant-share-1.1.9.gem (100%)
Fetching: vagrant-junos-0.2.1.gem (100%)
Installed the plugin 'vagrant-junos (0.2.1)'!

U:\vagrant-junos>vagrant plugin install vagrant-host-shell
Installing the 'vagrant-host-shell' plugin. This can take a few minutes...
Fetching: vagrant-host-shell-0.0.4.gem (100%)
Installed the plugin 'vagrant-host-shell (0.0.4)'!

Lastly start your vSRX up:

U:\vagrant-junos>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'juniper/ffp-12.1X47-D15.4-packetmode'...
.
.
.
==> default: Configuring and enabling network interfaces...

Then you can simply ssh into your new router from within Vagrant:

U:\vagrant-junos>vagrant ssh
--- JUNOS 12.1X47-D15.4 built 2014-11-12 02:13:59 UTC
root@vagrant-junos-test% cli
root@vagrant-junos-test>

How good is that! So at this point, you have a single instance of a vSRX up and running in Packet Mode, which means it is acting as a router with firewalling features turned off, so it’s great for getting to know Junos. Now, if we want to take this a step further and let’s say build a 2 router lab, with the routers connected together over interface ge0/0/1 (ge0/0/0 is used for SSH management from Vagrant), all we need to do is destroy the current lab by exiting from the router and issuing the ‘vagrant destroy’ command:


root@vagrant-junos-test> exit
root@vagrant-junos-test% exit
logout
Connection to 127.0.0.1 closed.

U:\vagrant-junos>vagrant destroy
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...

Then we edit the file ‘Vagrantfile’ to build our 2 router network. Mine looks like this:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# ge-0/0/0.0 defaults to NAT for SSH + management connectivity
# over Vagrant's forwarded ports.  This should configure ge-0/0/1.0
# through ge-0/0/7.0 on VirtualBox.

######### WARNING: testing only! #########
######### WARNING: testing only! #########
######### WARNING: testing only! #########
#
# this Vagrantfile can and will wreak havoc on your VBox setup, so please
# use the Vagrant boxes at https://atlas.hashicorp.com/juniper unless you're
# attempting to extend this plugin (and can lose your VBox network config)
# TODO: launch VMs from something other than travis to CI all features
#
# Note: VMware can't name interfaces, but also supports 10 interfaces
# (through ge-0/0/9.0), so you should adjust accordingly to test
#
# Note: interface descriptions in Junos don't work yet, but you woud set them
# here with 'description:'.


Vagrant.configure(2) do |config|
  config.vm.box = "juniper/ffp-12.1X47-D15.4-packetmode"

  config.vm.provider "virtualbox" do |vb|
    vb.memory = 512
    vb.cpus = 2
    vb.gui = false
  end

  config.vm.define "r1" do |r1|
    r1.vm.host_name = "r1"
    r1.vm.network "private_network",
                     ip: "192.168.1.1",
                     virtualbox__intnet: "1-2"
  end

  config.vm.define "r2" do |r2|
    r2.vm.host_name = "r2"
    r2.vm.network "private_network",
                     ip: "192.168.1.2",
                     virtualbox__intnet: "1-2"
  end
end

Note that we have defined the memory and number of CPU cores to use also in this file (2048MB is the default memory, but I have been running with 512 with no issues so far). So, let’s start up the lab again and this time it will reference our new Vagrantfile:


U:\vagrant-junos>vagrant up

……and after a couple of minutes, both routers are up and running and connected to each other:


U:\vagrant-junos>vagrant ssh r2
--- JUNOS 12.1X47-D15.4 built 2014-11-12 02:13:59 UTC
root@r2% cli
root@r2> show interfaces terse | match 192
ge-0/0/1.0 up up inet 192.168.1.2/24

root@r2> ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=64 time=60.692 ms
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.916 ms
^C
--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.916/31.304/60.692/29.388 ms

root@r2>

Happy labbing!