Introduction
If your are preparing for my JNCIA certification you come to the right place.
I figured out that every tutorial in the internet has the need to buy a JUNOS device or paid a cloud laboratory. I decide to make my own instead.
Today i would guide you to have your own lab up and running with Virtual Box, Vagrant and a SRX box from vagrantcloud.
Prerequisites
You will need to install some things that are out of scope here:
- Installing Virtual Box
- Installing Vagrant
I used Ubuntu 18.04 but any other Linux distribution should work.
This not pretend to be an Vagrant tutorial, the goal here is to setup a Junos Lab.
Vagrant plugins
You will need to install some plugins to allow Vagrant communicate with the JUNOS shell.
You might know JUNOS is not a Linux distribution or at least not an standard one.
vagrant plugin install vagrant-host-shell vagrant-junos
The Vagrantfile
The way Vagrant works like Infrastructure as Code "IaC" through a file. This is a Ruby file where you describe your VM environment setup.
Then, Vagrant do its magic, setup all entire environment for you with the VMs and networks.
Don't worry about Ruby, you don't need to know any. You only need to describe your environment like the following examples.
Filename: Vagrantfile
servers=[
{
:hostname => "junos-router",
:private_network => [
{
:ip => "10.10.10.1",
:virtualbox__intnet => "red_interna"
}
],
:box => "juniper/ffp-12.1X47-D15.4-packetmode",
:ram => 512,
:cpu => 2
}
]
image
Vagrant.configure(2) do |config|
servers.each do |machine|
config.vm.define machine[:hostname] do |node|
node.vm.box = machine[:box]
node.vm.hostname = machine[:hostname]
machine[:private_network].each do |pnetwork|
node.vm.network "private_network",
ip: pnetwork[:ip],
virtualbox__intnet: pnetwork[:virtualbox__intnet]
end
node.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", machine[:ram]]
end
end
end
end
Let analyse the Vagrantfile:
servers is an array with definition of all servers involved
Every server has attributes, such as ram, cpu. You should adapt this to your possibilities.
box attribute is the most important this is a reference to a "box image" at de vagrantcloud website. This is the VM image that we will run.
"juniper/ffp-12.1X47-D15.4-packetmode" is a JUNOS image to work with Vagrant and Virtual Box.
The rest of code is about the instantiation of the VM itself written in a way that we can don't worry about. So we can add many servers to the array as we want. Or at least, our hardware support.
Next step is to run the Lab.
Running the lab
Move in your terminal to the same directory than your Vagrantfile and up the environment.
vagrant up
The first time the vagrant will download the box, so it could take a wile. The next time should be faster to set up.
When setting up finish you can connect to the router. Notice that this method will log you in as root user.
// If only setup one VM
vagrant ssh
// if you setup more than one vm add the "hostname" to the command.
vagrant ssh junos-router
Finally you will acceded as root, remember so remember to get in the cli mode. but you already know this because you are preparing your JNCIA :D.
--- JUNOS 12.1X47-D15.4 built 2014-11-12 02:13:59 UTC
root@junos-router% cli
root@junos-router>
You can save your lab changes by using the suspend command. This will keep the VMs but will free RAM and CPU resources. Then, when you finish, destroy the lab to free disk space.
/* To save the lab changes but free resources use */
vagrant suspend
/* To resume suspended labs */
vagrant resume
/* To free vms disk space */
vagrant destroy
Setting up a custom topology.
Well done! you have your JUNOS VM up and running.
Next step will be to add more devices to your environment.
We can add some alpine vms to simulate final host clients with the "generic/alpine39" box.
Here some topology examples Vagranfiles.
One "router" and two "clients" (1r-2c)
servers=[
{
:hostname => "R1",
:private_network => [
{
:ip => "192.168.1.1",
:virtualbox__intnet => "R1-C1"
},
{
:ip => "192.168.2.1",
:virtualbox__intnet => "R1-C2"
}
],
:box => "juniper/ffp-12.1X47-D15.4-packetmode",
:ram => 512,
:cpu => 2
},
{
:hostname => "C1",
:private_network => [
{
:ip => "192.168.1.2",
:virtualbox__intnet => "R1-C1"
}
],
:box => "generic/alpine39",
:ram => 64,
:cpu => 1
},
{
:hostname => "C2",
:private_network => [
{
:ip => "192.168.2.2",
:virtualbox__intnet => "R1-C2"
}
],
:box => "generic/alpine39",
:ram => 64,
:cpu => 1
},
]
Vagrant.configure(2) do |config|
servers.each do |machine|
config.vm.define machine[:hostname] do |node|
node.vm.box = machine[:box]
node.vm.hostname = machine[:hostname]
machine[:private_network].each do |pnetwork|
node.vm.network "private_network",
ip: pnetwork[:ip],
virtualbox__intnet: pnetwork[:virtualbox__intnet]
end
node.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", machine[:ram]]
end
end
end
end
Three "routers" and Three "clients" (3r-3c)
servers=[
{
:hostname => "R1",
:private_network => [
{
:ip => "10.0.12.12",
:virtualbox__intnet => "R1-R2"
},
{
:ip => "10.0.13.13",
:virtualbox__intnet => "R1-R3"
},
{
:ip => "192.168.1.1",
:virtualbox__intnet => "R1-C1"
}
],
:box => "juniper/ffp-12.1X47-D15.4-packetmode",
:ram => 512,
:cpu => 2
},
{
:hostname => "R2",
:private_network => [
{
:ip => "10.0.12.21",
:virtualbox__intnet => "R1-R2"
},
{
:ip => "10.0.23.23",
:virtualbox__intnet => "R2-R3"
},
{
:ip => "192.168.2.1",
:virtualbox__intnet => "R2-C2"
}
],
:box => "juniper/ffp-12.1X47-D15.4-packetmode",
:ram => 512,
:cpu => 2
},
{
:hostname => "R3",
:private_network => [
{
:ip => "10.0.13.31",
:virtualbox__intnet => "R1-R3"
},
{
:ip => "10.0.23.32",
:virtualbox__intnet => "R2-R3"
},
{
:ip => "192.168.3.1",
:virtualbox__intnet => "R3-C3"
}
],
:box => "juniper/ffp-12.1X47-D15.4-packetmode",
:ram => 512,
:cpu => 2
},
{
:hostname => "C1",
:private_network => [
{
:ip => "192.168.1.2",
:virtualbox__intnet => "R1-C1"
}
],
:box => "generic/alpine39",
:ram => 64,
:cpu => 1
},
{
:hostname => "C2",
:private_network => [
{
:ip => "192.168.2.2",
:virtualbox__intnet => "R2-C2"
}
],
:box => "generic/alpine39",
:ram => 64,
:cpu => 1
},
{
:hostname => "C3",
:private_network => [
{
:ip => "192.168.3.2",
:virtualbox__intnet => "R3-C3"
}
],
:box => "generic/alpine39",
:ram => 64,
:cpu => 1
}
]
Vagrant.configure(2) do |config|
servers.each do |machine|
config.vm.define machine[:hostname] do |node|
node.vm.box = machine[:box]
node.vm.hostname = machine[:hostname]
machine[:private_network].each do |pnetwork|
node.vm.network "private_network",
ip: pnetwork[:ip],
virtualbox__intnet: pnetwork[:virtualbox__intnet]
end
node.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", machine[:ram]]
endcontribute
end
end
end
So this is all for now. I hope this help you to get your JUNOS lab up un running and maybe help you to get your network certifications.