Virtual Day
Building the ecosystem for the Cloud Operating Model with Azure, Cisco, F5 and GitLab Register

Getting Started

Configure the Network

You now have a web server running with the ability to modify files from our host and have them automatically synced to the guest. In this tutorial, you will use Vagrant's networking features to provide access to the guest machine from our host machine.

»Configure port forwarding

Port forwarding allows you to specify ports on the guest machine to share via a port on the host machine. This allows you to access a port on your own machine, but actually have all the network traffic forwarded to a specific port on the guest machine.

Set up a forwarded port so you can access Apache in your guest, by adding it to the Vagrantfile under the line you added to run your bootstrap script. Below is the full file with port forwarding added.

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/bionic64"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network :forwarded_port, guest: 80, host: 4567
end

Reload so that these changes can take effect.

$ vagrant reload

»Access the served files

Once the machine is running again, load http://127.0.0.1:4567 in your browser, where you will find a web page that is being served from the guest virtual machine.

»Next Steps

Vagrant also has other forms of networking, allowing you to assign a static IP address to the guest machine, or to bridge the guest machine onto an existing network. If you are interested in other options, read the networking page.

You have successfully configured networking for your virtual machine using Vagrant. Read on to learn about setting up shares with Vagrant.