Quick and Easy Junos Labs with Vagrant and VirtualBox

By | July 25, 2017

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…


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


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


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

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
Connection to 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

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

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

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

root@r2> ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=60.692 ms
64 bytes from icmp_seq=1 ttl=64 time=1.916 ms
--- 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


Happy labbing!

13 thoughts on “Quick and Easy Junos Labs with Vagrant and VirtualBox

  1. Els

    I can’t seem to install the plugins because vagrant isn’t recognized as a command….

    “‘vagrant’ is not recognized as an internal or external command, operable program or batch file. “

  2. will

    when I do vagrant up, i see loaderror cannot load such file — vagrant-host-shell.

    any idea?

    1. Rich Bibby Post author

      did you follow the step to install the vagrant host plugin?

      U:\vagrant-junos>vagrant plugin install vagrant-host-shell

  3. Eric

    This is very powerful (and appears somewhat simple) for use in learning JUNOS. Have you , by chance, updated it with a newer, more relevant version of vSRX?

    1. Rich Bibby Post author

      Hi Eric. Thanks for the feedback. No, I haven’t updated it I’m afraid. I’m sure other’s will have though.

  4. Sushil

    esustej@US-00001365 MINGW64 ~/vagrant-junos (master)
    $ vagrant ssh
    ssh_exchange_identification: read: Connection reset by peer

    I got above error when i tried to run the “Vagrant SSH” command.
    Can anyone tell me how can i fix this please

      1. Sushil

        Thanks Rich for quick response. Yes, this is windows machine and BIOS settings are blocked by Admin.
        I will work on getting the BIOS settings enabled.

  5. Sean

    I worked great! Thanks. Fyi, if you want to directly ssh from one router to the other you can use username root with password of Juniper.


Leave a Reply

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