From your configuration, you've correctly set up a public network interface in Vagrant:
config.vm.network "public_network", ip: "192.168.56.101", :mac => "0022334455DA"
The ifconfig output shows the interface (eth1) with the correct IP address is up and running. However, there appears to be a routing issue combined with potential VirtualBox network adapter misconfiguration.
Your ip route shows two default routes:
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
This creates ambiguity in routing decisions. The NAT interface (eth0) is taking precedence over your bridged public network (eth1).
The presence of VirtualBox Host-Only networks in your host machine's network configuration suggests potential conflicts. When using public_network with bridge mode, Host-Only adapters shouldn't interfere.
Here's how to properly configure your environment:
# Update your Vagrantfile network configuration
config.vm.network "public_network",
ip: "192.168.56.101",
bridge: "Intel Ethernet Connection", # Specify your exact adapter name
auto_config: true
# Then add this provisioner to fix routing
config.vm.provision "shell", run: "always", inline: <<-SHELL
ip route del default via 10.0.2.2 dev eth0
ip route add default via 192.168.56.1 dev eth1
SHELL
After making these changes:
- Run
vagrant reload --provision
- Check routes with
vagrant ssh -c "ip route"
- Test connectivity from host:
ping 192.168.56.101
If you prefer using DHCP instead of static IP:
config.vm.network "public_network",
use_dhcp_assigned_default_route: true,
bridge: "Intel Ethernet Connection"
Ensure your guest VM firewall isn't blocking connections:
sudo ufw disable # For Ubuntu
# Or
sudo systemctl stop firewalld # For CentOS
The issue occurs when trying to access a Vagrant VM via public_network configuration. Let's examine the current setup:
# Current Vagrantfile configuration
config.vm.network "public_network", ip: "192.168.56.101", :mac => "0022334455DA"
The VM successfully obtains the IP address (192.168.56.101) on eth1 interface, as shown in ifconfig output. However, network connectivity issues persist:
# Network interface showing correct IP assignment
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
Several factors could be causing this connectivity issue:
- VirtualBox Bridging Issues: Verify the bridge adapter is correctly bound to the host's physical NIC
# Check VirtualBox network settings VBoxManage list bridgedifs
- Firewall Restrictions: Check both host and guest firewall rules
# On Linux guest sudo iptables -L -n -v
- Routing Problems: Examine the routing table
# Current routes showing potential issues default via 10.0.2.2 dev eth0 192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.101
Here's a comprehensive approach to resolve the issue:
1. Verify VirtualBox Network Configuration
# Check VirtualBox network attachments
VBoxManage showvminfo [vmname] --details | grep "NIC"
2. Modify Vagrantfile for Better Bridging
# Improved public_network configuration
config.vm.network "public_network",
ip: "192.168.56.101",
bridge: "Intel Ethernet Connection", # Explicit bridge interface
mac: "0022334455DA",
auto_config: true
3. Network Interface Troubleshooting
# On guest VM, verify network interface settings
sudo ip link set eth1 up
sudo ip addr flush eth1
sudo dhclient -r eth1 && sudo dhclient eth1
4. Windows-Specific Fixes
For Windows hosts, these additional steps may help:
# Disable VirtualBox Host-Only adapters in Network Connections
netsh interface set interface "VirtualBox Host-Only Network" admin=disable
If automatic configuration fails, manually set up the network:
# In Vagrantfile
config.vm.provision "shell", inline: <<-SHELL
ip addr add 192.168.56.101/24 dev eth1
ip link set eth1 up
ip route add default via 192.168.56.1 dev eth1 metric 100
SHELL
After applying fixes, verify connectivity:
# From host machine
ping 192.168.56.101
traceroute 192.168.56.101
# From guest VM
ping 192.168.56.1 # Should reach gateway
ping 8.8.8.8 # Test internet connectivity