2013-09-03 18:08:28 +00:00
|
|
|
---
|
2013-09-06 16:50:43 +00:00
|
|
|
page_title: "Public Networks - Networking"
|
2013-09-03 18:08:28 +00:00
|
|
|
sidebar_current: "networking-public"
|
|
|
|
---
|
|
|
|
|
|
|
|
# Public Networks
|
|
|
|
|
2013-09-06 16:50:43 +00:00
|
|
|
**Network identifier: `public_network`**
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
Public networks are less private than private networks, and the exact
|
|
|
|
meaning actually varies from [provider to provider](/v2/providers/index.html),
|
|
|
|
hence the ambiguous definition. The idea is that while
|
|
|
|
[private networks](/v2/networking/private_network.html) should never allow the
|
|
|
|
general public access to your machine, public networks can.
|
|
|
|
|
|
|
|
<div class="alert alert-info">
|
|
|
|
<p>
|
|
|
|
<strong>Confused?</strong> We kind of are, too. It is likely that
|
|
|
|
public networks will be replaced by <code>:bridged</code> in a
|
|
|
|
future release, since that is in general what should be done with
|
|
|
|
public networks, and providers that don't support bridging generally
|
|
|
|
don't have any other features that map to public networks either.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
2014-10-08 06:05:46 +00:00
|
|
|
<div class="alert alert-warning">
|
|
|
|
<p>
|
2015-02-24 17:30:58 +00:00
|
|
|
<strong>Warning!</strong> Vagrant boxes are insecure by default
|
|
|
|
and by design, featuring public passwords, insecure keypairs
|
2014-10-08 06:05:46 +00:00
|
|
|
for SSH access, and potentially allow root access over SSH. With
|
|
|
|
these known credentials, your box is easily accessible by anyone on
|
|
|
|
your network. Before configuring Vagrant to use a public network,
|
|
|
|
consider <em>all</em> potential security implications
|
|
|
|
and review the <a href="/v2/boxes/base.html">default box
|
|
|
|
configuration</a> to identify potential security risks.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
## DHCP
|
|
|
|
|
|
|
|
The easiest way to use a public network is to allow the IP to be assigned
|
|
|
|
via DHCP. In this case, defining a public network is trivially easy:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
2013-09-06 16:50:43 +00:00
|
|
|
config.vm.network "public_network"
|
2013-09-03 18:08:28 +00:00
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
When DHCP is used, the IP can be determined by using `vagrant ssh` to
|
|
|
|
SSH into the machine and using the appropriate command line tool to find
|
|
|
|
the IP, such as `ifconfig`.
|
2013-09-03 18:59:49 +00:00
|
|
|
|
2015-09-23 03:29:11 +00:00
|
|
|
### Using the DHCP Assigned Default Route
|
|
|
|
|
|
|
|
Some cases require the DHCP assigned default route to be untouched. In these cases one
|
2015-09-23 03:58:01 +00:00
|
|
|
may specify the `use_dhcp_assigned_default_route` option. As an example:
|
2015-09-23 03:29:11 +00:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
2015-09-23 03:58:01 +00:00
|
|
|
config.vm.network "public_network",
|
|
|
|
use_dhcp_assigned_default_route: true
|
2015-09-23 03:29:11 +00:00
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2014-06-03 02:16:41 +00:00
|
|
|
## Static IP
|
|
|
|
|
|
|
|
Depending on your setup, you may wish to manually set the IP of your
|
|
|
|
bridged interface. To do so, add a `:ip` clause to the network definition.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
config.vm.network "public_network", ip: "192.168.0.17"
|
|
|
|
```
|
|
|
|
|
2015-02-24 17:30:58 +00:00
|
|
|
## Default Network Interface
|
|
|
|
|
|
|
|
If more than one network interface is available on the host machine, Vagrant will
|
|
|
|
ask you to choose which interface the virtual machine should bridge to. A default
|
|
|
|
interface can be specified by adding a `:bridge` clause to the network definition.
|
|
|
|
|
|
|
|
```ruby
|
2015-05-31 03:48:33 +00:00
|
|
|
config.vm.network "public_network", bridge: "en1: Wi-Fi (AirPort)"
|
2015-02-24 17:30:58 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
The string identifying the desired interface must exactly match the name of an
|
|
|
|
available interface. If it can't be found, Vagrant will ask you to pick
|
|
|
|
from a list of available network interfaces.
|
|
|
|
|
2015-05-31 03:48:33 +00:00
|
|
|
With some providers, it is possible to specify a list of adapters to bridge
|
|
|
|
against:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
config.vm.network "public_network", bridge: [
|
|
|
|
"en1: Wi-Fi (AirPort)",
|
|
|
|
"en6: Broadcom NetXtreme Gigabit Ethernet Controller",
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
In this example, the first network adapter that exists and can successfully be
|
|
|
|
bridge will be used.
|
|
|
|
|
2015-02-14 03:27:22 +00:00
|
|
|
## Disable Auto-Configuration
|
|
|
|
|
|
|
|
If you want to manually configure the network interface yourself, you
|
2015-02-24 17:30:58 +00:00
|
|
|
can disable auto-configuration by specifying `auto_config`:
|
2015-02-14 03:27:22 +00:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.network "public_network", auto_config: false
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2015-02-24 17:30:58 +00:00
|
|
|
Then the shell provisioner can be used to configure the ip of the interface:
|
2015-02-14 03:27:22 +00:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.network "public_network", auto_config: false
|
2015-02-24 17:30:58 +00:00
|
|
|
|
|
|
|
# manual ip
|
|
|
|
config.vm.provision "shell",
|
|
|
|
run: "always",
|
|
|
|
inline: "ifconfig eth1 192.168.0.17 netmask 255.255.255.0 up"
|
|
|
|
|
|
|
|
# manual ipv6
|
|
|
|
config.vm.provision "shell",
|
|
|
|
run: "always",
|
|
|
|
inline: "ifconfig eth1 inet6 add fc00::17/7"
|
2015-02-14 03:27:22 +00:00
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
## Default Router
|
|
|
|
|
2015-02-24 17:30:58 +00:00
|
|
|
Depending on your setup, you may wish to manually override the default
|
|
|
|
router configuration. This is required if you need access the Vagrant box from
|
|
|
|
other networks over the public network. To do so, you can use a shell
|
|
|
|
provisioner script:
|
2015-02-14 03:27:22 +00:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
config.vm.network "public_network", ip: "192.168.0.17"
|
|
|
|
|
2015-02-24 17:30:58 +00:00
|
|
|
# default router
|
|
|
|
config.vm.provision "shell",
|
|
|
|
run: "always",
|
|
|
|
inline: "route add default gw 192.168.0.1"
|
2013-09-03 18:59:49 +00:00
|
|
|
|
2015-02-24 17:30:58 +00:00
|
|
|
# default router ipv6
|
|
|
|
config.vm.provision "shell",
|
|
|
|
run: "always",
|
|
|
|
inline: "route -A inet6 add default gw fc00::1 eth1"
|
2013-09-03 18:59:49 +00:00
|
|
|
|
2015-02-24 17:30:58 +00:00
|
|
|
# delete default gw on eth0
|
|
|
|
config.vm.provision "shell",
|
|
|
|
run: "always",
|
|
|
|
inline: "eval `route -n | awk '{ if ($8 ==\"eth0\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
|
2013-09-03 18:59:49 +00:00
|
|
|
```
|
|
|
|
|
2015-02-24 17:30:58 +00:00
|
|
|
Note the above is fairly complex and may be guest OS specific, but we
|
|
|
|
document the rough idea of how to do it because it is a common question.
|