Skip to content

Commit d284e4c

Browse files
committed
Allow VM networks to be configured
1 parent 0881d75 commit d284e4c

File tree

3 files changed

+68
-16
lines changed

3 files changed

+68
-16
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,41 @@ DevBox can be configured using the `config.yaml` configuration file.
99

1010

1111
#### VM
12-
By default, DevBox will create a private network with an automatically assigned IP address. Use `ifconfig` on the VM to determine the IP address. A static IP address for the VM can be given by adding the `ip` property and assigning an address from the [reserved private address space](https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces). Also the default name for the VM is 'devbox', this can be changed by adding the `name` property. The default hostname for the VM is also 'devbox', this can be changed by adding the `hostname` property.
12+
By default, the name for the VM is 'devbox', this can be changed by adding the `name` property. The default hostname for the VM is also 'devbox', this can be changed by adding the `hostname` property.
1313
```yaml
14-
ip: "192.168.22.18"
1514
name: vmname
1615
hostname: vmhostname
1716
```
1817
1918
19+
#### Network
20+
By default, DevBox will create a private network with an automatically assigned IP address. Use `ifconfig` on the VM to determine the IP address. To create a bridged (public) network, add a `networks` array with a `type` property of `bridged`.
21+
```yaml
22+
networks:
23+
- type: bridged
24+
```
25+
26+
A static IP address for the VM can also be given by adding an `ip` property and assigning an address from the [reserved private address space](https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces).
27+
```yaml
28+
networks:
29+
- type: private
30+
ip: "192.168.178.40"
31+
```
32+
33+
```yaml
34+
networks:
35+
- type: bridged
36+
ip: "192.168.178.40"
37+
```
38+
39+
By default, DevBox will forward ports 80 and 3306 on the guest machine to ports 8000 and 33060 on the host. To forward additional ports, add a `ports` array with `guest` and `host` properties set to the ports you want to forward.
40+
```yaml
41+
ports:
42+
- guest: 443
43+
host: 44300
44+
```
45+
46+
2047
#### Folders
2148
By default, DevBox will share your project folder `.` with the `/vagrant` folder on the guest machine. To share additional folders with the guest machine `map` the host folder `to` the guest folder in the `folders` array.
2249
```yaml

Vagrantfile

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ name = settings["name"] ||= "devbox"
4141
# Default ports for forwarding
4242
default_ports = {
4343
80 => 8000,
44-
443 => 44300,
4544
3306 => 33060
4645
}
4746

@@ -70,19 +69,41 @@ Vagrant.configure("2") do |config|
7069
config.vm.box = settings["box"] ||= "damianlewis/ubuntu-#{settings["ubuntu"] ||= default_ubuntu}-#{webserver == "apache" ? "lamp" : "lemp"}"
7170
config.vm.box_version = settings["version"] ||= ">= 1.0"
7271

72+
# Configure default ports
73+
default_ports.each do |guest, host|
74+
config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
75+
end
76+
77+
# Configure additional ports to forward
78+
if settings.has_key?("ports")
79+
settings["ports"].each do |port|
80+
config.vm.network "forwarded_port", guest: port["guest"], host: port["host"], auto_correct: true
81+
end
82+
end
83+
7384
# Configure networks
7485
if settings.has_key?("networks")
7586
settings["networks"].each do |network|
76-
if network.has_key?("ip")
77-
config.vm.network network["type"], ip: network["ip"], bridge: network["bridge"] ||= nil
78-
else
79-
config.vm.network network["type"], bridge: network["bridge"] ||= nil
87+
if network.has_key?("type")
88+
if network["type"] == "private"
89+
if network.has_key?("ip")
90+
config.vm.network "private_network", ip: network["ip"]
91+
else
92+
config.vm.network "private_network", type: "dhcp"
93+
end
94+
end
95+
96+
if network["type"] == "bridged"
97+
if network.has_key?("ip")
98+
config.vm.network "public_network", ip: network["ip"], bridge: network["bridge"] ||= nil
99+
else
100+
config.vm.network "public_network", bridge: network["bridge"] ||= nil
101+
end
102+
end
80103
end
81104
end
82-
elsif settings.has_key?("ip")
83-
config.vm.network :private_network, ip: settings["ip"]
84105
else
85-
config.vm.network :private_network, type: "dhcp"
106+
config.vm.network "private_network", type: "dhcp"
86107
end
87108

88109
# Configure VirtualBox settings
@@ -98,11 +119,6 @@ Vagrant.configure("2") do |config|
98119
end
99120
end
100121

101-
# Configure default ports
102-
default_ports.each do |guest, host|
103-
config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
104-
end
105-
106122
# Configure shared folders
107123
if settings.has_key?("folders")
108124
settings["folders"].each do |folder|

config.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
---
22
# VM configurations
3-
ip: "192.168.10.10"
43
#ubuntu: "14.04"
54

5+
# Networks to configure
6+
#networks:
7+
# - type: bridged
8+
# ip: "192.168.178.40"
9+
10+
# Additional ports to forward
11+
#ports:
12+
# - guest: 443
13+
# host: 44300
14+
615
# Shared folders to configure
716
#folders:
817
# - map: ~/code

0 commit comments

Comments
 (0)