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…

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!

33 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. “

    Reply
  2. will

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

    any idea?

    Reply
    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

      Reply
  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?

    Reply
    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.
      Rich

      Reply
  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

    Reply
      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.

        Reply
  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.

    Reply
  6. Daniel

    Hi Rich,

    Can you take a look at this output; it’s getting stuck:

    C:\vagrant-junos>vagrant up
    Bringing machine ‘default’ up with ‘virtualbox’ provider…
    ==> default: Box ‘juniper/ffp-12.1X47-D15.4-packetmode’ could not be found. Attempting to find and install…
    default: Box Provider: virtualbox
    default: Box Version: >= 0
    ==> default: Loading metadata for box ‘juniper/ffp-12.1X47-D15.4-packetmode’
    default: URL: https://vagrantcloud.com/juniper/ffp-12.1X47-D15.4-packetmode
    ==> default: Adding box ‘juniper/ffp-12.1X47-D15.4-packetmode’ (v0.5.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/juniper/boxes/ffp-12.1X47-D15.4-packetmode/versions/0.5.0/providers/virtualbox.box
    default: Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com
    default:
    ==> default: Successfully added box ‘juniper/ffp-12.1X47-D15.4-packetmode’ (v0.5.0) for ‘virtualbox’!
    ==> default: Importing base box ‘juniper/ffp-12.1X47-D15.4-packetmode’…
    ==> default: Matching MAC address for NAT networking…
    ==> default: Checking if box ‘juniper/ffp-12.1X47-D15.4-packetmode’ version ‘0.5.0’ is up to date…
    ==> default: Setting the name of the VM: vagrant-junos_default_1554240364618_16169
    ==> default: Clearing any previously set network interfaces…
    ==> default: Preparing network interfaces based on configuration…
    default: Adapter 1: nat
    default: Adapter 2: intnet
    default: Adapter 3: intnet
    default: Adapter 4: intnet
    default: Adapter 5: intnet
    default: Adapter 6: intnet
    default: Adapter 7: intnet
    default: Adapter 8: intnet
    ==> default: Forwarding ports…
    default: 22 (guest) => 2222 (host) (adapter 1)
    ==> default: Booting VM…
    ==> default: Waiting for machine to boot. This may take a few minutes…
    default: SSH address: 127.0.0.1:2222
    default: SSH username: root
    default: SSH auth method: private key
    Timed out while waiting for the machine to boot. This means that
    Vagrant was unable to communicate with the guest machine within
    the configured (“config.vm.boot_timeout” value) time period.

    If you look above, you should be able to see the error(s) that
    Vagrant had when attempting to connect to the machine. These errors
    are usually good hints as to what may be wrong.

    If you’re using a custom box, make sure that networking is properly
    working and you’re able to connect to the machine. It is a common
    problem that networking isn’t setup properly in these boxes.
    Verify that authentication configurations are also setup properly,
    as well.

    If the box appears to be booting properly, you may want to increase
    the timeout (“config.vm.boot_timeout”) value.

    Reply
    1. Tyson

      Hi, I had the same issue “Timed out while waiting for the machine to boot.” using MacOS Mojave.
      I fixed it by downgrading from VirtualBox from version 6 to version 5.2.
      VirtualBox 6.0 no longer supports 32 bit operating systems.

      Reply
    2. Paul Basondole

      I am getting the same error too and I’m running VirtualBox Version 5.2.28 r130011 (Qt5.6.2) and Vagrant version 2.2.4 on windows 10.
      Tried to change the authentication method from private key to password and still get the same error.

      ==> r1: Waiting for machine to boot. This may take a few minutes…
      r1: SSH address: 127.0.0.1:2222
      r1: SSH username: root
      r1: SSH auth method: password
      Timed out while waiting for the machine to boot. This means that
      Vagrant was unable to communicate with the guest machine within
      the configured (“config.vm.boot_timeout” value) time period.

      Also note the machine boots up properly and I can login from the VirtualBox console with username “root” and password “Juniper” Any idea what to try next to get it working with vagrant will be appreciated

      Reply
  7. Daniel

    And here’s the output when I tried vagrant up a second time:

    C:\vagrant-junos>vagrant up
    Bringing machine ‘default’ up with ‘virtualbox’ provider…
    ==> default: Checking if box ‘juniper/ffp-12.1X47-D15.4-packetmode’ version ‘0.5.0’ is up to date…

    C:\vagrant-junos>vagrant ssh
    ssh_exchange_identification: read: Connection reset

    Reply
  8. Sean

    Can you show me how to set up a 3 router network? Not quite sure how to get 3 routers connected. Thanks.

    Reply
    1. Rich Bibby Post author

      Hi Sean,
      just edit the file called ‘Vagrantfile’ to add the 3rd router and 2 new network segments. something like this should do it:

      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”
      ip: “192.168.2.1”,
      virtualbox__intnet: “1-3”
      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”
      ip: “192.168.3.1”,
      virtualbox__intnet: “2-3”
      end

      config.vm.define “r3” do |r3|
      r3.vm.host_name = “r3”
      r3.vm.network “private_network”,
      ip: “192.168.2.2”,
      virtualbox__intnet: “1-3”
      ip: “192.168.3.2”,
      virtualbox__intnet: “2-3”
      end

      Rich

      Reply
      1. Sean

        Rich,
        Thank You! Didn’t realized you had responded. I’m just checking back to this as I’m a Cisco guy who needs to get Junos certified in the next 2 Months.

        Reply
  9. magda

    Hi All,

    I have virtualization enabled and I have this issue below:

    efuentes-mbp:multi-vagrant efuentes$ vagrant up –provider=juniper
    The provider ‘juniper’ could not be found, but was requested to
    back the machine ‘default’. Please use a provider that exists.

    efuentes-mbp:multi-vagrant efuentes$ cd vagrant-junos/
    efuentes-mbp:vagrant-junos efuentes$ vagrant up
    There are errors in the configuration of this machine. Please fix
    the following errors and try again:

    AWS Provider:
    * One or more of the needed AWS credentials are missing. No environment variables
    are set nor profile ‘default’ exists at ‘/Users/efuentes/.aws/’
    * An access key ID must be specified via “access_key_id”
    * A secret access key is required via “secret_access_key”
    * An AMI must be configured via “ami” (region: #{region})

    efuentes-mbp:vagrant-junos efuentes$

    Reply
  10. Trevor Wood

    I have Ubuntu 18.04.4 LTS 64-bit running and using the command line loaded Vagrant, VirtualBox and Git

    When loading ‘vagrant plugin install vagrant-junos

    Installing plugin takes few minutes etc……Then
    conflicting dependency fog-core (~> 1.43.0) and fog-core (= 1.45.0)
    Activated fog-core-1.45.0
    which does not match conflicting dependency (~> 1.43.0)
    Conflicting dependency chains: fog-core (= 1.45.0), 1.45.0 activated

    In other words I cannot get passed this stage due to the ‘fog-core’ file issue

    Reply
  11. Trevor Wood

    Seem to have fixed the ‘fog-core’ issue after checking out some of the chats online at github.
    I had vagrant 2.0.2 installed and there seems to be a bug associated with this.
    Followed the chat advice to install a newer version.
    I was able to install vagrant 2.0.3 and this worked as the instructions above.

    Working through the Juniper course on Pluralsight and so far so good.

    Reply
    1. Rich Bibby Post author

      Glad you got it sorted Trevor! Enjoy the course and thanks for viewing it! Hope you find it useful.
      Rich

      Reply
    1. Rich Bibby Post author

      it might depend on where you’ve installed it, but it should be in C:\vagrant-junos

      Reply
  12. sidney

    is this a known issue to install the plugins

    Vagrant failed to load a configured plugin source. This can be caused
    by a variety of issues including: transient connectivity issues, proxy
    filtering rejecting access to a configured plugin source, or a configured
    plugin source not responding correctly. Please review the error message
    below to help resolve the issue:

    timed out (https://gems.hashicorp.com/specs.4.8.gz)

    Source: https://gems.hashicorp.com/

    Reply
  13. Gustavo

    Hi, I can’t ping any router in any demo. I followed the instructions. Is there anything to do regarding the links, as in GNS23 for example?

    Reply

Leave a Reply

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