2013-09-03 18:08:28 +00:00
|
|
|
---
|
2017-03-28 01:19:52 +00:00
|
|
|
layout: "intro"
|
2013-09-06 16:50:43 +00:00
|
|
|
page_title: "Networking - Getting Started"
|
2013-09-03 18:08:28 +00:00
|
|
|
sidebar_current: "gettingstarted-networking"
|
2016-01-19 18:08:53 +00:00
|
|
|
description: |-
|
|
|
|
At this point we have a web server up and running with the ability to
|
|
|
|
modify files from our host and have them automatically synced to the guest.
|
|
|
|
However, accessing the web pages simply from the terminal from inside
|
|
|
|
the machine is not very satisfying. In this step, we will use Vagrant's
|
|
|
|
networking features to give us additional options for accessing the
|
|
|
|
machine from our host machine.
|
2013-09-03 18:08:28 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Networking
|
|
|
|
|
|
|
|
At this point we have a web server up and running with the ability to
|
|
|
|
modify files from our host and have them automatically synced to the guest.
|
|
|
|
However, accessing the web pages simply from the terminal from inside
|
2016-01-19 18:08:53 +00:00
|
|
|
the machine is not very satisfying. In this step, we will use Vagrant's
|
2013-09-03 18:08:28 +00:00
|
|
|
_networking_ features to give us additional options for accessing the
|
|
|
|
machine from our host machine.
|
|
|
|
|
|
|
|
## Port Forwarding
|
|
|
|
|
|
|
|
One option is to use _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.
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
Let us setup a forwarded port so we can access Apache in our guest. Doing so
|
2013-09-03 18:08:28 +00:00
|
|
|
is a simple edit to the Vagrantfile, which now looks like this:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
2019-08-14 17:48:33 +00:00
|
|
|
config.vm.box = "hashicorp/bionic64"
|
2014-05-22 16:35:12 +00:00
|
|
|
config.vm.provision :shell, path: "bootstrap.sh"
|
2015-02-24 18:13:56 +00:00
|
|
|
config.vm.network :forwarded_port, guest: 80, host: 4567
|
2013-09-03 18:08:28 +00:00
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
Run a `vagrant reload` or `vagrant up` (depending on if the machine
|
|
|
|
is already running) so that these changes can take effect.
|
|
|
|
|
|
|
|
Once the machine is running again, load `http://127.0.0.1:4567` in
|
|
|
|
your browser. You should see a web page that is being served from
|
|
|
|
the virtual machine that was automatically setup by Vagrant.
|
|
|
|
|
|
|
|
## Other Networking
|
|
|
|
|
|
|
|
Vagrant also has other forms of networking, allowing you to assign
|
|
|
|
a static IP address to the guest machine, or to bridge the guest
|
2016-01-19 18:08:53 +00:00
|
|
|
machine onto an existing network. If you are interested in other options,
|
|
|
|
read the [networking](/docs/networking/) page.
|
2014-12-19 15:38:56 +00:00
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
## Next Steps
|
|
|
|
|
|
|
|
You have successfully configured networking for your virtual machine using
|
|
|
|
Vagrant. Read on to learn about
|
2017-03-28 01:19:52 +00:00
|
|
|
[setting up shares with Vagrant](/intro/getting-started/share.html).
|