• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Vagrant
  • Install
  • Intro
  • Tutorials
  • Documentation
  • Vagrant Cloud
  • Try Cloud(opens in new tab)
  • Sign up
Networking and Provisioning

Skip to main content
3 tutorials
  • Provision a Virtual Machine
  • Configure the Network
  • Explore Other Providers

  • Resources

  • Tutorial Library
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  1. Developer
  2. Vagrant
  3. Tutorials
  4. Networking and Provisioning
  5. Configure the Network

Configure the Network

  • 2min

  • VagrantVagrant

In this tutorial, you will use Vagrant's networking features to provide access to the guest machine from your host machine.

Prerequisites

In the previous tutorial, Provision a Virtual Machine, you deployed a web server with the ability to modify files from your host and have them automatically synced to the guest. We recommend that you complete the previous tutorial, however, you can also get started if you have the following prerequisites.

  • Install the latest version of Vagrant.
  • Install a virtualization product such as: VirtualBox, VMware Fusion, or Hyper-V.

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.

To set up a forwarded port so you can access Apache on your guest, add the config.vm.network parameter to your Vagrantfile. Below is the full file with port forwarding.

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 has loaded, you can access http://127.0.0.1:4567 in your browser. 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.

 Previous
 Next

On this page

  1. Configure the Network
  2. Prerequisites
  3. Configure port forwarding
  4. Access the served files
  5. Next Steps
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)