vagrant public ip not accessible
I have this config:
config.vm.network "public_network", ip: "192.168.56.101", :mac => "0022334455DA"
And after vagrant up
ifconfig prints:
eth0 Link encap:Ethernet HWaddr 08:00:27:12:96:98
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe12:9698/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1141 errors:0 dropped:0 overruns:0 frame:0
TX packets:861 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:115407 (115.4 KB) TX bytes:98490 (98.4 KB)
eth1 Link encap:Ethernet HWaddr 00:22:33:44:55:da
inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::222:33ff:fe44:55da/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:319 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19236 (19.2 KB) TX bytes:648 (648.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
But I still can't access the server at 192.168.56.101
on my machine or any other on my network. When the config was private_server
I could access the address from my machine.
ip route show
default via 10.0.2.2 dev eth0
default via 10.0.2.2 dev eth0 metric 100
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.101
When the vm is running, VB network config shows two connections:
Adapter 1
Attached to: NAT
Adapter 2
Attached to: Bridged Adapter
Name: Intel Ethernet Connection
So I guess eth0 is NAT and eth1 is a bridged connection? the Intel Ethernet Connection
is my ethernet cable connected to the router.
Also when I open network and sharing center, it tells me there is an unidentified network with 2 connections: VirtualBox Host-Only Network
and VirtualBox Host-Only Network #2
. Which is confusing as I actually set Vagrant to use a public network.
Solution 1:
Using ifconfig, I found that the netmask assigned to the guest machine differed from the host's bridged interface, so I had to specify it manually. Once I did that, the VM was accessible outside of the host system. Here's my Vagrantfile entry:
config.vm.network :public_network, ip: '172.16.35.51', :netmask => '255.255.0.0', :bridge => 'eth0'